remotior_sensus.tools.band_calc module
Band calc.
This tool allows for mathematical calculations (pixel by pixel) between bands or single band rasters. A new raster file is created as result of calculation.
Typical usage example:
>>> # import Remotior Sensus and start the session
>>> import remotior_sensus
>>> rs = remotior_sensus.Session()
>>> # start the process
>>> output = rs.band_calc(
... input_raster_list=['file1.tif', 'file2.tif'], output_path='output.tif',
... expression_string='"file1 + file2"', input_name_list=['file1', 'file2']
... )
It is possible to iterate BandSets. BandSet iteration with structure
forbandsets[x1:x2]name_filter
or
forbandsets[x1,x2,x3]name_filter
or date iteration with structure
forbandsets[YYYY-MM-DD:YYYY-MM-DD]name_filter
or
forbandsets[YYYY-MM-DD, YYYY-MM-DD, YYYY-MM-DD, …]name_filter
with name_filter
: optional filter of name of first band in the BandSet.
It is possible to iterate bands in BandSet with structure
forbandsinbandset[x1:x2]name_filter
or
forbandsinbandset[x1,x2,x3,…]name_filter
or date iteration with structure
forbandsinbandset[YYYY-MM-DD, YYYY-MM-DD, YYYY-MM-DD, …]name_filter
with name_filter
: optional filter of name of first band in the BandSet.
- remotior_sensus.tools.band_calc.band_calc(expression_string: str, output_path: None | str = None, input_raster_list: list | None = None, input_name_list: list | None = None, n_processes: None | int = None, available_ram: None | int = None, align_raster: None | str = None, extent_raster: None | str = None, extent_list: list | None = None, extent_intersection: bool | None = True, xy_resolution_list: list | None = None, input_nodata_as_value: bool | None = None, use_value_as_nodata: None | int = None, output_nodata: None | int = None, output_datatype: None | str = None, use_scale: None | float = None, use_offset: None | float = None, calc_datatype: None | str = None, any_nodata_mask: bool | None = False, bandset_catalog: BandSetCatalog | None = None, bandset_number: None | int = None, input_bands: BandSet | None = None, point_coordinates: list | None = None, progress_message: bool | None = True, device=None) OutputManager
Performs band calculation.
Calculation is defined by an expression string using variable names that corresponds to input bands or rasters. Expression can use band alias such as “bandset1b1”, spectral band alias such as “#NIR#” for Near-Infrared and “#RED#” for Red, or expression alias such as “#NDVI#”. Multiple expression lines can be entered for serial calculation. Several iteration functions are available for band sets. NumPy functions can also be used if the output is a single band array with the same size as input raster. Input rasters can have different projection definitions, as the tool will try to reproject input rasters on the fly based on a reference raster (first input raster or align_raster).
- Parameters:
input_raster_list – list of input raster paths or list of lists [path, name] ignoring
input_name_list
.output_path – path of output file for single expression or path to a directory for multiple expression outputs.
expression_string – expression string used for calculation; multiple expressions can be entered separated by new line.
input_name_list – list of input raster names used in expressions (if name not defined in
input_raster_list
).input_bands – input BandSet for direct expression; in expressions, bands can be refferred as “b1”, “b2”, etc.; also, spectral band alias such as “#RED#” or “#NIR#”; also “b*” for using all the bands.
n_processes – number of threads for calculation.
available_ram – number of megabytes of RAM available to processes.
align_raster – string path of raster used for aligning output pixels and projections.
extent_raster – string path of raster used for extent reference.
extent_list – list of coordinates for defining calculation extent [left, top, right, bottom] in the same coordinates as the reference raster.
extent_intersection – if True the output extent is geometric intersection of input raster extents, if False the output extent is the maximum extent from union of input raster extents.
xy_resolution_list – list of [x, y] pixel resolution.
input_nodata_as_value – if True then unmask the value of nodata pixels in calculations, if False then mask nodata pixels in calculations.
use_value_as_nodata – use integer value as nodata in calculation.
output_nodata – integer value used as nodata in output raster.
output_datatype – string of data type for output raster such as Float64, Float32, Int32, UInt32, Int16, UInt16, or Byte.
use_scale – float number used for scale for output.
use_offset – float number used for offset for output.
calc_datatype – data type used during calculation, which may differ from
output_datatype
, such as Float64, Float32, Int32, UInt32, Int16, UInt16, or Byte.any_nodata_mask – if True then output nodata where any input is nodata, if False then output nodata where all the inputs are nodata, if None then do not apply nodata to output.
bandset_catalog – BandSetCatalog object for using band sets in calculations.
bandset_number – number of BandSet defined as current one.
point_coordinates – list of a point coordinates [x, y] for pixel calculations on Bandset
progress_message – if True then start progress message, if False does not start the progress message (useful if launched from other tools).
- Returns:
OutputManager()
object withpaths = [output raster paths]
Examples
- Sum of two raster files
>>> output_object = band_calc( ... input_raster_list=['file1.tif', 'file2.tif'], output_path='output.tif', ... expression_string='"file1 + file2"', input_name_list=['file1', 'file2'] ... ) >>> # for instance display the output path >>> print(output_object.paths) ['output.tif']
- Calculation setting output datatype
>>> output_object = band_calc( ... input_raster_list=['file1.tif', 'file2.tif'], output_path='output.tif', ... expression_string='"file1 + file2"', input_name_list=['file1', 'file2'], ... output_datatype='Int32' ... )
- Calculation setting the output extent as the maximum extent from union of input raster extents
>>> output_object = band_calc( ... input_raster_list=['file1.tif', 'file2.tif'], output_path='output.tif', ... expression_string='"file1 + file2"', input_name_list=['file1', 'file2'], ... extent_intersection=False ... )