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,navigation_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})
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 navigation_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.
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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| obpg_writel2-1.0.0.tar.gz | 13.8 kB | Without provenance | Details for obpg_writel2-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| obpg_writel2-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for obpg_writel2-1.0.0-py3-none-any.whl |
Total release size: 27.2 kB
Release files / obpg_writel2-1.0.0.tar.gz
| Download URL | obpg_writel2-1.0.0.tar.gz |
|---|---|
| Size | 13.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e0c857a610f88778d36ecf96280b17fa4fe0d2f363990108375b756d329eb36
|
|
BLAKE2b-256 checksum How to use checksums |
fcff0d1c4a9fc042ec09c57a6e721c6ee169d7bacd6947c20bd1bd37da3f563d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / obpg_writel2-1.0.0-py3-none-any.whl
| Download URL | obpg_writel2-1.0.0-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
326a4ee6d7356ceb329c1f1a3cec490d699bc9bf4a0af9e4f3a8c928d333d924
|
|
BLAKE2b-256 checksum How to use checksums |
66af339a28d2748be210afc21c836f79853d9e5d9c93f273e51be676131297d9
|
| 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.0
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.