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#
|
The cube's band coordinates (including |
|
Each band's index in the sensor's full band set ( |
|
Convert a product file of any supported layout to the current format. |
|
Whether the product has a band cube (every level but L2B and L2A.AUX). |
|
Whether a product with these global attributes has no band cube: L2B, |
|
Whether the product has pixel coordinates (an L1B only after georeferencing). |
|
Per-band metadata of a product file, without reading pixel data. |
|
Read any supported HYPSO product file into the in-memory model. |
|
A product file's layout: |
|
(y, x) for a gridded product, else (lines, samples). |
|
Write a DataTree to NetCDF so that |
|
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_indexwhen present), to carry over to a new cube on the same bands.- Return type:
- hypso.io.product.band_indices(cube)[source]#
Each band’s index in the sensor’s full band set (
band_indexcoordinate, else0..n-1).- Return type:
- hypso.io.product.convert_product(src, out_dir=None)[source]#
Convert a product file of any supported layout to the current format.
- Parameters:
src (str or pathlib.Path)
out_dir (str or pathlib.Path, optional) – Default: next to
src.
- Returns:
The new file, named by
hypso.io.naming. Aconvertstep is recorded; the source file is left untouched.- Return type:
- 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:
- 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:
- hypso.io.product.is_georeferenced(tree)[source]#
Whether the product has pixel coordinates (an L1B only after georeferencing).
- Parameters:
tree (xarray.DataTree)
- Return type:
- hypso.io.product.list_band_variables(path)[source]#
Per-band metadata of a product file, without reading pixel data.
- 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:
- 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"(/productsand/geometrygroups) or"ground_station_l1a".- Return type:
- hypso.io.product.spatial_dims(ds)[source]#
(y, x) for a gridded product, else (lines, samples).
- Return type:
- hypso.io.product.write_netcdf_safely(tree, path, encoding=None, retries=1)[source]#
Write a DataTree to NetCDF so that
pathis 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 writeretriestimes. 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:
tree (xarray.DataTree)
retries (int)
- Return type:
- 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 theband_quantizationglobal attribute.
- Return type:
None