zarr-cm 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl
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.
- zarr_cm/__init__.py +231 -0
- zarr_cm/_version.py +2 -2
- {zarr_cm-0.1.0.dist-info → zarr_cm-0.2.0.dist-info}/METADATA +1 -1
- {zarr_cm-0.1.0.dist-info → zarr_cm-0.2.0.dist-info}/RECORD +6 -6
- {zarr_cm-0.1.0.dist-info → zarr_cm-0.2.0.dist-info}/WHEEL +0 -0
- {zarr_cm-0.1.0.dist-info → zarr_cm-0.2.0.dist-info}/licenses/LICENSE +0 -0
zarr_cm/__init__.py
CHANGED
|
@@ -6,6 +6,15 @@ zarr-cm: Python implementation of Zarr Conventions Metadata
|
|
|
6
6
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
|
+
import typing
|
|
10
|
+
from typing import Any, Final, Literal, NotRequired, TypedDict
|
|
11
|
+
|
|
12
|
+
if typing.TYPE_CHECKING:
|
|
13
|
+
import types
|
|
14
|
+
from collections.abc import Iterable
|
|
15
|
+
|
|
16
|
+
from . import geo_proj, multiscales, spatial, uom
|
|
17
|
+
from . import license as license_
|
|
9
18
|
from ._core import (
|
|
10
19
|
ConventionAttrs,
|
|
11
20
|
ConventionMetadataObject,
|
|
@@ -23,15 +32,231 @@ from .multiscales import (
|
|
|
23
32
|
from .spatial import SpatialAttrs, SpatialConventionAttrs
|
|
24
33
|
from .uom import UCUM, UomAttrs, UomConventionAttrs
|
|
25
34
|
|
|
35
|
+
ConventionName = Literal["geo-proj", "spatial", "multiscales", "license", "uom"]
|
|
36
|
+
|
|
37
|
+
_REGISTRY: Final[dict[ConventionName, types.ModuleType]] = {
|
|
38
|
+
"geo-proj": geo_proj,
|
|
39
|
+
"spatial": spatial,
|
|
40
|
+
"multiscales": multiscales,
|
|
41
|
+
"license": license_,
|
|
42
|
+
"uom": uom,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
CONVENTION_NAMES: Final = frozenset(_REGISTRY)
|
|
46
|
+
|
|
47
|
+
ALL_CONVENTION_KEYS: Final = frozenset(
|
|
48
|
+
geo_proj.CONVENTION_KEYS
|
|
49
|
+
| spatial.CONVENTION_KEYS
|
|
50
|
+
| multiscales.CONVENTION_KEYS
|
|
51
|
+
| license_.CONVENTION_KEYS
|
|
52
|
+
| uom.CONVENTION_KEYS
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
MultiConventionAttrs = TypedDict(
|
|
56
|
+
"MultiConventionAttrs",
|
|
57
|
+
{
|
|
58
|
+
"zarr_conventions": NotRequired[list[ConventionMetadataObject]],
|
|
59
|
+
# geo-proj
|
|
60
|
+
"proj:code": NotRequired[str],
|
|
61
|
+
"proj:wkt2": NotRequired[str],
|
|
62
|
+
"proj:projjson": NotRequired[dict[str, Any]],
|
|
63
|
+
# spatial
|
|
64
|
+
"spatial:dimensions": NotRequired[list[str]],
|
|
65
|
+
"spatial:bbox": NotRequired[list[float]],
|
|
66
|
+
"spatial:transform_type": NotRequired[str],
|
|
67
|
+
"spatial:transform": NotRequired[list[float]],
|
|
68
|
+
"spatial:shape": NotRequired[list[int]],
|
|
69
|
+
"spatial:registration": NotRequired[str],
|
|
70
|
+
# multiscales
|
|
71
|
+
"multiscales": NotRequired[MultiscalesAttrs],
|
|
72
|
+
# license
|
|
73
|
+
"license": NotRequired[LicenseAttrs],
|
|
74
|
+
# uom
|
|
75
|
+
"uom": NotRequired[UomAttrs],
|
|
76
|
+
},
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _get_module(name: ConventionName) -> types.ModuleType:
|
|
81
|
+
"""Look up convention module by display name, raise ValueError if unknown."""
|
|
82
|
+
try:
|
|
83
|
+
return _REGISTRY[name]
|
|
84
|
+
except KeyError:
|
|
85
|
+
msg = f"Unknown convention {name!r}. Valid names: {sorted(CONVENTION_NAMES)}"
|
|
86
|
+
raise ValueError(msg) from None
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _detect_conventions(attrs: dict[str, Any]) -> frozenset[ConventionName]:
|
|
90
|
+
"""Identify which conventions are present by matching UUIDs in zarr_conventions."""
|
|
91
|
+
uuids = {cmo.get("uuid") for cmo in attrs.get("zarr_conventions", [])}
|
|
92
|
+
return frozenset(name for name, mod in _REGISTRY.items() if mod.UUID in uuids)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def create_many(
|
|
96
|
+
conventions: dict[ConventionName, dict[str, Any]],
|
|
97
|
+
) -> dict[str, Any]:
|
|
98
|
+
"""Create and insert multiple conventions into a single attributes dict.
|
|
99
|
+
|
|
100
|
+
Parameters
|
|
101
|
+
----------
|
|
102
|
+
conventions
|
|
103
|
+
Mapping from convention display name (e.g. ``"geo-proj"``) to
|
|
104
|
+
already-formed convention data (the ``AttrsT`` value).
|
|
105
|
+
|
|
106
|
+
Returns
|
|
107
|
+
-------
|
|
108
|
+
dict[str, Any]
|
|
109
|
+
A new attributes dict containing all convention data and a
|
|
110
|
+
combined ``zarr_conventions`` array.
|
|
111
|
+
"""
|
|
112
|
+
result: dict[str, Any] = {}
|
|
113
|
+
for name, data in conventions.items():
|
|
114
|
+
mod = _get_module(name)
|
|
115
|
+
mod.validate(data)
|
|
116
|
+
result = mod.insert(result, data, overwrite=True)
|
|
117
|
+
return result
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def validate_many(
|
|
121
|
+
attrs: dict[str, Any],
|
|
122
|
+
conventions: Iterable[ConventionName],
|
|
123
|
+
) -> dict[str, Any]:
|
|
124
|
+
"""Validate multiple conventions within an attributes dict.
|
|
125
|
+
|
|
126
|
+
Parameters
|
|
127
|
+
----------
|
|
128
|
+
attrs
|
|
129
|
+
The attributes dict to validate.
|
|
130
|
+
conventions
|
|
131
|
+
Convention names to validate.
|
|
132
|
+
|
|
133
|
+
Returns
|
|
134
|
+
-------
|
|
135
|
+
dict[str, Any]
|
|
136
|
+
The input *attrs* (pass-through on success).
|
|
137
|
+
"""
|
|
138
|
+
for name in conventions:
|
|
139
|
+
mod = _get_module(name)
|
|
140
|
+
_, extracted = mod.extract(attrs)
|
|
141
|
+
mod.validate(dict(extracted))
|
|
142
|
+
return attrs
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def insert_many(
|
|
146
|
+
attrs: dict[str, Any],
|
|
147
|
+
conventions: dict[ConventionName, dict[str, Any]],
|
|
148
|
+
*,
|
|
149
|
+
overwrite: bool = False,
|
|
150
|
+
) -> dict[str, Any]:
|
|
151
|
+
"""Insert multiple conventions into an attributes dict.
|
|
152
|
+
|
|
153
|
+
Parameters
|
|
154
|
+
----------
|
|
155
|
+
attrs
|
|
156
|
+
The existing attributes dict.
|
|
157
|
+
conventions
|
|
158
|
+
Mapping from convention display name to already-formed convention data.
|
|
159
|
+
overwrite
|
|
160
|
+
If False (default), raise ``ValueError`` when *attrs* already
|
|
161
|
+
contains keys present in a convention's data.
|
|
162
|
+
|
|
163
|
+
Returns
|
|
164
|
+
-------
|
|
165
|
+
dict[str, Any]
|
|
166
|
+
A new attributes dict with all convention data merged in.
|
|
167
|
+
"""
|
|
168
|
+
result = attrs
|
|
169
|
+
for name, data in conventions.items():
|
|
170
|
+
mod = _get_module(name)
|
|
171
|
+
mod.validate(data)
|
|
172
|
+
result = mod.insert(result, data, overwrite=overwrite)
|
|
173
|
+
return result
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def extract_many(
|
|
177
|
+
attrs: dict[str, Any],
|
|
178
|
+
conventions: Iterable[ConventionName],
|
|
179
|
+
) -> tuple[dict[str, Any], dict[ConventionName, dict[str, Any]]]:
|
|
180
|
+
"""Extract multiple conventions from an attributes dict.
|
|
181
|
+
|
|
182
|
+
Parameters
|
|
183
|
+
----------
|
|
184
|
+
attrs
|
|
185
|
+
The attributes dict to extract from.
|
|
186
|
+
conventions
|
|
187
|
+
Convention names to extract.
|
|
188
|
+
|
|
189
|
+
Returns
|
|
190
|
+
-------
|
|
191
|
+
tuple[dict[str, Any], dict[str, dict[str, Any]]]
|
|
192
|
+
``(remaining_attrs, extracted)`` where *extracted* maps
|
|
193
|
+
convention names to their convention data dicts.
|
|
194
|
+
"""
|
|
195
|
+
remaining = attrs
|
|
196
|
+
extracted: dict[ConventionName, dict[str, Any]] = {}
|
|
197
|
+
for name in conventions:
|
|
198
|
+
mod = _get_module(name)
|
|
199
|
+
remaining, data = mod.extract(remaining)
|
|
200
|
+
extracted[name] = dict(data)
|
|
201
|
+
return remaining, extracted
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def validate_all(
|
|
205
|
+
attrs: dict[str, Any],
|
|
206
|
+
) -> dict[str, Any]:
|
|
207
|
+
"""Validate all detected conventions within an attributes dict.
|
|
208
|
+
|
|
209
|
+
Detects which conventions are present by matching UUIDs in
|
|
210
|
+
``zarr_conventions``, then validates each one.
|
|
211
|
+
|
|
212
|
+
Parameters
|
|
213
|
+
----------
|
|
214
|
+
attrs
|
|
215
|
+
The attributes dict to validate.
|
|
216
|
+
|
|
217
|
+
Returns
|
|
218
|
+
-------
|
|
219
|
+
dict[str, Any]
|
|
220
|
+
The input *attrs* (pass-through on success).
|
|
221
|
+
"""
|
|
222
|
+
return validate_many(attrs, _detect_conventions(attrs))
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def extract_all(
|
|
226
|
+
attrs: dict[str, Any],
|
|
227
|
+
) -> tuple[dict[str, Any], dict[ConventionName, dict[str, Any]]]:
|
|
228
|
+
"""Extract all detected conventions from an attributes dict.
|
|
229
|
+
|
|
230
|
+
Detects which conventions are present by matching UUIDs in
|
|
231
|
+
``zarr_conventions``, then extracts each one.
|
|
232
|
+
|
|
233
|
+
Parameters
|
|
234
|
+
----------
|
|
235
|
+
attrs
|
|
236
|
+
The attributes dict to extract from.
|
|
237
|
+
|
|
238
|
+
Returns
|
|
239
|
+
-------
|
|
240
|
+
tuple[dict[str, Any], dict[str, dict[str, Any]]]
|
|
241
|
+
``(remaining_attrs, extracted)`` where *extracted* maps
|
|
242
|
+
convention names to their convention data dicts.
|
|
243
|
+
"""
|
|
244
|
+
return extract_many(attrs, _detect_conventions(attrs))
|
|
245
|
+
|
|
246
|
+
|
|
26
247
|
__all__ = [
|
|
248
|
+
"ALL_CONVENTION_KEYS",
|
|
249
|
+
"CONVENTION_NAMES",
|
|
27
250
|
"UCUM",
|
|
28
251
|
"ConventionAttrs",
|
|
29
252
|
"ConventionMetadataObject",
|
|
253
|
+
"ConventionName",
|
|
30
254
|
"GeoProjAttrs",
|
|
31
255
|
"GeoProjConventionAttrs",
|
|
32
256
|
"LayoutObject",
|
|
33
257
|
"LicenseAttrs",
|
|
34
258
|
"LicenseConventionAttrs",
|
|
259
|
+
"MultiConventionAttrs",
|
|
35
260
|
"MultiscalesAttrs",
|
|
36
261
|
"MultiscalesConventionAttrs",
|
|
37
262
|
"SpatialAttrs",
|
|
@@ -40,5 +265,11 @@ __all__ = [
|
|
|
40
265
|
"UomAttrs",
|
|
41
266
|
"UomConventionAttrs",
|
|
42
267
|
"__version__",
|
|
268
|
+
"create_many",
|
|
269
|
+
"extract_all",
|
|
270
|
+
"extract_many",
|
|
271
|
+
"insert_many",
|
|
272
|
+
"validate_all",
|
|
43
273
|
"validate_convention_metadata_object",
|
|
274
|
+
"validate_many",
|
|
44
275
|
]
|
zarr_cm/_version.py
CHANGED
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '0.
|
|
32
|
-
__version_tuple__ = version_tuple = (0,
|
|
31
|
+
__version__ = version = '0.2.0'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 2, 0)
|
|
33
33
|
|
|
34
34
|
__commit_id__ = commit_id = None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: zarr-cm
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Python implementation of Zarr Conventions Metadata
|
|
5
5
|
Project-URL: Homepage, https://github.com/zarr-conventions/zarr-cm
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/zarr-conventions/zarr-cm/issues
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
zarr_cm/__init__.py,sha256=
|
|
1
|
+
zarr_cm/__init__.py,sha256=Hw5KH_lASVSgY_eIeOdpGXbr_aYEogbIbNuAyzErxuY,7662
|
|
2
2
|
zarr_cm/_core.py,sha256=FBf_dSy6e_JhO2NLLZAsjd9lo0doNj-sP6SaD9ccXSw,3318
|
|
3
|
-
zarr_cm/_version.py,sha256=
|
|
3
|
+
zarr_cm/_version.py,sha256=Dg8AmJomLVpjKL6prJylOONZAPRtB86LOce7dorQS_A,704
|
|
4
4
|
zarr_cm/_version.pyi,sha256=o7uNL6MhuJoiqpEnriU7rBT6TmkJZA-i2qMoNz9YcgQ,82
|
|
5
5
|
zarr_cm/geo_proj.py,sha256=hThP9JXBS_UJBv5LVVlGVlqPa-FJIHxFGbQqkNhsgz0,2877
|
|
6
6
|
zarr_cm/license.py,sha256=K1VmX_iGBiXc7jBMhor2Z3MRfv3u_OPSUu7HzCYfB1M,3082
|
|
@@ -8,7 +8,7 @@ zarr_cm/multiscales.py,sha256=Fb0npvFyMB72FADfyXCxR2N8nZ0HoQWlZdyffNGUVsk,3561
|
|
|
8
8
|
zarr_cm/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
zarr_cm/spatial.py,sha256=7VT8KuuLOhvx9pM4FadpFUSxB-F-4Kw92faYnfJri1Y,4171
|
|
10
10
|
zarr_cm/uom.py,sha256=Hgiq2nk-h0B3KkFSkR_B-mjbaZrGw6OPo78ZA2qFW68,2610
|
|
11
|
-
zarr_cm-0.
|
|
12
|
-
zarr_cm-0.
|
|
13
|
-
zarr_cm-0.
|
|
14
|
-
zarr_cm-0.
|
|
11
|
+
zarr_cm-0.2.0.dist-info/METADATA,sha256=vZU_Ui1jfU3BxruNriA6efUqdAs5sG6ss7o_l8AfT1g,5340
|
|
12
|
+
zarr_cm-0.2.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
13
|
+
zarr_cm-0.2.0.dist-info/licenses/LICENSE,sha256=ZE1QpSxHhv5y8vLtkWCxZA9-et8IrqusTlNS9ARqr4s,1523
|
|
14
|
+
zarr_cm-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|