hypso.io.product#

One reader and one writer for every HYPSO product level, on xarray.DataTree.

In-memory model (what read_product() returns and write_product() takes):

/                     root Dataset
    <prefix>          product cube, dims (lines, samples, bands), or
                      (y, x, bands) on a map grid (hypso.grid): "dn"
                      (L1A), "Lt" (L1B), "rhot" (L1C), or the AC
                      variable for L2A (e.g. "Rrs", "rhos")
    wavelength        coord (bands): nominal band centre, 0.1 nm rounded
    radiation_wavelength  coord (bands): precise as-calibrated centre
    fwhm              coord (bands)
    latitude, longitude, crs_wgs84, <angles>   only when georeferenced
    pixel_flags       optional CF flag variable (hypso.masks.flags);
                      the product itself is unmasked
    <other>           any other 2D variable - derived products such as
                      a chlorophyll map - with its attributes
    x, y, crs         gridded products only: projection coordinates and
                      the CF grid-mapping variable (latitude/longitude
                      stay, as 2D auxiliary coordinates)
    attrs             global attributes; processing_level is required
/metadata/<group>     one child node per metadata group

On disk the cube is one 2D variable per band (Lt_378, …), the layout ESA SNAP reads, with geometry at the root and metadata/* nested. All CF attributes come from hypso.io.cf, so a file read in any supported layout is written back in the current one. Supported layouts: current flat files, older grouped files (/products and /geometry), and ground-station L1A files (one uint16 /products/dn cube).

Functions#

band_coords(cube)

The cube's band coordinates (including band_index when present), to

band_indices(cube)

Each band's index in the sensor's full band set (band_index

convert_product(src[, out_dir])

Convert a product file of any supported layout to the current format.

has_cube(tree)

Whether the product has a band cube (every level but L2B and L2A.AUX).

is_cubeless(attrs)

Whether a product with these global attributes has no band cube: L2B,

is_georeferenced(tree)

Whether the product has pixel coordinates (an L1B only after georeferencing).

list_band_variables(path)

Per-band metadata of a product file, without reading pixel data.

read_product(path[, wavelength_range, wavelengths, ...])

Read any supported HYPSO product file into the in-memory model.

source_layout(path)

A product file's layout: "current", "legacy" (/products and /geometry groups) or "ground_station_l1a".

spatial_dims(ds)

(y, x) for a gridded product, else (lines, samples).

write_netcdf_safely(tree, path[, encoding, retries])

Write a DataTree to NetCDF so that path is either the complete file or untouched.

write_product(tree, path[, datacube, significant_bits])

Write a product tree in the current file format.

Module Contents#

hypso.io.product.band_coords(cube)[source]#

The cube’s band coordinates (including band_index when present), to carry over to a new cube on the same bands.

Return type:

dict

hypso.io.product.band_indices(cube)[source]#

Each band’s index in the sensor’s full band set (band_index coordinate, else 0..n-1).

Return type:

numpy.ndarray

hypso.io.product.convert_product(src, out_dir=None)[source]#

Convert a product file of any supported layout to the current format.

Parameters:
Returns:

The new file, named by hypso.io.naming. A convert step is recorded; the source file is left untouched.

Return type:

pathlib.Path

hypso.io.product.has_cube(tree)[source]#

Whether the product has a band cube (every level but L2B and L2A.AUX).

Parameters:

tree (xarray.DataTree)

Return type:

bool

hypso.io.product.is_cubeless(attrs)[source]#

Whether a product with these global attributes has no band cube: L2B, and the L2A.AUX file of an AC tool’s other outputs.

Return type:

bool

hypso.io.product.is_georeferenced(tree)[source]#

Whether the product has pixel coordinates (an L1B only after georeferencing).

Parameters:

tree (xarray.DataTree)

Return type:

bool

hypso.io.product.list_band_variables(path)[source]#

Per-band metadata of a product file, without reading pixel data.

Returns:

{"name", "band", "wavelength", "radiation_wavelength", "fwhm", "units", "long_name"} sorted by band index, or one entry with band None for a single-cube (datacube) file. Used by the Satpy readers.

Return type:

list of dict

hypso.io.product.read_product(path, wavelength_range=None, wavelengths=None, indices=None)[source]#

Read any supported HYPSO product file into the in-memory model.

Parameters:
  • path (str or pathlib.Path)

  • wavelength_range (optional) – Read only some bands, selected as in hypso.processing.bands.select_bands() (at most one of them). Only the selected band variables are read from the file; a file holding the cube as one variable is read whole and then subset.

  • wavelengths (optional) – Read only some bands, selected as in hypso.processing.bands.select_bands() (at most one of them). Only the selected band variables are read from the file; a file holding the cube as one variable is read whole and then subset.

  • indices (optional) – Read only some bands, selected as in hypso.processing.bands.select_bands() (at most one of them). Only the selected band variables are read from the file; a file holding the cube as one variable is read whole and then subset.

Returns:

See the module description. tree.encoding["source"] holds the path (not written back).

Return type:

xarray.DataTree

Raises:

ValueError – If no product cube or processing level is found, or the file uses the levels from before format 3.0.

hypso.io.product.source_layout(path)[source]#

A product file’s layout: "current", "legacy" (/products and /geometry groups) or "ground_station_l1a".

Return type:

str

hypso.io.product.spatial_dims(ds)[source]#

(y, x) for a gridded product, else (lines, samples).

Return type:

tuple

hypso.io.product.write_netcdf_safely(tree, path, encoding=None, retries=1)[source]#

Write a DataTree to NetCDF so that path is either the complete file or untouched.

The file is written on local disk first ($HYPSO_WRITE_TMPDIR, default the system temporary directory), copied next to the destination as <name>.part, checked (SHA-256 of the copy against the local file) and renamed into place. An HDF or I/O error retries the whole write retries times. Writing NetCDF/HDF5 directly to a network file system failed now and then (“NetCDF: HDF error” in about 1 of 100 writes to the NFS home, 2026-11); a plain sequential copy is far less exposed, and a failed attempt never leaves a partial file under the real name.

Parameters:
Return type:

pathlib.Path

hypso.io.product.write_product(tree, path, datacube=False, significant_bits=SIGNIFICANT_BITS)[source]#

Write a product tree in the current file format.

Parameters:
  • tree (xarray.DataTree) – In-memory model (see the module description).

  • path (str or pathlib.Path)

  • datacube (bool, default False) – Write the cube as one 3D variable instead of one variable per band.

  • significant_bits (int or None, default 14) – Keep this many significant mantissa bits of the float band variables (L1B-L2A; netCDF BitRound, max relative error 2**-(bits + 1); values stay float32, NaN is kept, readers need nothing special). None writes them lossless. L1A counts, geometry, derived variables and metadata are always lossless. Recorded in the band_quantization global attribute.

Return type:

None