eoio.processors.units.drivers.s2msi1c module#

eoio.processors.units.drivers.s2msi1c - unit conversion for Sentinel-2 MSI L1c products

class eoio.processors.units.drivers.s2msi1c.S2MSI1CUnitDriver[source]#

Bases: BaseUnitConversionDriver

Sentinel-2 MSI L1c unit conversion driver.

Intended scope: - reflectance -> radiance, using metadata available in the product

This driver assumes eoio readers provide enough product identification to allow cheap matching (e.g. ds.attrs[‘eoio:product’] in {“sentinel2_l1c”, “sentinel2_l2a”}).

Notes

Sentinel-2 unit conversion depends on: - per-band solar irradiance (E_sun) and band definitions - solar zenith angle (or sun elevation) at acquisition time / tile - any scaling/quantification already applied by the reader

Where those values live should be standardised in dataset and variable attrs.

convert(ds: Dataset, to: str, var_names: Sequence[str] | None, *, context: Mapping[str, Any]) Dataset[source]#

Convert selected variables in the dataset to the requested target units, based on supported conversion pairs. If no variables are selected, the default is all measurement vars. Converts the data using conversion coefficients found in metadata (E_sun, solar zenith, etc.) and updates units attributes accordingly.

Using algorithm from senbox.org/s2tbx <https://htmlpreview.github.io/?https://github.com/senbox-org/s2tbx/blob/bca0c210fc15f0f95128dceaa512947388bc4f97/s2tbx-reflectance-to-radiance-ui/src/main/resources/org/esa/s2tbx/reflectance2radiance/docs/ReflectanceToRadianceAlgorithmSpecification.html>

radiance = pixelValue * cosine(radians(incidenceAngle)) * solarIrradiance * U / pi

Parameters:
  • ds – Input dataset.

  • to – Target unit name (e.g. “radiance”).

  • var_names – Variables to convert. If None default is all measurement vars.

  • context – Processing context provided by eoio, passed to all processors.

Returns:

Dataset with converted variables.

Raises:
  • ValueError – If an unsupported conversion is requested.

  • KeyError – If requested variables are not present.

static interp_var_s2(ds, target_resolution, var='solar_zenith_angle')[source]#

Interpolate var data from source to target resolution

Parameters:
  • ds – S2 ds read in by eoio

  • target_resolution – resolution to interpolate to

Returns:

interpolated data on target resolution grid

matches(ds: Dataset, context: Mapping[str, Any]) bool[source]#

Determine whether this driver can handle the given dataset.

Matching should be cheap and unambiguous; avoid heavy inspection.

Parameters:
  • ds – Input dataset.

  • context – Processing context provided by eoio.

Returns:

True if this looks like a Sentinel-2 MSI dataset, otherwise False.

name: str = 's2msi1c'#
static rfl_to_rad(rfl: float | ndarray | DataArray, sza: float | ndarray, e_sol: float | ndarray, u: float | int) float | ndarray | DataArray[source]#

Convert reflectance to radiance

Parameters:
  • rfl – reflectance(s)

  • sza – solar zenith angle (radians)

  • e_sol – solar irradiance

  • u – Earth-Sun distance correction factor

Returns:

radiance (W/(m²*sr*μm))

supported() Set[Tuple[str, str]][source]#

Return supported conversion pairs.

Returns:

Set of supported (from_unit, to_unit) pairs.