Vegetation indices

remote_sensing_processor.calculate_index(name, input_path, output_path=None, bands=None, suffix=None, nodata=None, write_stac=True)[source]

Calculates vegetation indexes.

Parameters:
  • name (string) – Name of index. If the index is not supported, then it will be considered a normalized difference index. RSP supports all the indices supported by spyndex and listed here.

  • input_path (string or STAC Item) – A path to a directory or a STAC dataset or a STAC Item with imagery product. If you define a supported imagery product and a name of supported index, you do not need to define bands. Bands needed for index calculation are picked automatically.

  • output_path (string (optional)) – Path to a directory where the output index will be saved. If not set, then will write to the same directory as input_path. Must be set if input is a remote STAC Item.

  • bands (dict of strings, ints or floats (optional)) –

    Bands and coefficients to calculate the index. Only needed if imagery product or the index is not currently supported or if you want to set your own custom coefficients or constants values (e.g. C1, C2, g and L for EVI). Dictionary keys are the same as here.

  • suffix (str (optional)) – You can define a suffix that will be added to a file name if you want the file name of your index to be different from index name (e.g. if you want to try several parameter combinations).

  • nodata (int or float (default = None)) – Nodata value. If not set, then is read from inputs.

  • write_stac (bool (default = True)) – If True, then output metadata is saved to a STAC file.

Returns:

Path where index raster is saved.

Return type:

pathlib.Path

Examples

>>> import remote_sensing_processor as rsp
>>> # Calculate NDVI from Sentinel 2 product with stac metadata
>>> ndvi = rsp.calculate_index(
...     name="NDVI",
...     input_path="/home/rsp_test/mosaics/sentinel/meta.json",
... )
>>> print(ndvi)
'/home/rsp_test/mosaics/sentinel/NDVI.json'
>>> # Calculate EVI from Sentinel 2 product by directly defining bands and coefficients
>>> evi = rsp.calculate_index(
...     name="EVI",
...     input_path="/home/rsp_test/mosaics/sentinel/",
...     output_path="/home/rsp_test/mosaics/sentinel_indices/",
...     bands={"N": "B8", "R": "B4", "B": "B2", "g": 2.5, "C1": 6, "C2": 7.5, "L": 1},
...     suffix="C1-6",
... )
>>> print(evi)
'/home/rsp_test/mosaics/sentinel/sentinel_indices/EVI-C1-6.json'