obpg-writel2 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- obpg_writel2-1.0.0/PKG-INFO +85 -0
- obpg_writel2-1.0.0/README.md +75 -0
- obpg_writel2-1.0.0/obpg_writel2.egg-info/PKG-INFO +85 -0
- obpg_writel2-1.0.0/obpg_writel2.egg-info/SOURCES.txt +15 -0
- obpg_writel2-1.0.0/obpg_writel2.egg-info/dependency_links.txt +1 -0
- obpg_writel2-1.0.0/obpg_writel2.egg-info/requires.txt +2 -0
- obpg_writel2-1.0.0/obpg_writel2.egg-info/top_level.txt +1 -0
- obpg_writel2-1.0.0/pyproject.toml +26 -0
- obpg_writel2-1.0.0/setup.cfg +4 -0
- obpg_writel2-1.0.0/src/__init__.py +13 -0
- obpg_writel2-1.0.0/src/global_metadata.py +48 -0
- obpg_writel2-1.0.0/src/product_info.py +425 -0
- obpg_writel2-1.0.0/src/reader.py +84 -0
- obpg_writel2-1.0.0/src/writer.py +289 -0
- obpg_writel2-1.0.0/tests/test_product_info.py +67 -0
- obpg_writel2-1.0.0/tests/test_reader.py +83 -0
- obpg_writel2-1.0.0/tests/test_writer.py +124 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: obpg-writel2
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Helpers for reading L2 metadata and writing derived L2 NetCDF4 products
|
|
5
|
+
Author-email: Gwyn Fireman <Gwyn.F.Fireman@nasa.gov>, Claude Sonnet 5 <noreply@anthropic.com>
|
|
6
|
+
Requires-Python: >=3.12
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: numpy>=1.26.4
|
|
9
|
+
Requires-Dist: h5netcdf>=1.8.1
|
|
10
|
+
|
|
11
|
+
# writel2
|
|
12
|
+
|
|
13
|
+
Helpers for writing standard-layout L2 NetCDF4 ocean color products from
|
|
14
|
+
Python, and for reading metadata back out of an existing L2 file.
|
|
15
|
+
|
|
16
|
+
- `writel2.L2Writer` creates the standard l2gen group layout
|
|
17
|
+
(`sensor_band_parameters`, `scan_line_attributes`, `geophysical_data`,
|
|
18
|
+
`navigation_data`, `processing_control`/`input_parameters`
|
|
19
|
+
[/`flag_percentages`]), preloads the static global attributes, and writes
|
|
20
|
+
variables into any of those groups via `write_product(name, data,
|
|
21
|
+
group=...)`, whose attributes (`long_name`, `units`, `valid_min`/`valid_max`,
|
|
22
|
+
`scale_factor`/`add_offset`, `_FillValue`, `flag_values`/`flag_meanings`,
|
|
23
|
+
`reference`, `comment`, ...) are resolved from `share/common/product.xml` -
|
|
24
|
+
the same metadata l2gen itself uses, regardless of which group a variable
|
|
25
|
+
belongs to.
|
|
26
|
+
- `writel2.L2Reader` is a read-only helper for pulling metadata back out of
|
|
27
|
+
an existing L2 (or L1/L3) file, mainly so `L2Writer` can seed a derived
|
|
28
|
+
product's global attributes from its source file.
|
|
29
|
+
- `writel2.ProductTable` resolves a product name (e.g. `"chlor_a"`,
|
|
30
|
+
`"Rrs_443"`) against `product.xml` into a `ProductInfo` record.
|
|
31
|
+
- `writel2.GlobalMetadata` loads the static, institution-wide global
|
|
32
|
+
attributes (license, naming authority, creator/publisher info, ...) from
|
|
33
|
+
`$OCDATAROOT/common/global_metadata.json`.
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install $OCSSWROOT/src/scripts/writel2
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This installs as `obpg-writel2`, importable as `writel2`.
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
See [`examples/demo_write_l2.py`](examples/demo_write_l2.py) for a complete,
|
|
46
|
+
runnable example that writes a small file touching every group:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
python $OCSSWROOT/src/scripts/writel2/examples/demo_write_l2.py /tmp/demo_l2.nc
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The short version:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import numpy as np
|
|
56
|
+
from writel2 import L2Writer
|
|
57
|
+
|
|
58
|
+
with L2Writer("out.L2.nc", title="Demo Level-2 Data") as writer:
|
|
59
|
+
# geophysical_data: resolved against product.xml for long_name, units,
|
|
60
|
+
# valid_min/valid_max, scale_factor/add_offset, _FillValue, ...
|
|
61
|
+
flags = np.zeros((4, 3), dtype=np.int32)
|
|
62
|
+
writer.write_product("l2_flags", flags)
|
|
63
|
+
|
|
64
|
+
# processing_control/input_parameters and /flag_percentages
|
|
65
|
+
writer.set_input_parameters({"ifile": "input.L1B.nc", "l2prod": "l2_flags"})
|
|
66
|
+
writer.set_flag_percentages({"ATMFAIL": 0.0, "LAND": 0.49})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Datatype and attributes for any group's variables are resolved from
|
|
70
|
+
`product.xml` and applied automatically by `write_product()`, including
|
|
71
|
+
appropriate scaling - pass `group=` to target `sensor_band_parameters`,
|
|
72
|
+
`scan_line_attributes`, or `navigation_data` instead of the default
|
|
73
|
+
`geophysical_data`. The one exception is `geophysical_data`'s own local
|
|
74
|
+
`wavelength` coordinate variable (used alongside 3D products), which l2gen
|
|
75
|
+
writes directly rather than resolving against product.xml; the calling
|
|
76
|
+
script must set its datatype and attributes manually. See the demo script
|
|
77
|
+
for the full pattern, including how to register dimensions shared across
|
|
78
|
+
groups.
|
|
79
|
+
|
|
80
|
+
## Tests
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install $OCSSWROOT/src/scripts/writel2
|
|
84
|
+
python -m unittest discover -s $OCSSWROOT/src/scripts/writel2/tests
|
|
85
|
+
```
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# writel2
|
|
2
|
+
|
|
3
|
+
Helpers for writing standard-layout L2 NetCDF4 ocean color products from
|
|
4
|
+
Python, and for reading metadata back out of an existing L2 file.
|
|
5
|
+
|
|
6
|
+
- `writel2.L2Writer` creates the standard l2gen group layout
|
|
7
|
+
(`sensor_band_parameters`, `scan_line_attributes`, `geophysical_data`,
|
|
8
|
+
`navigation_data`, `processing_control`/`input_parameters`
|
|
9
|
+
[/`flag_percentages`]), preloads the static global attributes, and writes
|
|
10
|
+
variables into any of those groups via `write_product(name, data,
|
|
11
|
+
group=...)`, whose attributes (`long_name`, `units`, `valid_min`/`valid_max`,
|
|
12
|
+
`scale_factor`/`add_offset`, `_FillValue`, `flag_values`/`flag_meanings`,
|
|
13
|
+
`reference`, `comment`, ...) are resolved from `share/common/product.xml` -
|
|
14
|
+
the same metadata l2gen itself uses, regardless of which group a variable
|
|
15
|
+
belongs to.
|
|
16
|
+
- `writel2.L2Reader` is a read-only helper for pulling metadata back out of
|
|
17
|
+
an existing L2 (or L1/L3) file, mainly so `L2Writer` can seed a derived
|
|
18
|
+
product's global attributes from its source file.
|
|
19
|
+
- `writel2.ProductTable` resolves a product name (e.g. `"chlor_a"`,
|
|
20
|
+
`"Rrs_443"`) against `product.xml` into a `ProductInfo` record.
|
|
21
|
+
- `writel2.GlobalMetadata` loads the static, institution-wide global
|
|
22
|
+
attributes (license, naming authority, creator/publisher info, ...) from
|
|
23
|
+
`$OCDATAROOT/common/global_metadata.json`.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install $OCSSWROOT/src/scripts/writel2
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
This installs as `obpg-writel2`, importable as `writel2`.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
See [`examples/demo_write_l2.py`](examples/demo_write_l2.py) for a complete,
|
|
36
|
+
runnable example that writes a small file touching every group:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
python $OCSSWROOT/src/scripts/writel2/examples/demo_write_l2.py /tmp/demo_l2.nc
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The short version:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import numpy as np
|
|
46
|
+
from writel2 import L2Writer
|
|
47
|
+
|
|
48
|
+
with L2Writer("out.L2.nc", title="Demo Level-2 Data") as writer:
|
|
49
|
+
# geophysical_data: resolved against product.xml for long_name, units,
|
|
50
|
+
# valid_min/valid_max, scale_factor/add_offset, _FillValue, ...
|
|
51
|
+
flags = np.zeros((4, 3), dtype=np.int32)
|
|
52
|
+
writer.write_product("l2_flags", flags)
|
|
53
|
+
|
|
54
|
+
# processing_control/input_parameters and /flag_percentages
|
|
55
|
+
writer.set_input_parameters({"ifile": "input.L1B.nc", "l2prod": "l2_flags"})
|
|
56
|
+
writer.set_flag_percentages({"ATMFAIL": 0.0, "LAND": 0.49})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Datatype and attributes for any group's variables are resolved from
|
|
60
|
+
`product.xml` and applied automatically by `write_product()`, including
|
|
61
|
+
appropriate scaling - pass `group=` to target `sensor_band_parameters`,
|
|
62
|
+
`scan_line_attributes`, or `navigation_data` instead of the default
|
|
63
|
+
`geophysical_data`. The one exception is `geophysical_data`'s own local
|
|
64
|
+
`wavelength` coordinate variable (used alongside 3D products), which l2gen
|
|
65
|
+
writes directly rather than resolving against product.xml; the calling
|
|
66
|
+
script must set its datatype and attributes manually. See the demo script
|
|
67
|
+
for the full pattern, including how to register dimensions shared across
|
|
68
|
+
groups.
|
|
69
|
+
|
|
70
|
+
## Tests
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install $OCSSWROOT/src/scripts/writel2
|
|
74
|
+
python -m unittest discover -s $OCSSWROOT/src/scripts/writel2/tests
|
|
75
|
+
```
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: obpg-writel2
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Helpers for reading L2 metadata and writing derived L2 NetCDF4 products
|
|
5
|
+
Author-email: Gwyn Fireman <Gwyn.F.Fireman@nasa.gov>, Claude Sonnet 5 <noreply@anthropic.com>
|
|
6
|
+
Requires-Python: >=3.12
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: numpy>=1.26.4
|
|
9
|
+
Requires-Dist: h5netcdf>=1.8.1
|
|
10
|
+
|
|
11
|
+
# writel2
|
|
12
|
+
|
|
13
|
+
Helpers for writing standard-layout L2 NetCDF4 ocean color products from
|
|
14
|
+
Python, and for reading metadata back out of an existing L2 file.
|
|
15
|
+
|
|
16
|
+
- `writel2.L2Writer` creates the standard l2gen group layout
|
|
17
|
+
(`sensor_band_parameters`, `scan_line_attributes`, `geophysical_data`,
|
|
18
|
+
`navigation_data`, `processing_control`/`input_parameters`
|
|
19
|
+
[/`flag_percentages`]), preloads the static global attributes, and writes
|
|
20
|
+
variables into any of those groups via `write_product(name, data,
|
|
21
|
+
group=...)`, whose attributes (`long_name`, `units`, `valid_min`/`valid_max`,
|
|
22
|
+
`scale_factor`/`add_offset`, `_FillValue`, `flag_values`/`flag_meanings`,
|
|
23
|
+
`reference`, `comment`, ...) are resolved from `share/common/product.xml` -
|
|
24
|
+
the same metadata l2gen itself uses, regardless of which group a variable
|
|
25
|
+
belongs to.
|
|
26
|
+
- `writel2.L2Reader` is a read-only helper for pulling metadata back out of
|
|
27
|
+
an existing L2 (or L1/L3) file, mainly so `L2Writer` can seed a derived
|
|
28
|
+
product's global attributes from its source file.
|
|
29
|
+
- `writel2.ProductTable` resolves a product name (e.g. `"chlor_a"`,
|
|
30
|
+
`"Rrs_443"`) against `product.xml` into a `ProductInfo` record.
|
|
31
|
+
- `writel2.GlobalMetadata` loads the static, institution-wide global
|
|
32
|
+
attributes (license, naming authority, creator/publisher info, ...) from
|
|
33
|
+
`$OCDATAROOT/common/global_metadata.json`.
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install $OCSSWROOT/src/scripts/writel2
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This installs as `obpg-writel2`, importable as `writel2`.
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
See [`examples/demo_write_l2.py`](examples/demo_write_l2.py) for a complete,
|
|
46
|
+
runnable example that writes a small file touching every group:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
python $OCSSWROOT/src/scripts/writel2/examples/demo_write_l2.py /tmp/demo_l2.nc
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The short version:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import numpy as np
|
|
56
|
+
from writel2 import L2Writer
|
|
57
|
+
|
|
58
|
+
with L2Writer("out.L2.nc", title="Demo Level-2 Data") as writer:
|
|
59
|
+
# geophysical_data: resolved against product.xml for long_name, units,
|
|
60
|
+
# valid_min/valid_max, scale_factor/add_offset, _FillValue, ...
|
|
61
|
+
flags = np.zeros((4, 3), dtype=np.int32)
|
|
62
|
+
writer.write_product("l2_flags", flags)
|
|
63
|
+
|
|
64
|
+
# processing_control/input_parameters and /flag_percentages
|
|
65
|
+
writer.set_input_parameters({"ifile": "input.L1B.nc", "l2prod": "l2_flags"})
|
|
66
|
+
writer.set_flag_percentages({"ATMFAIL": 0.0, "LAND": 0.49})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Datatype and attributes for any group's variables are resolved from
|
|
70
|
+
`product.xml` and applied automatically by `write_product()`, including
|
|
71
|
+
appropriate scaling - pass `group=` to target `sensor_band_parameters`,
|
|
72
|
+
`scan_line_attributes`, or `navigation_data` instead of the default
|
|
73
|
+
`geophysical_data`. The one exception is `geophysical_data`'s own local
|
|
74
|
+
`wavelength` coordinate variable (used alongside 3D products), which l2gen
|
|
75
|
+
writes directly rather than resolving against product.xml; the calling
|
|
76
|
+
script must set its datatype and attributes manually. See the demo script
|
|
77
|
+
for the full pattern, including how to register dimensions shared across
|
|
78
|
+
groups.
|
|
79
|
+
|
|
80
|
+
## Tests
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install $OCSSWROOT/src/scripts/writel2
|
|
84
|
+
python -m unittest discover -s $OCSSWROOT/src/scripts/writel2/tests
|
|
85
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
obpg_writel2.egg-info/PKG-INFO
|
|
4
|
+
obpg_writel2.egg-info/SOURCES.txt
|
|
5
|
+
obpg_writel2.egg-info/dependency_links.txt
|
|
6
|
+
obpg_writel2.egg-info/requires.txt
|
|
7
|
+
obpg_writel2.egg-info/top_level.txt
|
|
8
|
+
src/__init__.py
|
|
9
|
+
src/global_metadata.py
|
|
10
|
+
src/product_info.py
|
|
11
|
+
src/reader.py
|
|
12
|
+
src/writer.py
|
|
13
|
+
tests/test_product_info.py
|
|
14
|
+
tests/test_reader.py
|
|
15
|
+
tests/test_writer.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
writel2
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "obpg-writel2"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = '''Helpers for reading L2 metadata and writing derived L2 NetCDF4 products'''
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
authors = [
|
|
8
|
+
{name = "Gwyn Fireman", email = "Gwyn.F.Fireman@nasa.gov"},
|
|
9
|
+
{name = "Claude Sonnet 5", email = "noreply@anthropic.com"},
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
dependencies = [
|
|
13
|
+
'numpy>=1.26.4',
|
|
14
|
+
'h5netcdf>=1.8.1',
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[build-system]
|
|
18
|
+
requires = ["setuptools>=45", "wheel"]
|
|
19
|
+
build-backend = "setuptools.build_meta"
|
|
20
|
+
|
|
21
|
+
[tool.setuptools]
|
|
22
|
+
packages = ["writel2"]
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.package-dir]
|
|
25
|
+
"writel2" = "src"
|
|
26
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .global_metadata import GlobalMetadata
|
|
2
|
+
from .product_info import ProductInfo, ProductNotFoundError, ProductTable
|
|
3
|
+
from .reader import L2Reader
|
|
4
|
+
from .writer import L2Writer
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"GlobalMetadata",
|
|
8
|
+
"ProductInfo",
|
|
9
|
+
"ProductNotFoundError",
|
|
10
|
+
"ProductTable",
|
|
11
|
+
"L2Reader",
|
|
12
|
+
"L2Writer",
|
|
13
|
+
]
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Loads the static, institution-wide NetCDF4 global attributes shared by every
|
|
3
|
+
L2 output file (license, naming_authority, creator_*/publisher_*, ...) from
|
|
4
|
+
$OCDATAROOT/common/global_metadata.json, mirroring how ProductTable resolves
|
|
5
|
+
share/common/product.xml (product_info.py). In l2gen these same values are
|
|
6
|
+
hardcoded #define macros in oel_hdf4/libl1/l1.h, written unconditionally by
|
|
7
|
+
the NetCDF4 output path in src/l2gen/l2_generic.c.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
from collections.abc import Mapping
|
|
15
|
+
from typing import Optional
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class GlobalMetadata(Mapping):
|
|
19
|
+
"""Read-only, lazily-loaded view of global_metadata.json's key/value pairs."""
|
|
20
|
+
|
|
21
|
+
def __init__(self, path: Optional[str] = None):
|
|
22
|
+
self._path = path
|
|
23
|
+
self._attrs: Optional[dict] = None
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def path(self) -> str:
|
|
27
|
+
if self._path:
|
|
28
|
+
return self._path
|
|
29
|
+
data_root = os.environ.get("OCDATAROOT")
|
|
30
|
+
if not data_root:
|
|
31
|
+
raise RuntimeError("OCDATAROOT environment variable is not defined.")
|
|
32
|
+
return os.path.join(data_root, "common", "global_metadata.json")
|
|
33
|
+
|
|
34
|
+
def _ensure_loaded(self) -> dict:
|
|
35
|
+
if self._attrs is None:
|
|
36
|
+
with open(self.path) as f:
|
|
37
|
+
data: dict = json.load(f)
|
|
38
|
+
self._attrs = data
|
|
39
|
+
return self._attrs
|
|
40
|
+
|
|
41
|
+
def __getitem__(self, name):
|
|
42
|
+
return self._ensure_loaded()[name]
|
|
43
|
+
|
|
44
|
+
def __iter__(self):
|
|
45
|
+
return iter(self._ensure_loaded())
|
|
46
|
+
|
|
47
|
+
def __len__(self):
|
|
48
|
+
return len(self._ensure_loaded())
|