skmap.parallel.blocks.RasterBlockAggregator#
- class RasterBlockAggregator(reader=None)[source]#
Bases:
objectClass for aggregating results of block wise raster processing into a single result.
- Parameters:
reader (
RasterBlockReader) – RasterBlockReader instance to use for reading rasters.
For full usage examples please refer to the block processing tutorial notebook [1].
References
[1] Raster block processing tutorial
Examples
>>> from skmap.parallel.blocks import RasterBlockReader, RasterBlockAggregator >>> >>> fp = 'https://s3.eu-central-1.wasabisys.com/skmap/lcv/lcv_landcover.hcl_lucas.corine.rf_p_30m_0..0cm_2019_skmap_epsg3035_v0.1.tif' >>> >>> reader = RasterBlockReader(fp) >>> aggregator = RasterBlockAggregator(reader)
Methods
Aggregates results of block wise raster processing into a single result.
- aggregate(src_path, geometry, block_func, agg_func=<function mean>, **kwargs)[source]#
Aggregates results of block wise raster processing into a single result.
- Parameters:
src_path (
Union[str,Iterable[str]]) – Path(s) (or URLs) of the raster file(s) to read. If aggregator is initialized withreader=None, the first file insrc_pathwill be used to initialize a new reader.geometry (
dict) – The bounding geometry within which to read raster blocks, given as a dictionary (with the GeoJSON geometry schema).block_func (
Callable) – Callable to perform on the data for each block.agg_func (
Callable) – Callable to produce an aggregation of block-wise results.**kwargs –
Additional keyword arguments passed to
RasterBlockReader.read_overlay().
- Returns:
The result of
agg_funccalled with block-wiseblock_funcresults as the argument.
For full usage examples please refer to the block processing tutorial notebook [1].
References
[1] Raster block processing tutorial
Examples
>>> from skmap.parallel import blocks >>> geom = { ... 'type': 'Polygon', ... 'coordinates': [[ ... [4765389, 2441103], ... [4764441, 2439352], ... [4767369, 2438696], ... [4761659, 2441949], ... [4765389, 2441103], ... ]], ... } >>> >>> def urban_fabric_area(lc): ... return (lc==1) * 9e-4 # spatial resolution is 30x30 m >>> >>> result = aggregator.aggregate( ... fp, geom, ... block_func=urban_fabric_area, ... agg_func=np.sum, ... )