hypso.processing#
Processing steps as functions from one product tree to the next level’s.
The trees are hypso.io.product’s in-memory model; hypso.Product
calls these functions. Each step records itself in metadata/processing
(hypso.io.provenance) and leaves its input tree unchanged.
Submodules#
Functions#
|
Capture parameters (dimensions, binning, timing, sensor profile) from a |
|
The imaging mode ("nominal", "wide", "moon", ...): the first of the |
|
Atmospheric correction of an L1C tree. |
|
An L2B tree from one of the package's algorithms on an L2A. |
|
Add pixel coordinates and sun and sensor angles to an L1B tree. |
|
Calibrate an L1A tree to L1B (top-of-atmosphere radiance |
|
Top-of-atmosphere reflectance |
|
An L2B tree from an L2A tree and the derived variables. |
|
A product tree with only some of its bands. |
|
Separate an L2A's AC-tool products from its reflectance. |
|
Top-of-atmosphere reflectance from radiance. |
Package Contents#
- hypso.processing.capture_params(tree)[source]#
Capture parameters (dimensions, binning, timing, sensor profile) from a product tree’s
metadata/capture_configand global attributes.- Parameters:
tree (xarray.DataTree)
- Return type:
CaptureParams
- hypso.processing.classify_capture_type(profile, values)[source]#
The imaging mode (“nominal”, “wide”, “moon”, …): the first of the sensor’s capture_type_thresholds whose attribute (frame_count, image_height, …) has its value in values; “custom” otherwise.
- Parameters:
profile (hypso.sensors.SensorProfile)
values (dict)
- Return type:
- hypso.processing.correct_atmosphere(tree, method='machi', masked=False, mask_flags=None, work_dir=None, config=None, **options)[source]#
Atmospheric correction of an L1C tree.
- Parameters:
tree (xarray.DataTree) – L1C product tree in sensor geometry (not regridded).
method ({"machi", "dps", "polymer", "acolite", "ocsmart"}, default "machi") – See the module description. polymer and acolite are not ported to the current levels yet and raise NotImplementedError.
masked (bool, default False) – Give the method NaN where
pixel_flagsare set (all flags, or onlymask_flags). The input product itself stays unmasked.mask_flags (list of str, optional) – Flags to mask with, e.g.
["land", "cloud"].work_dir (str or path, optional) – External tools only: where the staged input and the tool’s raw output go (kept); default a temporary directory, removed afterwards.
config (str, path or dict, optional) – External tools only: AC tool configuration (
hypso.ac.config); default theHYPSO_AC_CONFIGenvironment variable.**options – Method-specific. machi:
est_min_R(expected minimum surface reflectance, default 0.05),tol(default 0.01),approach_rate(default 1),fit_exclude_flags(pixel_flags names left out of the fit; default none, all finite pixels),fit_subsample(fit on every Nth pixel plus each band’s darkest; default 1, all). dps:statistic("min"or"percentile"),percentile. polymer, acolite, ocsmart: any key of the tool’s configuration section (e.g.settings={...}), overriding it; acolite alsooutput("l2w"or"l2r") andreuse_output.
- Returns:
L2A tree.
- Return type:
- hypso.processing.derive(tree, group, algorithm=None)[source]#
An L2B tree from one of the package’s algorithms on an L2A.
- Parameters:
tree (xarray.DataTree) – An L2A tree; most algorithms need
Rrs(L2A.RRS.*).group (str) – L2B group,
"BGC"or"IOP".algorithm (str, optional) – See
hypso.processing.l2b_algorithms.ALGORITHMS; default the group’s default (BGC:"oci", IOP:"qaa").
- Returns:
...L2B.<group>.<algorithm>.- Return type:
- hypso.processing.georeference_l1b(tree, latitudes=None, longitudes=None, direct=True)[source]#
Add pixel coordinates and sun and sensor angles to an L1B tree.
An already georeferenced L1B gets new geometry; none of the old is kept.
- Parameters:
tree (xarray.DataTree) – L1B product tree.
latitudes (array_like or path, optional) – Indirect pixel coordinates,
(lines, samples)arrays or paths to raw float32 files. Omit both to use direct georeferencing as the main geometry.longitudes (array_like or path, optional) – Indirect pixel coordinates,
(lines, samples)arrays or paths to raw float32 files. Omit both to use direct georeferencing as the main geometry.direct (bool, default True) – Also compute direct georeferencing from the ADCS telemetry (
latitude_direct,longitude_direct,<angle>_direct). Skipped with a warning if the telemetry points off the Earth.
- Returns:
L1B tree with geometry.
- Return type:
- hypso.processing.l1a_to_l1b(tree, coeff_type=None, version=None, coeff_files=None, radiometric=True, smile=True, destripe=True, spectral=True, keystone=False)[source]#
Calibrate an L1A tree to L1B (top-of-atmosphere radiance
Lt).- Parameters:
tree (xarray.DataTree) – L1A product tree.
coeff_type (str, optional) – Radiometric variant:
"abs"(default),"moved"or"lab", or a set registered withhypso.calibration.register_calibration_coeffs. None uses the file’sradiometric_coefficients_versionif present, else the default. Withoutversion, a variant the default release lacks takes the newest release that has it (HYPSO-1"moved": V2).version (str or dict, optional) – Coefficient release -
"V3.1"(default),"V3.1v2spec"(V2 band names, for OC-SMART),"V2","V1";"V3"means V3.1 - or{correction: release}to mix them, e.g.{"smile": "V2"}(the calibration package’sdata/coefficients.yaml).coeff_files (dict, optional) – Explicit
{kind: path}instead ofcoeff_typeandversion.radiometric (bool, default True) – False skips that correction.
smile (bool, default True) – False skips that correction.
destripe (bool, default True) – False skips that correction.
spectral (bool, default True) – False skips that correction.
keystone (bool, default False) – Also correct keystone (spatial misregistration across the spectrum) with the sensor’s optional distortion model, after radiometric calibration and before smile (
hypso.calibration.keystone). Groundwork, unreviewed: HYPSO-2’s model is shipped disabled, so this warns; sensors without a model raise ValueError.
- Returns:
L1B tree, without geometry (
hypso.processing.georeference_l1b()adds it). The files used, their checksums and the package versions are recorded inmetadata/processing/l1b, and a summary is logged.- Return type:
- hypso.processing.l1b_to_l1c(tree, use_direct_georef=False, ssi_source='tsis', use_unbinned=True)[source]#
Top-of-atmosphere reflectance
rhotfrom a georeferenced L1B tree.- Parameters:
tree (xarray.DataTree) – Georeferenced L1B product tree (sensor geometry or gridded).
use_direct_georef (bool, default False) – Use
solar_zenith_directinstead ofsolar_zenith, when present.ssi_source ({"tsis", "thuillier"}, default "tsis") – Solar irradiance spectrum: TSIS-1 HSRS or Thuillier (2002).
use_unbinned (bool, default True) – Build the spectral response functions from the unbinned wavelengths and bin them, instead of from the binned band centres.
- Returns:
L1C tree with
metadata/srf.- Return type:
- hypso.processing.make_l2b(tree, group, source, variables, parameters=None)[source]#
An L2B tree from an L2A tree and the derived variables.
- Parameters:
tree (xarray.DataTree) – The L2A product the variables were derived from.
group (str) – Product group, a key of
hypso.io.naming.L2B_GROUPS.source (str) – Algorithm or tool, e.g.
"oc4"or"polymer"(a file-name token).variables (dict) –
{name: xarray.DataArray or (array, attrs)}, each of the product’s spatial shape; attributes should includeunitsandlong_name.parameters (dict, optional) – Recorded in the
l2b_<group>_<source>provenance step.
- Return type:
- hypso.processing.select_bands(tree, wavelength_range=None, wavelengths=None, indices=None)[source]#
A product tree with only some of its bands.
- Parameters:
tree (xarray.DataTree) – L1B, L1C or L2A product tree.
wavelength_range (tuple of float, optional) –
(min, max)in nm: the bands whose centre lies within it.wavelengths (array_like, optional) – Wavelengths in nm: the nearest band to each.
indices (array_like of int, optional) – Band indices in the sensor’s full band set (
band_index).
- Returns:
Same level, with the kept bands’
band_index,metadata/srf(andmetadata/machi) trimmed to them, and aselect_bandsstep.- Return type:
- hypso.processing.split_tool_products(tree)[source]#
Separate an L2A’s AC-tool products from its reflectance.
- Parameters:
tree (xarray.DataTree) – An L2A tree, e.g. from
hypso.processing.correct_atmosphere()or an L2A file written before the products moved to L2B.- Returns:
(l2a_tree, {group: l2b_tree}): the L2A without the products, and one L2B tree per group (hypso.io.naming.L2B_GROUPS), named after the AC tool (L2B.BGC.polymer). The tool’s flag variables are kept in the L2A and copied into each L2B.- Return type:
- hypso.processing.toa_reflectance(radiance, f0, iso_time, solar_zenith)[source]#
Top-of-atmosphere reflectance from radiance.
rho = pi L d^2 / (F0 cos(sza)), withdthe Earth-Sun distance in AU (Normalized reflectances).- Parameters:
radiance (numpy.ndarray) –
(lines, samples, bands)radiance in W m-2 um-1 sr-1.f0 (array_like) – Per-band solar irradiance F0 in mW m-2 nm-1 (numerically equal to W m-2 um-1).
iso_time (str) – Acquisition time (ISO 8601), for the Earth-Sun distance.
solar_zenith (numpy.ndarray) –
(lines, samples)solar zenith angle in degrees.
- Returns:
Reflectance, in the radiance’s dtype.
- Return type: