Applier (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.
See Applier Examples for more information.
-
class
hubdc.applier.
Applier
(controls=None)[source]¶ Bases:
object
This class is the main point of entry in this module. For detailed usage examples see Applier Examples.
- Attributes and properties are:
- inputRaster
ApplierInputRasterGroup
object containing all input rasters - inputRasterArchive
ApplierInputRasterArchiveGroup
object containing all input raster archieves - inputVector
ApplierInputVectorGroup
object containing all input vectors - outputRaster
ApplierOutputRasterGroup
object containing all output rasters - controls
ApplierControls
object containing all input rasters - mainGrid
Grid
object
- inputRaster
-
__init__
(controls=None)[source]¶ Parameters: controls – an ApplierControls
object
-
apply
(operatorType=None, operatorFunction=None, description=None, overwrite=True, *ufuncArgs, **ufuncKwargs)[source]¶ Applies the
operator
blockwise over a raster processing chain and returns a list of results, one for each block.The
operator
must be a subclass ofApplierOperator
and 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)
or:
def my_ufunc(operator): # process the data applier.apply(operator=my_ufunc)
For detailed usage examples see Applier Examples.
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:
object
Class for controlling various details of the applier processing.
-
deriveExtent
(grids, projection)[source]¶ Derives the extent from the given
Grid
’s in the givenProjection
.
-
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=Size(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
Size
object.
-
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
Extent
object, 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.
-
setGrid
(grid=None)[source]¶ Set the applier grid defining the extent, resolution and projection. Pass a
Grid
object, or None (default) to derive the grid from the input rasters.
-
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
CUIProgress
object. For suppressing outputs use anSilentProgress
object
-
setProjection
(projection=None)[source]¶ Set the applier projection. Pass a Well-Known Text (WKT) projection string, or an Authority EPSG ID as int, or a
Projection
object, or None (default) to use the projection that is 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
Resolution
object, 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:
object
Defauls 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
= Size(x=256, y=256)¶
-
nworker
= None¶
-
nwriter
= None¶
-
writeENVIHeader
= True¶
-
class
-
class
hubdc.applier.
ApplierIO
(filename)[source]¶ Bases:
object
Base class for io items. For internal use only.
-
class
hubdc.applier.
ApplierInputRaster
(filename)[source]¶ Bases:
hubdc.applier.ApplierIO
Class for handling input raster dataset.
-
array
(overlap=0, resampleAlg=<Mock name='mock.gdal.GRA_NearestNeighbour' id='140313600122064'>, 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: - 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
-
bandArray
(indicies, overlap=0, resampleAlg=<Mock name='mock.gdal.GRA_NearestNeighbour' id='140313600122064'>, noDataValue=None, errorThreshold=0.0, warpMemoryLimit=104857600, multithread=False)[source]¶ Returns a band subset of the image data as 3-d numpy array of shape = (zsize, ysize, xsize), where zsize is the number of indicies.
Parameters: - indicies – list of band indicies
- 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
-
fractionArray
(categories, overlap=0, index=None)[source]¶ Returns a stack of category fractions for the given
categories
as 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='140313600122064'>, noDataValue=None, errorThreshold=0.0, warpMemoryLimit=104857600, multithread=False)[source]¶ Returns all pixel profiles for which
mask
is 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.ApplierIOGroup
Container for
ApplierInputRaster
andApplierInputRasterGroup
objects.-
findRaster
(ufunc=<function <lambda>>)[source]¶ Returns the first
ApplierInputRaster
for that the user defined functionufunc(key, raster)
matches. Returns None in case of no match.
-
findRasterKey
(ufunc=<function <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
-
static
fromIndex
(index)[source]¶ Returns an input raster group containing all input rasters contained in the
ApplierInputRasterIndex
given byindex
.
-
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
ApplierInputRaster
namedkey
.
-
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
ApplierInputRaster
given byvalue
and namedkey
.
-
-
class
hubdc.applier.
ApplierInputRasterIndex
[source]¶ Bases:
object
-
WGS84
= Projection(wkt=<Mockname='mock.osr.SpatialReference()'id='140313596641680'>)¶
-
-
class
hubdc.applier.
ApplierInputVector
(filename, layerNameOrIndex=0)[source]¶ Bases:
hubdc.applier.ApplierIO
Class for handling the vector dataset given by it’s
filename
andlayerNameOrIndex
.-
__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='140313596607568'>)[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
-
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.ApplierIOGroup
Container for
ApplierInputVector
andApplierInputVectorGroup
objects.-
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
ApplierInputVector
given byvalue
and namedkey
.
-
vector
(key)[source]¶ Returns the
ApplierInputVector
namedkey
.
-
-
class
hubdc.applier.
ApplierOperator
(mainGrid, inputRaster, inputVector, outputRaster, controls, ufuncArgs, ufuncKwargs, operatorUFunc=None)[source]¶ Bases:
object
This 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]¶
-
static
aggregate
(blockResults, grid, *args, **kwargs)[source]¶ Overwrite this method to specify how to aggregate the list of block-wise return values. See Applier Examples for more information.
-
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
value
.
-
ufunc
(*args, **kwargs)[source]¶ Overwrite this method to specify the image processing. See Applier Examples for more information.
-
progressBar
¶ Returns the
ProgressBar
.
-
-
class
hubdc.applier.
ApplierOptions
[source]¶ Bases:
object
Enumeration types.
-
class
hubdc.applier.
ApplierOutputRaster
(filename, driver=None, creationOptions=None)[source]¶ Bases:
hubdc.applier.ApplierIO
Class for creating and handling an output raster dataset.
-
__init__
(filename, driver=None, creationOptions=None)[source]¶ Parameters: - filename – destination filename for output raster
- driver (hubdc.model.RasterDriver) –
- creationOptions (RasterCreationOptions) – e.g. for ENVI and GTiff files see http://www.gdal.org/frmt_various.html#ENVI and http://www.gdal.org/frmt_gtiff.html.
-
band
(index)[source]¶ Returns the
ApplierOutputRasterBand
for 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.ApplierIO
Class 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.ApplierIOGroup
Container for
ApplierOutputRaster
andApplierOutputRasterGroup
objects.-
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
ApplierOutputRaster
namedkey
.
-
setRaster
(key, value)[source]¶ Add an
ApplierOutputRaster
given byvalue
and namedkey
.
-