satellitetools.biophys.biophys

Python implementation of ESA SNAP s2toolbox biophysical processor and computation of vegetation indices. See ATBD at https://step.esa.int/docs/extra/ATBD_S2ToolBox_L2B_V1.1.pdf And java source code at https://github.com/senbox-org/s2tbx/tree/master/s2tbx-biophysical/src/main/java/org/esa/s2tbx/biophysical SNAP auxdata from: https://github.com/senbox-org/s2tbx/tree/master/s2tbx-biophysical/src/main/resources/auxdata/2_1

Caveats Currently changes out of bounds inputs and outputs to nan (or min or max value if output wihtin tolerance). Maybe output flagging information as well ( i.e. diffferent flags input and output out of bounds).

Convex hull input checking currently disabled. It’s computationally slow and not sure of its benefits. Better to filter out bad data based on L2A quality info/classification and hope averaging removes some bad pixels.

@author: Olli Nevalainen,

Finnish Meteorological Institute)

Attributes

logger

SNAP_BIO_BANDS

SNAP_BIO_RMSE

Classes

StrEnum

str(object='') -> str

VegetationIndex

Enum where members are also (and must be) strings

BiophysVariable

Enum where members are also (and must be) strings

SNAPBiophysProcessor

SNAP Biophysical Processor.

Functions

create_data_cube(→ xarray.DataArray)

Create data cube for SNAP biophysical processor.

run_snap_biophys(→ xarray.Dataset)

Compute specified variable using the SNAP algorithm.

compute_ndvi(→ xarray.Dataset)

Compute NDVI

compute_ci_red_edge(→ xarray.Dataset)

Compute CI_Red_Edge vegetation index.

compute_gcc(→ xarray.Dataset)

Compute GCC vegetation index.

compute_vegetation_index(→ xarray.Dataset)

Compute vegetation index.

Module Contents

class satellitetools.biophys.biophys.StrEnum[source]

Bases: str, enum.Enum

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

Initialize self. See help(type(self)) for accurate signature.

satellitetools.biophys.biophys.logger[source]
class satellitetools.biophys.biophys.VegetationIndex[source]

Bases: enum.StrEnum

Enum where members are also (and must be) strings

Initialize self. See help(type(self)) for accurate signature.

NDVI = 'ndvi'[source]
CI_RED_EDGE = 'ci_red_edge'[source]
GCC = 'gcc'[source]
class satellitetools.biophys.biophys.BiophysVariable[source]

Bases: enum.StrEnum

Enum where members are also (and must be) strings

Initialize self. See help(type(self)) for accurate signature.

FAPAR = 'fapar'[source]
FCOVER = 'fcover'[source]
LAI = 'lai'[source]
LAI_Cab = 'lai_cab'[source]
LAI_Cw = 'lai_cw'[source]
classmethod get_by_name(name: str) BiophysVariable[source]

Get BiophysVariable by name.

Parameters:

name (str) – Name of the biophysical variable.

Returns:

BiophysVariable or raise Valuer error if not found.

Return type:

Union[None, “BiophysVariable”]

satellitetools.biophys.biophys.SNAP_BIO_BANDS[source]
satellitetools.biophys.biophys.SNAP_BIO_RMSE[source]
class satellitetools.biophys.biophys.SNAPBiophysProcessor(data_cube: xarray.DataArray, variable: BiophysVariable)[source]

SNAP Biophysical Processor.

data_cube[source]

Data cube with Sentinel-2 10-20m bands and observation geometry layers biophysical bands.

Type:

xr.DataArray

variable[source]

Biophysical variable to compute.

Type:

BiophysVariable

nn_params[source]

Neural network parameters.

Type:

dict

Initialize SNAPBiophysProcessor.

Parameters:
  • data_cube (xr.DataArray) – Data cube with Sentinel-2 10-20m bands and observation geometry layers biophysical bands.

  • variable (BiophysVariable) – Biophysical variable to compute.

data_cube[source]
variable[source]
nn_params[source]
_read_snap_nn_params(variable: BiophysVariable) dict[source]
_normalization(x)[source]
_denormalization(x)[source]
_input_ouf_of_range(x)[source]
_output_ouf_of_range(x)[source]
_layer1(x)[source]
_layer2(x)[source]
_run_neural_network(x)[source]
run() xarray.DataArray[source]

Run SNAP Biophysical Processor.

Returns:

Array of the computed biophysical variable.

Return type:

xr.DataArray

satellitetools.biophys.biophys.create_data_cube(ds: xarray.Dataset) xarray.DataArray[source]

Create data cube for SNAP biophysical processor.

Parameters:

ds (xr.Dataset) – xarray dataset.

Returns:

Data cube with Sentinel-2 10-20m bands and observation geometry layers biophysical bands.

Return type:

xr.DataArray

satellitetools.biophys.biophys.run_snap_biophys(ds: xarray.Dataset, variable: BiophysVariable) xarray.Dataset[source]

Compute specified variable using the SNAP algorithm.

See ATBD at https://step.esa.int/docs/extra/ATBD_S2ToolBox_L2B_V1.1.pdf

Parameters:
  • ds (xr dataset) – xarray dataset.

  • variable (Union[str, BiophysVariable]) – Options ‘FAPAR’, ‘FCOVER’, ‘LAI’, ‘LAI_Cab’ or ‘LAI_Cw’

Returns:

Adds the specified variable array to the input dataset.

Return type:

xarray dataset

satellitetools.biophys.biophys.compute_ndvi(ds: xarray.Dataset) xarray.Dataset[source]

Compute NDVI

Parameters:

ds (xarray dataset)

Returns:

Adds ‘ndvi’ xr array to xr dataset.

Return type:

xarray dataset

satellitetools.biophys.biophys.compute_ci_red_edge(ds: xarray.Dataset) xarray.Dataset[source]

Compute CI_Red_Edge vegetation index.

Parameters:

ds (xarray dataset)

Returns:

Adds ‘ci_red_edge’ xr array to xr dataset.

Return type:

xarray dataset

satellitetools.biophys.biophys.compute_gcc(ds: xarray.Dataset) xarray.Dataset[source]

Compute GCC vegetation index.

Parameters:

ds (xarray dataset)

Returns:

Adds ‘gcc’ xr array to xr dataset.

Return type:

xarray dataset

satellitetools.biophys.biophys.compute_vegetation_index(ds: xarray.Dataset, vi: VegetationIndex) xarray.Dataset[source]

Compute vegetation index.

Parameters:
  • ds (xarray dataset)

  • vi (VegetationIndex) – Vegetation index to compute.

Returns:

Adds vegetation index array to xr dataset.

Return type:

xarray dataset