writel2
Helpers for writing standard-layout L2 NetCDF4 ocean color products from Python, and for reading metadata back out of an existing L2 file.
writel2.L2Writercreates the standard l2gen group layout (sensor_band_parameters,scan_line_attributes,geophysical_data,geolocation_data,processing_control/input_parameters[/flag_percentages]), preloads the static global attributes, and writes variables into any of those groups viawrite_product(name, data, group=...), whose attributes (long_name,units,valid_min/valid_max,scale_factor/add_offset,_FillValue,flag_values/flag_meanings,reference,comment, ...) are resolved fromshare/common/product.xml- the same metadata l2gen itself uses, regardless of which group a variable belongs to.writel2.L2Readeris a read-only helper for pulling metadata back out of an existing L2 (or L1/L3) file, mainly soL2Writercan seed a derived product's global attributes from its source file.writel2.ProductTableresolves a product name (e.g."chlor_a","Rrs_443") againstproduct.xmlinto aProductInforecord.writel2.GlobalMetadataloads the static, institution-wide global attributes (license, naming authority, creator/publisher info, ...) from$OCDATAROOT/common/global_metadata.json.
Install
pip install $OCSSWROOT/src/scripts/writel2
This installs as obpg-writel2, importable as writel2.
Usage
See examples/demo_write_l2.py for a complete,
runnable example that writes a small file touching every group:
python $OCSSWROOT/src/scripts/writel2/examples/demo_write_l2.py /tmp/demo_l2.nc
The short version:
import numpy as np
from writel2 import L2Writer
with L2Writer("out.L2.nc", title="Demo Level-2 Data") as writer:
# geophysical_data: resolved against product.xml for long_name, units,
# valid_min/valid_max, scale_factor/add_offset, _FillValue, ...
flags = np.zeros((4, 3), dtype=np.int32)
writer.write_product("l2_flags", flags)
# processing_control/input_parameters and /flag_percentages
writer.set_input_parameters({"ifile": "input.L1B.nc", "l2prod": "l2_flags"})
writer.set_flag_percentages({"ATMFAIL": 0.0, "LAND": 0.49})
# Global attribute (group=None, the default) or group-level attribute
# (group=writer.groups[...]).
writer.set_group_attrs({"scene_id": "DEMO-0001"})
Datatype and attributes for any group's variables are resolved from
product.xml and applied automatically by write_product(), including
appropriate scaling - pass group= to target sensor_band_parameters,
scan_line_attributes, or geolocation_data instead of the default
geophysical_data. The one exception is geophysical_data's own local
wavelength coordinate variable (used alongside 3D products), which l2gen
writes directly rather than resolving against product.xml; the calling
script must set its datatype and attributes manually. See the demo script
for the full pattern, including how to register dimensions shared across
groups.
navigation_data is still accepted as a standard group name for
latitude/longitude (and still triggers geospatial_bounds), but it's
deprecated - writing to it logs a warning recommending geolocation_data
instead.
Public API
L2Writer:
write_product(name, data, dim_names=(...), group="geophysical_data")- resolvenameagainstproduct.xmland write it intogroup; returns the createdh5netcdf.Variable.set_group_attrs(attrs, group=None)- write attributes to a group; withgroup=None(the default) writes global (file-level) attributes.set_input_parameters(params)- write attributes toprocessing_control/input_parameters.set_flag_percentages(percentages, group_name="flag_percentages")- write attributes toprocessing_control/<group_name>.flag_percentages_group(name="flag_percentages")- get (creating if needed) the named child group ofprocessing_control.copy_global_attrs_from(source, names=None, overrides=None)- copy global attributes from anL2Reader, optionally restricted tonamesand/or overridden byoverrides.close()- close the underlying file (also called on__exit__).
L2Reader:
global_attrs(property) - the source file's global attributes as adict.group(name)- the namedh5netcdf.Group, orNoneif absent.is_l2()- whether the source file looks like an L2 file.copy_global_attrs_to(dest, names=None)- copy global attributes ontodest(anh5netcdf.FileorGroup), optionally restricted tonames.close()- close the underlying file (also called on__exit__).
ProductTable.find(name, wavelengths=None) resolves a product name into a
ProductInfo record. GlobalMetadata loads
$OCDATAROOT/common/global_metadata.json and exposes its contents as a
dict-like object.
Tests
pip install $OCSSWROOT/src/scripts/writel2
python -m unittest discover -s $OCSSWROOT/src/scripts/writel2/tests
Metadata
Release files for obpg-writel2 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| obpg_writel2-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for obpg_writel2-1.0.2-py3-none-any.whl |
Release files / obpg_writel2-1.0.2-py3-none-any.whl
| Download URL | obpg_writel2-1.0.2-py3-none-any.whl |
|---|---|
| Size | 20.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0a0637fcec46d3986a51ef4dccf3b5131598d9ef2bf793bc53443103b54d1d0c
|
|
BLAKE2b-256 checksum How to use checksums |
97f8d3f79dbe4b70ebcee57da54ec8adbd17be27184f308cd0cd11d9a2a56ef1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for obpg-writel2 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.