dep_tools.processors module

Definition of base class and implementations of Processor objects.

Processor objects process input data to produce output data. As such, they are the most likely to be written for custom processing.

class dep_tools.processors.Processor(send_area_to_processor=False)[source]

Bases: ABC

A Processor converts input data to output data.

Parameters:

send_area_to_processor (bool) – Whether to send the input area (typically used by a loader to load appropriate data) to the processor.

abstract process(input_data)[source]

Process the data.

Parameters:

input_data (Any) – Any data.

class dep_tools.processors.LandsatProcessor(send_area_to_processor=False, scale_and_offset=True, mask_clouds=True, mask_clouds_kwargs={})[source]

Bases: Processor

A Processor for use with Landsat data.

Typically this Processor will be subclassed when working with Landsat data

Parameters:
  • scale_and_offset (bool) – Whether to scale and offset the input data. Landsat data is typically stored in 16-bit integers, this applies the standard scale and offset values to each band for surface reflectance data and (as a side effect) converts the data type to floating point.

  • mask_clouds (bool) – Whether to mask_clouds, using dep_tools.landsat_utils.mask_clouds_landsat().

  • mask_clouds_kwargs (dict) – Additional arguments to dep_tools.landsat_utils.mask_clouds_landsat().

process(xr)[source]

Process the data.

Parameters:

xr (DataArray | Dataset) – Any input data, but to benefit from the functionality of this class, input should be Landsat surface reflectance data, typically with the “QA_PIXEL” band as well.

Return type:

DataArray | Dataset

Returns:

The input data, optionally with clouds masked and/or scale and offset applied.

class dep_tools.processors.S2Processor(send_area_to_processor=False, scale_and_offset=False, mask_clouds=True, mask_clouds_kwargs={})[source]

Bases: Processor

A Processor for use with Sentinel-2 data.

Typically this Processor will be subclassed when working with Sentinel-2 data.

Parameters:
  • scale_and_offset (bool) – Whether to scale and offset the input data. Landsat data is typically stored in 16-bit integers, this applies the standard scale and offset values to each band for surface reflectance data and (as a side effect) converts the data type to floating point.

  • mask_clouds (bool) – Whether to mask_clouds, using dep_tools.s2_utils.mask_clouds().

  • mask_clouds_kwargs (dict) – Additional arguments to dep_tools.s2_utils.mask_clouds().

process(xr)[source]

Process the data.

Parameters:

xr (DataArray) – Any input data, but to benefit from the functionality of this class, input should be Sentinel-2 data, typically including the “SCL” band.

Return type:

DataArray

Returns:

The input data, optionally with clouds masked and/or scale and offset applied.

class dep_tools.processors.XrPostProcessor(convert_to_int16=True, output_value_multiplier=10000, scale_int16s=False, output_nodata=-32767, extra_attrs={})[source]

Bases: Processor

A Processor with typical things to do to output data.

Some Task objects allow for use of a Processor to prep data for writing after the actual processing. This is mostly a wrapper around scale_to_int16().

Parameters:
  • convert_to_int16 (bool) – Whether to convert output data to 16-bit (signed) integer.

  • output_value_multiplier (int) – A multiplier to apply to the input data.

  • scale_int16s (bool) – Whether data which is already 16-bit signed integer should be scaled using output_value_multiplier.

  • output_nodata (int) – The nodata value to be declared in the output.

  • extra_attrs (dict) – Extra attributes to add to the output data.

process(xr)[source]

Process the data.

Parameters:

xr (DataArray | Dataset) – Any input data.

Returns:

The input data, with scaling, type-conversion and other adjustments applied.