envlib 0.1.3__tar.gz → 0.1.4__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.
- {envlib-0.1.3 → envlib-0.1.4}/PKG-INFO +2 -2
- envlib-0.1.4/envlib/__init__.py +17 -0
- {envlib-0.1.3 → envlib-0.1.4}/envlib/catalogue.py +8 -2
- {envlib-0.1.3 → envlib-0.1.4}/envlib/metadata.py +40 -8
- envlib-0.1.3/envlib/__init__.py +0 -9
- {envlib-0.1.3 → envlib-0.1.4}/.gitignore +0 -0
- {envlib-0.1.3 → envlib-0.1.4}/LICENSE +0 -0
- {envlib-0.1.3 → envlib-0.1.4}/README.md +0 -0
- {envlib-0.1.3 → envlib-0.1.4}/envlib/vocabularies/__init__.py +0 -0
- {envlib-0.1.3 → envlib-0.1.4}/envlib/vocabularies/aggregation_statistic.json +0 -0
- {envlib-0.1.3 → envlib-0.1.4}/envlib/vocabularies/feature.json +0 -0
- {envlib-0.1.3 → envlib-0.1.4}/envlib/vocabularies/frequency_interval.json +0 -0
- {envlib-0.1.3 → envlib-0.1.4}/envlib/vocabularies/license.json +0 -0
- {envlib-0.1.3 → envlib-0.1.4}/envlib/vocabularies/method.json +0 -0
- {envlib-0.1.3 → envlib-0.1.4}/envlib/vocabularies/processing_level.json +0 -0
- {envlib-0.1.3 → envlib-0.1.4}/envlib/vocabularies/standard_name.json +0 -0
- {envlib-0.1.3 → envlib-0.1.4}/envlib/vocabularies/variable.json +0 -0
- {envlib-0.1.3 → envlib-0.1.4}/pyproject.toml +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""envlib: a distributed database and catalogue for environmental data."""
|
|
2
|
+
|
|
3
|
+
from envlib import vocabularies
|
|
4
|
+
from envlib.catalogue import Catalogue, DatasetRef
|
|
5
|
+
from envlib.metadata import Metadata, ValidationError, canonical_station_point, compute_station_id
|
|
6
|
+
|
|
7
|
+
__version__ = '0.1.4'
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
'Catalogue',
|
|
11
|
+
'DatasetRef',
|
|
12
|
+
'Metadata',
|
|
13
|
+
'ValidationError',
|
|
14
|
+
'canonical_station_point',
|
|
15
|
+
'compute_station_id',
|
|
16
|
+
'vocabularies',
|
|
17
|
+
]
|
|
@@ -362,10 +362,16 @@ def _check_stations(ds):
|
|
|
362
362
|
stored = [str(v) for v in sid_var.data]
|
|
363
363
|
if stored != expected:
|
|
364
364
|
first_bad = next(i for i, (s, e) in enumerate(zip(stored, expected, strict=True)) if s != e)
|
|
365
|
+
bad_point = points[first_bad]
|
|
365
366
|
msg = (
|
|
366
367
|
f'{STATION_ID_VAR!r} values do not match the envlib derivation (first mismatch at index '
|
|
367
|
-
f'{first_bad}: stored {stored[first_bad]!r}, derived {expected[first_bad]!r}
|
|
368
|
-
f'
|
|
368
|
+
f'{first_bad}: stored {stored[first_bad]!r}, derived {expected[first_bad]!r} from the '
|
|
369
|
+
f'STORED geometry ({bad_point.x}, {bad_point.y})). The stored GEOMETRY is the usual '
|
|
370
|
+
f'culprit here, not the id: a store may re-round a point as it writes it (cfdb encodes '
|
|
371
|
+
f'point coordinates at 5 decimal places), so a point that derived the stored id before '
|
|
372
|
+
f'the write no longer derives it after. Pass station points through '
|
|
373
|
+
f'envlib.canonical_station_point BEFORE writing them to the geometry coordinate, so '
|
|
374
|
+
f'what is stored is already canonical and the round-trip is stable.'
|
|
369
375
|
)
|
|
370
376
|
raise ValidationError(msg)
|
|
371
377
|
|
|
@@ -250,13 +250,30 @@ def _hash_fields(field_values) -> str:
|
|
|
250
250
|
return blake2b(joined.encode('utf-8'), digest_size=12).hexdigest()
|
|
251
251
|
|
|
252
252
|
|
|
253
|
-
def
|
|
254
|
-
"""
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
253
|
+
def canonical_station_point(geometry) -> shapely.Point:
|
|
254
|
+
"""The canonical EPSG:4326 Point whose WKB :func:`compute_station_id` hashes.
|
|
255
|
+
|
|
256
|
+
z stripped if present; WKT round-trip with ``rounding_precision=5`` (~1 m at
|
|
257
|
+
the equator); signed zero collapsed (``-0.0`` -> ``0.0``, reachable after
|
|
258
|
+
reprojection). Same validation, and the same ``ValidationError``, as
|
|
259
|
+
:func:`compute_station_id` — a producer wants a bad geometry rejected here
|
|
260
|
+
rather than one step later.
|
|
261
|
+
|
|
262
|
+
**Producers must STORE this point, not the raw one.** A store that re-rounds
|
|
263
|
+
the geometry its own way will otherwise hold a point that no longer derives
|
|
264
|
+
the ``station_id`` stored beside it, and the dataset becomes unpublishable.
|
|
265
|
+
cfdb is exactly such a store: it encodes point coordinates with
|
|
266
|
+
``shapely.to_wkt(..., rounding_precision=5)``, whose ``trim=True`` default
|
|
267
|
+
rounds the shortest decimal *string* half-to-even, while the derivation here
|
|
268
|
+
uses ``wkt.dumps`` (``trim=False``), which rounds the underlying *binary*
|
|
269
|
+
value. The two disagree on roughly 9% of coordinates given to 6 decimal
|
|
270
|
+
places — every case being an ordinate whose shortest representation ends in
|
|
271
|
+
a trailing '5' past the 5th decimal. Passing a point through this function
|
|
272
|
+
first makes the round-trip a fixed point, because a canonical point has no
|
|
273
|
+
6th decimal left to round. (envlib 0.1.4; found on a live publish failure,
|
|
274
|
+
2026-08-24.)
|
|
275
|
+
|
|
276
|
+
Idempotent: ``canonical_station_point(canonical_station_point(p))`` is ``p``.
|
|
260
277
|
"""
|
|
261
278
|
if not isinstance(geometry, shapely.Point):
|
|
262
279
|
msg = f'station geometry must be a shapely Point (v1 supports Points only), not {type(geometry).__name__}.'
|
|
@@ -272,7 +289,22 @@ def compute_station_id(geometry) -> str:
|
|
|
272
289
|
if geometry.has_z:
|
|
273
290
|
geometry = shapely.Point(geometry.x, geometry.y)
|
|
274
291
|
rounded = cast('shapely.Point', wkt.loads(wkt.dumps(geometry, rounding_precision=5)))
|
|
275
|
-
|
|
292
|
+
return shapely.Point(rounded.x + 0.0, rounded.y + 0.0)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def compute_station_id(geometry) -> str:
|
|
296
|
+
"""Deterministic station id from a shapely Point in EPSG:4326.
|
|
297
|
+
|
|
298
|
+
tethys-compatible derivation: z stripped if present; WKT round-trip with
|
|
299
|
+
``rounding_precision=5`` (~1 m at the equator); signed zero collapsed
|
|
300
|
+
(``-0.0`` -> ``0.0``, reachable after reprojection); explicit little-endian
|
|
301
|
+
WKB; keyless blake2b-12 hex. Same x/y at different z share a station_id.
|
|
302
|
+
|
|
303
|
+
The canonicalization is :func:`canonical_station_point`; this hashes its WKB.
|
|
304
|
+
Splitting the two moved no id (verified against 0.1.3 over ~143,000 points
|
|
305
|
+
in review round ``envlib-stationid-1``, including exception parity).
|
|
306
|
+
"""
|
|
307
|
+
canonical_point = canonical_station_point(geometry)
|
|
276
308
|
return blake2b(shapely.to_wkb(canonical_point, byte_order=1), digest_size=12).hexdigest()
|
|
277
309
|
|
|
278
310
|
|
envlib-0.1.3/envlib/__init__.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"""envlib: a distributed database and catalogue for environmental data."""
|
|
2
|
-
|
|
3
|
-
from envlib import vocabularies
|
|
4
|
-
from envlib.catalogue import Catalogue, DatasetRef
|
|
5
|
-
from envlib.metadata import Metadata, ValidationError, compute_station_id
|
|
6
|
-
|
|
7
|
-
__version__ = '0.1.3'
|
|
8
|
-
|
|
9
|
-
__all__ = ['Catalogue', 'DatasetRef', 'Metadata', 'ValidationError', 'compute_station_id', 'vocabularies']
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|