hubdc.applier¶
Basic tools for setting up a function to be applied over a raster processing chain.
The Applier class is the main point of entry in this module.
-
class
hubdc.applier.Applier(controls=None)[source]¶ Bases:
objectThis class is the main point of entry in this module.
- Attributes and properties are:
- inputRaster
ApplierInputRasterGroupobject containing all input rasters - inputRasterArchive
ApplierInputRasterArchiveGroupobject containing all input raster archieves - inputVector
ApplierInputVectorGroupobject containing all input vectors - outputRaster
ApplierOutputRasterGroupobject containing all output rasters - controls
ApplierControlsobject containing all input rasters - mainGrid
Gridobject
- inputRaster
-
__init__(controls=None)[source]¶ Parameters: controls – an ApplierControlsobject
-
apply(operatorType=None, operatorFunction=None, description=None, overwrite=True, *ufuncArgs, **ufuncKwargs)[source]¶ Applies the
operatorblockwise over a raster processing chain and returns a list of results, one for each block.The
operatormust be a subclass ofApplierOperatorand needs to implement theufunc()method to specify the image processing.For example:
class MyOperator(ApplierOperator): def ufunc(self): # process the data applier.apply(operator=MyOperator)
Parameters: - description – short description that is displayed on the progress bar
- ufuncArgs – additional arguments that will be passed to the operators ufunc() method.
- ufuncKwargs – additional keyword arguments that will be passed to the operators ufunc() method.
Returns: list of results, one for each processed block
-
class
hubdc.applier.ApplierControls[source]¶ Bases:
objectClass for controlling various details of the applier processing.
-
deriveExtent(grids, projection)[source]¶ Derives the extent from the given grids in the given projection.
-
deriveGrid(inputRasterGroup)[source]¶ Derives the grid from the given
ApplierInputRasterGroup’s.
-
setAutoExtent(autoExtent='intersection')[source]¶ Define how the grid extent is derived from the input rasters. Possible options are listed in
AutoExtent.
-
setAutoResolution(autoResolution='minimum')[source]¶ Define how the grid resolution is derived from the input rasters. Possible options are listed in
AutoResolution.
-
setBlockSize(blockSize=RasterSize(x=256, y=256))[source]¶ Set the processing block x and y size. Pass an int defining x and y size to be the same, or a tuple (int, int) defining x and y size separately, or a
Sizeobject.
-
setExtent(extent=None)[source]¶ Set the applier extent. Pass a (float, float, float, float) tuple defining the extent as (xMin, xMax, yMin, yMax), or an
Extentobject, or None (default) to derive the extent from the input rasters.
-
setGDALCacheMax(bytes=104857600)[source]¶ For details see the GDAL_CACHEMAX Configuration Option.
-
setGDALDisableReadDirOnOpen(disable=True)[source]¶ For details see the GDAL_DISABLE_READDIR_ON_OPEN Configuration Option.
-
setGDALMaxDatasetPoolSize(nfiles=100)[source]¶ For details see the GDAL_MAX_DATASET_POOL_SIZE Configuration Option.
-
setGDALSwathSize(bytes=104857600)[source]¶ For details see the GDAL_SWATH_SIZE Configuration Option.
-
setNumThreads(nworker=None)[source]¶ Set the number of pool worker for multiprocessing. Set to None to disable multiprocessing (recommended for debugging). Set to -1 to use all CPUs.
-
setNumWriter(nwriter=None)[source]¶ Set the number of writer processes. Set to None to disable multiwriting (recommended for debugging).
-
setProgressBar(progressBar=None)[source]¶ Set the progress display object. Default is an
CUIProgressobject. For suppressing outputs use anSilentProgressobject
-
setProgressCallback(progressCallback=None)[source]¶ Set the progress callback function, a function with one argument named
percent, that is called each time the applier finishes a block.
-
setProjection(projection=None)[source]¶ Set the applier projection (default is projection shared by all input rasters.
-
setResolution(resolution=None)[source]¶ Set the applier resolution. Pass a float defining x and y resolution to be the same, or a (float, float) tuple defining x and y resolution separately, or a
Resolutionobject, or None (default) to derive the resolution from the input rasters.
-
setWriteENVIHeader(createEnviHeader=True)[source]¶ Set to True to create additional ENVI header files for all output rasters. The header files store all metadata items from the ENVI domain, so that the images can be correctly interpreted by the ENVI software. Currently only the native ENVI format and the GTiff format is supported.
-
-
class
hubdc.applier.ApplierDefaults[source]¶ Bases:
objectDefault values for various settings used inside an applier processing chain.
-
class
GDALEnv[source]¶ Bases:
object-
cacheMax= 104857600¶
-
disableReadDirOnOpen= True¶
-
maxDatasetPoolSize= 100¶
-
swathSize= 104857600¶
-
-
class
GDALWarp[source]¶ Bases:
object-
errorThreshold= 0.0¶
-
memoryLimit= 104857600¶
-
multithread= False¶
-
-
autoExtent= 'intersection'¶
-
autoResolution= 'minimum'¶
-
blockSize= RasterSize(x=256, y=256)¶
-
nworker= None¶
-
nwriter= None¶
-
writeENVIHeader= True¶
-
class
-
class
hubdc.applier.ApplierIO(filename)[source]¶ Bases:
objectBase class for io items. For internal use only.
-
class
hubdc.applier.ApplierInputRaster(filename)[source]¶ Bases:
hubdc.applier.ApplierIOClass for handling input raster dataset.
-
array(indices=None, overlap=0, resampleAlg=<Mock name='mock.gdal.GRA_NearestNeighbour' id='139880523761312'>, noDataValue=None, errorThreshold=0.0, warpMemoryLimit=104857600, multithread=False, grid=None)[source]¶ Returns image data as 3-d numpy array of shape = (zsize, ysize, xsize), where zsize is the number of bands.
Parameters: - indices – list of band indices to read (default is all bands)
- overlap – the number of pixels to additionally read along each spatial dimension
- resampleAlg – GDAL resampling algorithm, e.g. gdal.GRA_NearestNeighbour
- noDataValue – explicitely set the noDataValue used for reading; this overwrites the noDataValue defined by the raster itself
- errorThreshold – error threshold for approximation transformer (in pixels)
- warpMemoryLimit – size of working buffer in bytes
- multithread – whether to multithread computation and I/O operations
- grid – explicitly set the
Grid, for which image data is returned
-
fractionArray(categories, overlap=0, index=None)[source]¶ Returns a stack of category fractions for the given
categoriesas a 3-d numpy array of shape = (zsize, ysize, xsize), where zsize is the number of categories.Parameters: - categories – list of categories of interest
- overlap – the number of pixels to additionally read along each spatial dimension
- index – index to the band holding the categories
-
noDataValue(default=None)[source]¶ Return single image no data value. Only valid to use if all bands have the same no data value.
-
sample(mask, resampleAlg=<Mock name='mock.gdal.GRA_NearestNeighbour' id='139880523761312'>, noDataValue=None, errorThreshold=0.0, warpMemoryLimit=104857600, multithread=False)[source]¶ Returns all pixel profiles for which
maskis True as a 2-d numpy array of shape = (zsize, samples). Note that pixel profiles are individually accessed, which is fast for sparse masks, but slow otherwise.Parameters: - overlap – the number of pixels to additionally read along each spatial dimension
- resampleAlg – GDAL resampling algorithm, e.g. gdal.GRA_NearestNeighbour
- noDataValue – explicitely set the noDataValue used for reading; this overwrites the noDataValue defined by the raster itself
- errorThreshold – error threshold for approximation transformer (in pixels)
- warpMemoryLimit – size of working buffer in bytes
- multithread – whether to multithread computation and I/O operations
-
-
class
hubdc.applier.ApplierInputRasterGroup[source]¶ Bases:
hubdc.applier.ApplierIOGroupContainer for
ApplierInputRasterandApplierInputRasterGroupobjects.-
findRaster(ufunc=<function ApplierInputRasterGroup.<lambda>>)[source]¶ Returns the first
ApplierInputRasterfor that the user defined functionufunc(key, raster)matches. Returns None in case of no match.
-
findRasterKey(ufunc=<function ApplierInputRasterGroup.<lambda>>)[source]¶ Returns the first key for that the user defined function
ufunc(key, raster)matches. Returns None in case of no match.
-
flatRasterKeys()[source]¶ Returns an iterator over the keys of all contained
ApplierInputRaster’s. Traverses the group structure recursively.
-
flatRasters()[source]¶ Returns an iterator over all contained
ApplierInputRaster’s. Traverses the group structure recursively.
-
classmethod
fromFolder(folder, extensions, ufunc=None)[source]¶ Returns an input raster group containing all input rasters that are located relativ to the given
folder, matches one of the fileextensions, and (optionally) matches the user defined filterufunc(dirname, basename, extension). In the result, the file system folder structure is preserved.Parameters: - folder – root folder
- extensions – only rasters that matches one of the given extensions are included, e.g. [‘’, ‘.bsq’, ‘.tif’, ‘.vrt’].
- ufunc – function of form
ufunc(dirname, basename, extension); only files that pass the filter function (i.e. return True) are included
-
groupKeys()[source]¶ Returns an iterator over the keys of all directly contained
ApplierInputRasterGroups’s. No recursion.
-
groups()[source]¶ Returns an iterator over all directly contained
ApplierInputRasterGroups’s. No recursion.
-
raster(key)[source]¶ Returns the
ApplierInputRasternamedkey.
-
rasterKeys()[source]¶ Returns an iterator over the keys of all directly contained
ApplierInputRaster’s. No recursion.
-
rasters()[source]¶ Returns an iterator over all directly contained
ApplierInputRaster’s. No recursion.
-
setRaster(key, value)[source]¶ Add an
ApplierInputRastergiven byvalueand namedkey.
-
-
class
hubdc.applier.ApplierInputVector(filename, layerNameOrIndex=0)[source]¶ Bases:
hubdc.applier.ApplierIOClass for handling the vector dataset given by it’s
filenameandlayerNameOrIndex.-
__init__(filename, layerNameOrIndex=0)[source]¶ Parameters: - filename – filename
- layerNameOrIndex (str or int) – layer name or index
-
array(initValue=0, burnValue=1, burnAttribute=None, allTouched=False, filterSQL=None, overlap=0, dtype=<Mock name='mock.float32' id='139880518043184'>)[source]¶ Returns the vector rasterization of the current block in form of a 3-d numpy array of shape = (1, ysize, xsize).
Parameters: - initValue – value to pre-initialize the output array
- burnValue – value to burn into the output array for all objects; exclusive with
burnAttribute - burnAttribute – identifies an attribute field on the features to be used for a burn-in value; exclusive with
burnValue - allTouched – whether to enable that all pixels touched by lines or polygons will be updated, not just those on the line render path, or whose center point is within the polygon
- filterSQL – set an SQL WHERE clause which will be used to filter vector features
- overlap – the number of pixels to additionally read along each spatial dimension
-
coverageFractionArray(oversampling=1, overlap=0)[source]¶ Returns aggregated coverage fractions of the current block in form of a 3d numpy array of shape = (1, ysize, xsize).
Parameters: - oversampling – factor defining the relative degree of rasterization detail compared to the target resolution. If for example the target resolution is 30m and the oversampling factor is 10, then the categories are first rasterized at 3m, and finally aggregated to the target resolution.
- overlap – the number of pixels to additionally read along each spatial dimension
-
fractionArray(categories, categoryAttribute=None, oversampling=1, overlap=0)[source]¶ Returns aggregated category fractions of the current block in form of a 3d numpy array of shape = (categories, ysize, xsize).
Parameters: - categories – list of categories (numbers or names)
- categoryAttribute – attribute field on the features holding the categories
- oversampling – factor defining the relative degree of rasterization detail compared to the target resolution. If for example the target resolution is 30m and the oversampling factor is 10, then the categories are first rasterized at 3m, and finally aggregated to the target resolution.
- overlap – the number of pixels to additionally read along each spatial dimension
-
-
class
hubdc.applier.ApplierInputVectorGroup[source]¶ Bases:
hubdc.applier.ApplierIOGroupContainer for
ApplierInputVectorandApplierInputVectorGroupobjects.-
flatVectorKeys()[source]¶ Returns an iterator over the keys of all contained
ApplierInputVectors’s. Traverses the group structure recursively.
-
flatVectors()[source]¶ Returns an iterator over all contained
ApplierInputVector’s. Traverses the group structure recursively.
-
groupKeys()[source]¶ Returns an iterator over the keys of all directly contained
ApplierInputVectorGroups’s. No recursion.
-
groups()[source]¶ Returns an iterator over all directly contained
ApplierInputVectorGroups’s. No recursion.
-
setVector(key, value)[source]¶ Add an
ApplierInputVectorgiven byvalueand namedkey.
-
vector(key)[source]¶ Returns the
ApplierInputVectornamedkey.
-
-
class
hubdc.applier.ApplierOperator(mainGrid, inputRaster, inputVector, outputRaster, controls, ufuncArgs, ufuncKwargs, operatorUFunc=None)[source]¶ Bases:
objectThis is the baseclass for an user defined applier operator. For details on user defined operators see
hubdc.applier.Applier.apply()-
__init__(mainGrid, inputRaster, inputVector, outputRaster, controls, ufuncArgs, ufuncKwargs, operatorUFunc=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
static
aggregate(blockResults, grid, *args, **kwargs)[source]¶ Overwrite this method to specify how to aggregate the list of block-wise return values.
-
full(value, bands=1, dtype=None, overlap=0)[source]¶ Returns a 3-d numpy array of shape = (zsize, ysize+2*overlap, xsize+2*overlap) filled with constant
valueor list of values, one for each band.
-
progressBar¶ Returns the
ProgressBar.
-
-
class
hubdc.applier.ApplierOptions[source]¶ Bases:
objectEnumeration types.
-
class
hubdc.applier.ApplierOutputRaster(filename, driver=None, creationOptions=None)[source]¶ Bases:
hubdc.applier.ApplierIOClass for creating and handling an output raster dataset.
-
__init__(filename, driver=None, creationOptions=None)[source]¶ Parameters: - filename – destination filename for output raster
- driver (hubdc.core.RasterDriver) –
- creationOptions (list) – raster creation options
-
band(index)[source]¶ Returns the
ApplierOutputRasterBandfor the givenindex.
-
bands()[source]¶ Returns an iterator over all
ApplierOutputRasterBand’s.
-
setArray(array, overlap=0)[source]¶ Write data to the output raster.
Parameters: - array – 3-d numpy array of shape = (zsize, ysize, xsize) or 2-d numpy array of shape = (ysize, xsize)
- overlap – the amount of margin (number of pixels) to be removed from the image data block in each direction; this is useful when the overlap keyword was also used during data reading.
-
setMetadataDict(metadataDict)[source]¶ Set metadata dictionary.
Parameters: metadataDict – dictionary of dictionaries for different metadata domains, e.g. {'ENVI': {'wavelength' : [482, 561, 655, 865, 1609, 2201], 'wavelength_units' : 'nanometers', 'band_names' : ['Blue', 'Green', 'Red', 'NIR', 'SWIR1', 'SWIR2']}}
-
-
class
hubdc.applier.ApplierOutputRasterBand(parent, index)[source]¶ Bases:
hubdc.applier.ApplierIOClass for handling an output raster band dataset.
-
setArray(array, overlap=0)[source]¶ Write data to the output raster band.
Parameters: - array – 3-d numpy array of shape = (1, ysize, xsize) or 2-d numpy array of shape = (ysize, xsize)
- overlap – the amount of margin (number of pixels) to be removed from the image data block in each direction; this is useful when the overlap keyword was also used during data reading.
-
-
class
hubdc.applier.ApplierOutputRasterGroup[source]¶ Bases:
hubdc.applier.ApplierIOGroupContainer for
ApplierOutputRasterandApplierOutputRasterGroupobjects.-
flatRasterKeys()[source]¶ Returns an iterator over the keys of all contained
ApplierOutputRaster’s. Traverses the group structure recursively.
-
flatRasters()[source]¶ Returns an iterator over all contained
ApplierOutputRaster’s. Traverses the group structure recursively.
-
raster(key)[source]¶ Returns the
ApplierOutputRasternamedkey.
-
setRaster(key, value)[source]¶ Add an
ApplierOutputRastergiven byvalueand namedkey.
-