pygeoprocessing.multiprocessing package¶
Module contents¶
- pygeoprocessing.multiprocessing.raster_calculator(base_raster_path_band_const_list, local_op, target_raster_path, datatype_target, nodata_target, n_workers=2, calc_raster_stats=True, use_shared_memory=False, largest_block=65536, raster_driver_creation_tuple=('GTIFF', ('TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', 'BLOCKXSIZE=256', 'BLOCKYSIZE=256')))[source]¶
Apply local a raster operation on a stack of rasters.
This function applies a user defined function across a stack of rasters’ pixel stack. The rasters in
base_raster_path_band_list
must be spatially aligned and have the same cell sizes.- Parameters
base_raster_path_band_const_list (sequence) – a sequence containing either (str, int) tuples,
numpy.ndarray
s of up to two dimensions, or an (object, ‘raw’) tuple. A(str, int)
tuple refers to a raster path band index pair to use as an input. Thenumpy.ndarray
s must be broadcastable to each other AND the size of the raster inputs. Values passed by(object, 'raw')
tuples passobject
directly into thelocal_op
. All rasters must have the same raster size. If only arrays are input, numpy arrays must be broadcastable to each other and the final raster size will be the final broadcast array shape. A value error is raised if only “raw” inputs are passed.local_op (function) – there are elements in
base_raster_path_band_const_list
. The parameters inlocal_op
will map 1-to-1 in order with the values inbase_raster_path_band_const_list
.raster_calculator
will calllocal_op
to generate the pixel values intarget_raster
along memory block aligned processing windows. Note any particular call tolocal_op
will have the arguments fromraster_path_band_const_list
sliced to overlap that window. If an argument fromraster_path_band_const_list
is a raster/path band tuple, it will be passed tolocal_op
as a 2D numpy array of pixel values that align with the processing window thatlocal_op
is targeting. A 2D or 1D array will be sliced to match the processing window and in the case of a 1D array tiled in whatever dimension is flat. If an argument is a scalar it is passed as as scalar. The return value must be a 2D array of the same size as any of the input parameter 2D arrays and contain the desired pixel values for the target raster.target_raster_path (string) – the path of the output raster. The projection, size, and cell size will be the same as the rasters in
base_raster_path_const_band_list
or the final broadcast size of the constant/ndarray values in the list.datatype_target (gdal datatype; int) – the desired GDAL output type of the target raster.
nodata_target (numerical value) – the desired nodata value of the target raster.
n_workers (int) – number of Processes to launch for parallel processing, defaults to
multiprocessing.cpu_count()
.calc_raster_stats (boolean) – If True, calculates and sets raster statistics (min, max, mean, and stdev) for target raster.
use_shared_memory (boolean) – If True, uses Python Multiprocessing shared memory to calculate raster stats for faster performance. This feature is available for Python >= 3.8 and will otherwise be ignored for earlier versions of Python.
largest_block (int) – Attempts to internally iterate over raster blocks with this many elements. Useful in cases where the blocksize is relatively small, memory is available, and the function call overhead dominates the iteration. Defaults to 2**20. A value of anything less than the original blocksize of the raster will result in blocksizes equal to the original size.
raster_driver_creation_tuple (tuple) – a tuple containing a GDAL driver name string as the first element and a GDAL creation options tuple/list as the second. Defaults to geoprocessing.DEFAULT_GTIFF_CREATION_TUPLE_OPTIONS.
- Returns
None
- Raises
ValueError – invalid input provided