h5yaml 0.0.5__tar.gz → 0.1.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.
- h5yaml-0.1.0/.pre-commit-config.yaml +11 -0
- {h5yaml-0.0.5 → h5yaml-0.1.0}/PKG-INFO +6 -5
- {h5yaml-0.0.5 → h5yaml-0.1.0}/README.md +2 -1
- {h5yaml-0.0.5 → h5yaml-0.1.0}/pyproject.toml +3 -3
- {h5yaml-0.0.5 → h5yaml-0.1.0}/src/h5yaml/Data/h5_testing.yaml +4 -1
- {h5yaml-0.0.5 → h5yaml-0.1.0}/src/h5yaml/Data/nc_testing.yaml +4 -1
- {h5yaml-0.0.5 → h5yaml-0.1.0}/src/h5yaml/yaml_h5.py +46 -66
- {h5yaml-0.0.5 → h5yaml-0.1.0}/.gitignore +0 -0
- {h5yaml-0.0.5 → h5yaml-0.1.0}/LICENSE +0 -0
- {h5yaml-0.0.5 → h5yaml-0.1.0}/MANIFEST.in +0 -0
- {h5yaml-0.0.5 → h5yaml-0.1.0}/src/h5yaml/conf_from_yaml.py +0 -0
- {h5yaml-0.0.5 → h5yaml-0.1.0}/src/h5yaml/lib/chunksizes.py +0 -0
- {h5yaml-0.0.5 → h5yaml-0.1.0}/src/h5yaml/yaml_nc.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: h5yaml
|
|
3
|
-
Version: 0.0
|
|
3
|
+
Version: 0.1.0
|
|
4
4
|
Summary: Use YAML configuration file to generate HDF5/netCDF4 formated files.
|
|
5
5
|
Project-URL: Homepage, https://github.com/rmvanhees/h5_yaml
|
|
6
6
|
Project-URL: Source, https://github.com/rmvanhees/h5_yaml
|
|
@@ -9,18 +9,18 @@ Author-email: Richard van Hees <r.m.van.hees@sron.nl>
|
|
|
9
9
|
License-Expression: BSD-3-Clause
|
|
10
10
|
License-File: LICENSE
|
|
11
11
|
Keywords: HDF5,YAML,netCDF4
|
|
12
|
-
Classifier: Development Status ::
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
14
14
|
Classifier: Intended Audience :: Science/Research
|
|
15
15
|
Classifier: Operating System :: OS Independent
|
|
16
16
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
20
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
21
20
|
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
22
|
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
|
|
23
|
-
Requires-Python: >=3.
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
24
|
Requires-Dist: h5py>=3.13
|
|
25
25
|
Requires-Dist: netcdf4>=1.7
|
|
26
26
|
Requires-Dist: numpy>=2.2
|
|
@@ -133,10 +133,11 @@ The YAML file should be structured as follows:
|
|
|
133
133
|
Alternatively, provide a list with names of YAML files which contain the definitions
|
|
134
134
|
of the compounds.
|
|
135
135
|
|
|
136
|
+
```
|
|
136
137
|
compounds:
|
|
137
138
|
- h5_nomhk_tm.yaml
|
|
138
139
|
- h5_science_hk.yaml
|
|
139
|
-
|
|
140
|
+
```
|
|
140
141
|
* The 'variables' are defined by their data-type ('_dtype') and dimensions ('_dims'),
|
|
141
142
|
and optionally chunk sizes ('_chunks'), compression ('_compression'), variable length
|
|
142
143
|
('_vlen'). In addition, each variable can have as many attributes as you like,
|
|
@@ -104,10 +104,11 @@ The YAML file should be structured as follows:
|
|
|
104
104
|
Alternatively, provide a list with names of YAML files which contain the definitions
|
|
105
105
|
of the compounds.
|
|
106
106
|
|
|
107
|
+
```
|
|
107
108
|
compounds:
|
|
108
109
|
- h5_nomhk_tm.yaml
|
|
109
110
|
- h5_science_hk.yaml
|
|
110
|
-
|
|
111
|
+
```
|
|
111
112
|
* The 'variables' are defined by their data-type ('_dtype') and dimensions ('_dims'),
|
|
112
113
|
and optionally chunk sizes ('_chunks'), compression ('_compression'), variable length
|
|
113
114
|
('_vlen'). In addition, each variable can have as many attributes as you like,
|
|
@@ -14,18 +14,18 @@ license = "BSD-3-Clause"
|
|
|
14
14
|
authors = [
|
|
15
15
|
{name = "Richard van Hees", email = "r.m.van.hees@sron.nl"}
|
|
16
16
|
]
|
|
17
|
-
requires-python = ">=3.
|
|
17
|
+
requires-python = ">=3.10"
|
|
18
18
|
classifiers = [
|
|
19
|
-
"Development Status ::
|
|
19
|
+
"Development Status :: 5 - Production/Stable",
|
|
20
20
|
"Intended Audience :: Developers",
|
|
21
21
|
"Intended Audience :: Science/Research",
|
|
22
22
|
"Operating System :: OS Independent",
|
|
23
23
|
"Programming Language :: Python :: 3 :: Only",
|
|
24
|
-
"Programming Language :: Python :: 3.9",
|
|
25
24
|
"Programming Language :: Python :: 3.10",
|
|
26
25
|
"Programming Language :: Python :: 3.11",
|
|
27
26
|
"Programming Language :: Python :: 3.12",
|
|
28
27
|
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Programming Language :: Python :: 3.14",
|
|
29
29
|
"Topic :: Scientific/Engineering :: Atmospheric Science",
|
|
30
30
|
]
|
|
31
31
|
keywords = [
|
|
@@ -45,7 +45,10 @@ dimensions:
|
|
|
45
45
|
# - compound elements must have a data-type, and can have a unit and long_name
|
|
46
46
|
compounds:
|
|
47
47
|
stats_dtype:
|
|
48
|
-
time:
|
|
48
|
+
time:
|
|
49
|
+
- u8
|
|
50
|
+
- seconds since 1970-01-01T00:00:00
|
|
51
|
+
- timestamp
|
|
49
52
|
index: [u2, '1', index]
|
|
50
53
|
tbl_id: [u1, '1', binning id]
|
|
51
54
|
saa: [u1, '1', saa-flag]
|
|
@@ -45,7 +45,10 @@ dimensions:
|
|
|
45
45
|
# - compound elements must have a data-type, and can have a unit and long_name
|
|
46
46
|
compounds:
|
|
47
47
|
stats_dtype:
|
|
48
|
-
time:
|
|
48
|
+
time:
|
|
49
|
+
- u8
|
|
50
|
+
- seconds since 1970-01-01T00:00:00
|
|
51
|
+
- timestamp
|
|
49
52
|
index: [u2, '1', index]
|
|
50
53
|
tbl_id: [u1, '1', binning id]
|
|
51
54
|
saa: [u1, '1', saa-flag]
|
|
@@ -23,7 +23,43 @@ import numpy as np
|
|
|
23
23
|
from h5yaml.conf_from_yaml import conf_from_yaml
|
|
24
24
|
from h5yaml.lib.chunksizes import guess_chunks
|
|
25
25
|
|
|
26
|
+
|
|
26
27
|
# - helper function ------------------------------------
|
|
28
|
+
def adjust_attr(attr_key: str, attr_val: np.ndarray, attr_dtype: str) -> np.ndarray:
|
|
29
|
+
"""..."""
|
|
30
|
+
if attr_key in ("valid_min", "valid_max", "valid_range"):
|
|
31
|
+
match attr_dtype:
|
|
32
|
+
case "i1":
|
|
33
|
+
res = np.int8(attr_val)
|
|
34
|
+
case "i2":
|
|
35
|
+
res = np.int16(attr_val)
|
|
36
|
+
case "i4":
|
|
37
|
+
res = np.int32(attr_val)
|
|
38
|
+
case "i8":
|
|
39
|
+
res = np.int64(attr_val)
|
|
40
|
+
case "u1":
|
|
41
|
+
res = np.uint8(attr_val)
|
|
42
|
+
case "u2":
|
|
43
|
+
res = np.uint16(attr_val)
|
|
44
|
+
case "u4":
|
|
45
|
+
res = np.uint32(attr_val)
|
|
46
|
+
case "u8":
|
|
47
|
+
res = np.uint64(attr_val)
|
|
48
|
+
case "f2":
|
|
49
|
+
res = np.float16(attr_val)
|
|
50
|
+
case "f4":
|
|
51
|
+
res = np.float32(attr_val)
|
|
52
|
+
case "f8":
|
|
53
|
+
res = np.float64(attr_val)
|
|
54
|
+
case _:
|
|
55
|
+
res = attr_val
|
|
56
|
+
|
|
57
|
+
return res
|
|
58
|
+
|
|
59
|
+
if attr_key == "flag_values":
|
|
60
|
+
return np.array(attr_val, dtype="u1")
|
|
61
|
+
|
|
62
|
+
return attr_val
|
|
27
63
|
|
|
28
64
|
|
|
29
65
|
# - class definition -----------------------------------
|
|
@@ -82,6 +118,8 @@ class H5Yaml:
|
|
|
82
118
|
)
|
|
83
119
|
if "_values" in val:
|
|
84
120
|
dset[:] = val["_values"]
|
|
121
|
+
elif "_range" in val:
|
|
122
|
+
dset[:] = np.arange(*val["_range"], dtype=val["_dtype"])
|
|
85
123
|
|
|
86
124
|
dset.make_scale(
|
|
87
125
|
Path(key).name
|
|
@@ -89,36 +127,8 @@ class H5Yaml:
|
|
|
89
127
|
else "This is a netCDF dimension but not a netCDF variable."
|
|
90
128
|
)
|
|
91
129
|
for attr, attr_val in val.items():
|
|
92
|
-
if attr.startswith("_"):
|
|
93
|
-
|
|
94
|
-
if attr in ("valid_min", "valid_max"):
|
|
95
|
-
match val["_dtype"]:
|
|
96
|
-
case "i1":
|
|
97
|
-
dset.attrs[attr] = np.int8(attr_val)
|
|
98
|
-
case "i2":
|
|
99
|
-
dset.attrs[attr] = np.int16(attr_val)
|
|
100
|
-
case "i4":
|
|
101
|
-
dset.attrs[attr] = np.int32(attr_val)
|
|
102
|
-
case "i8":
|
|
103
|
-
dset.attrs[attr] = np.int64(attr_val)
|
|
104
|
-
case "u1":
|
|
105
|
-
dset.attrs[attr] = np.uint8(attr_val)
|
|
106
|
-
case "u2":
|
|
107
|
-
dset.attrs[attr] = np.uint16(attr_val)
|
|
108
|
-
case "u4":
|
|
109
|
-
dset.attrs[attr] = np.uint32(attr_val)
|
|
110
|
-
case "u8":
|
|
111
|
-
dset.attrs[attr] = np.uint64(attr_val)
|
|
112
|
-
case "f2":
|
|
113
|
-
dset.attrs[attr] = np.float16(attr_val)
|
|
114
|
-
case "f4":
|
|
115
|
-
dset.attrs[attr] = np.float32(attr_val)
|
|
116
|
-
case "f8":
|
|
117
|
-
dset.attrs[attr] = np.float64(attr_val)
|
|
118
|
-
case _:
|
|
119
|
-
dset.attrs[attr] = attr_val
|
|
120
|
-
else:
|
|
121
|
-
dset.attrs[attr] = attr_val
|
|
130
|
+
if not attr.startswith("_"):
|
|
131
|
+
dset.attrs[attr] = adjust_attr(attr, attr_val, val["_dtype"])
|
|
122
132
|
|
|
123
133
|
def __compounds(self: H5Yaml, fid: h5py.File) -> dict[str, str | int | float]:
|
|
124
134
|
"""Add compound datatypes to HDF5 product."""
|
|
@@ -192,9 +202,8 @@ class H5Yaml:
|
|
|
192
202
|
fillvalue=fillvalue,
|
|
193
203
|
)
|
|
194
204
|
for attr, attr_val in val.items():
|
|
195
|
-
if attr.startswith("_"):
|
|
196
|
-
|
|
197
|
-
dset.attrs[attr] = attr_val
|
|
205
|
+
if not attr.startswith("_"):
|
|
206
|
+
dset.attrs[attr] = adjust_attr(attr, attr_val, val["_dtype"])
|
|
198
207
|
continue
|
|
199
208
|
|
|
200
209
|
n_udim = 0
|
|
@@ -263,38 +272,8 @@ class H5Yaml:
|
|
|
263
272
|
dset.dims[ii].attach_scale(fid[coord])
|
|
264
273
|
|
|
265
274
|
for attr, attr_val in val.items():
|
|
266
|
-
if attr.startswith("_"):
|
|
267
|
-
|
|
268
|
-
if attr in ("valid_min", "valid_max"):
|
|
269
|
-
match val["_dtype"]:
|
|
270
|
-
case "i1":
|
|
271
|
-
dset.attrs[attr] = np.int8(attr_val)
|
|
272
|
-
case "i2":
|
|
273
|
-
dset.attrs[attr] = np.int16(attr_val)
|
|
274
|
-
case "i4":
|
|
275
|
-
dset.attrs[attr] = np.int32(attr_val)
|
|
276
|
-
case "i8":
|
|
277
|
-
dset.attrs[attr] = np.int64(attr_val)
|
|
278
|
-
case "u1":
|
|
279
|
-
dset.attrs[attr] = np.uint8(attr_val)
|
|
280
|
-
case "u2":
|
|
281
|
-
dset.attrs[attr] = np.uint16(attr_val)
|
|
282
|
-
case "u4":
|
|
283
|
-
dset.attrs[attr] = np.uint32(attr_val)
|
|
284
|
-
case "u8":
|
|
285
|
-
dset.attrs[attr] = np.uint64(attr_val)
|
|
286
|
-
case "f2":
|
|
287
|
-
dset.attrs[attr] = np.float16(attr_val)
|
|
288
|
-
case "f4":
|
|
289
|
-
dset.attrs[attr] = np.float32(attr_val)
|
|
290
|
-
case "f8":
|
|
291
|
-
dset.attrs[attr] = np.float64(attr_val)
|
|
292
|
-
case _:
|
|
293
|
-
dset.attrs[attr] = attr_val
|
|
294
|
-
elif attr == "flag_values":
|
|
295
|
-
dset.attrs[attr] = np.array(attr_val, dtype="u1")
|
|
296
|
-
else:
|
|
297
|
-
dset.attrs[attr] = attr_val
|
|
275
|
+
if not attr.startswith("_"):
|
|
276
|
+
dset.attrs[attr] = adjust_attr(attr, attr_val, val["_dtype"])
|
|
298
277
|
|
|
299
278
|
if compounds is not None and val["_dtype"] in compounds:
|
|
300
279
|
if compounds[val["_dtype"]]["units"]:
|
|
@@ -318,7 +297,8 @@ class H5Yaml:
|
|
|
318
297
|
"""
|
|
319
298
|
try:
|
|
320
299
|
with h5py.File(l1a_name, "w") as fid:
|
|
321
|
-
self.
|
|
300
|
+
if "groups" in self.h5_def:
|
|
301
|
+
self.__groups(fid)
|
|
322
302
|
self.__dimensions(fid)
|
|
323
303
|
self.__variables(fid, self.__compounds(fid))
|
|
324
304
|
except PermissionError as exc:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|