envlib-ingest-base 0.3.0__tar.gz → 0.3.2__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.
@@ -1,3 +1,22 @@
1
+ Metadata-Version: 2.5
2
+ Name: envlib-ingest-base
3
+ Version: 0.3.2
4
+ Summary: Shared toolkit for envlib data-ingest repos: source-agnostic time-series resampling and ts_ortho (station) dataset build + idempotent commons update.
5
+ Project-URL: Source, https://github.com/envlib/envlib-ingest-base
6
+ Author-email: mullenkamp <mullenkamp1@gmail.com>
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Requires-Python: >=3.10
11
+ Requires-Dist: booklet>=0.12.10
12
+ Requires-Dist: cfdb>=0.9.4
13
+ Requires-Dist: ebooklet>=0.10.3
14
+ Requires-Dist: envlib>=0.1.4
15
+ Requires-Dist: numpy
16
+ Requires-Dist: sentry-sdk
17
+ Requires-Dist: shapely>=2.0
18
+ Description-Content-Type: text/markdown
19
+
1
20
  # envlib-ingest-base
2
21
 
3
22
  Shared, tested toolkit for the envlib data-ingest family — and the Docker base image that carries
@@ -190,6 +209,15 @@ Version notes: `station_ref` exists in datasets built by toolkit >= 0.1.2 (mergi
190
209
  into an older dataset raises — rebuild it — while revise-only merges keep working); the CF attrs
191
210
  and `station_altitude` land from toolkit >= 0.1.4.
192
211
 
212
+ Station **geometry** is canonicalized through `envlib.canonical_station_point` before it is
213
+ stored, from toolkit >= 0.3.1 (which is why that release floors `envlib>=0.1.4`). Without it, a
214
+ source supplying more than 5 decimal places of longitude/latitude could write a point that cfdb
215
+ re-rounds on the way in, leaving a stored geometry that no longer derives the stored `station_id`
216
+ — a dataset that then fails `publish()` forever. Ids are unaffected, so this changed nothing for
217
+ stations already stored; datasets built by earlier toolkits need no rebuild. Two stations that
218
+ round to the same point (within ~1 m) are now rejected at build with both refs named, instead of
219
+ dying inside cfdb's coordinate-uniqueness check.
220
+
193
221
  **The envlib metadata is the single source of truth for the cadence** — there is no `freq`
194
222
  parameter. `frequency_interval` is a closed envlib vocabulary; only *fixed* codes work here
195
223
  (`1min`…`30min`, `1h`…`12h`, `day` — `month`/`year`/`None` raise, a dense axis needs a fixed
@@ -1,21 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: envlib-ingest-base
3
- Version: 0.3.0
4
- Summary: Shared toolkit for envlib data-ingest repos: source-agnostic time-series resampling and ts_ortho (station) dataset build + idempotent commons update.
5
- Project-URL: Source, https://github.com/envlib/envlib-ingest-base
6
- Author-email: mullenkamp <mullenkamp1@gmail.com>
7
- License-Expression: Apache-2.0
8
- License-File: LICENSE
9
- Classifier: Programming Language :: Python :: 3 :: Only
10
- Requires-Python: >=3.10
11
- Requires-Dist: cfdb>=0.9.4
12
- Requires-Dist: ebooklet>=0.10.3
13
- Requires-Dist: envlib>=0.1.3
14
- Requires-Dist: numpy
15
- Requires-Dist: sentry-sdk
16
- Requires-Dist: shapely>=2.0
17
- Description-Content-Type: text/markdown
18
-
19
1
  # envlib-ingest-base
20
2
 
21
3
  Shared, tested toolkit for the envlib data-ingest family — and the Docker base image that carries
@@ -208,6 +190,15 @@ Version notes: `station_ref` exists in datasets built by toolkit >= 0.1.2 (mergi
208
190
  into an older dataset raises — rebuild it — while revise-only merges keep working); the CF attrs
209
191
  and `station_altitude` land from toolkit >= 0.1.4.
210
192
 
193
+ Station **geometry** is canonicalized through `envlib.canonical_station_point` before it is
194
+ stored, from toolkit >= 0.3.1 (which is why that release floors `envlib>=0.1.4`). Without it, a
195
+ source supplying more than 5 decimal places of longitude/latitude could write a point that cfdb
196
+ re-rounds on the way in, leaving a stored geometry that no longer derives the stored `station_id`
197
+ — a dataset that then fails `publish()` forever. Ids are unaffected, so this changed nothing for
198
+ stations already stored; datasets built by earlier toolkits need no rebuild. Two stations that
199
+ round to the same point (within ~1 m) are now rejected at build with both refs named, instead of
200
+ dying inside cfdb's coordinate-uniqueness check.
201
+
211
202
  **The envlib metadata is the single source of truth for the cadence** — there is no `freq`
212
203
  parameter. `frequency_interval` is a closed envlib vocabulary; only *fixed* codes work here
213
204
  (`1min`…`30min`, `1h`…`12h`, `day` — `month`/`year`/`None` raise, a dense axis needs a fixed
@@ -7,7 +7,7 @@
7
7
  from envlib_ingest_base.resample import resample
8
8
  from envlib_ingest_base.tsortho import build_and_publish, build_local, merge_dataset, update_and_publish
9
9
 
10
- __version__ = '0.3.0'
10
+ __version__ = '0.3.2'
11
11
  __all__ = [
12
12
  'build_and_publish',
13
13
  'build_local',
@@ -391,10 +391,50 @@ def _write_rows(var, stations: dict, series: dict, t0_us: int, n_times: int, ste
391
391
 
392
392
 
393
393
  def _points_ids_names(stations: dict):
394
- points = [shapely.Point(float(d['lon']), float(d['lat'])) for d in stations.values()]
394
+ """Station geometry + labels, in ``stations`` order.
395
+
396
+ The points are CANONICALISED (``envlib.canonical_station_point``) before they leave this
397
+ function, and that is not cosmetic: cfdb stores a point coordinate by encoding it with
398
+ ``shapely.to_wkt(..., rounding_precision=5)``, whose ``trim=True`` default rounds the
399
+ shortest decimal string half-to-even, while ``compute_station_id`` rounds the binary value
400
+ via ``wkt.dumps`` (``trim=False``). They disagree on ~9% of coordinates supplied to 6
401
+ decimal places, so writing the RAW point stores a geometry that no longer derives the
402
+ ``station_id`` written beside it and the dataset can never be published — which is exactly
403
+ how a live ECan publish failed on 2026-08-24. Canonicalising first makes the store's
404
+ round-trip a fixed point. Ids are unaffected (the canonical point is what they already
405
+ hashed), so this changes nothing for any station already stored.
406
+ """
407
+ points = [
408
+ envlib.canonical_station_point(shapely.Point(float(d['lon']), float(d['lat'])))
409
+ for d in stations.values()
410
+ ]
395
411
  ids = np.array([envlib.compute_station_id(p) for p in points], dtype=object)
396
412
  names = np.array([str(d['name']) for d in stations.values()], dtype=object)
397
413
  refs = np.array([str(r) for r in stations], dtype=object)
414
+
415
+ # Two stations inside the same ~1 m 5-dp cell collapse to ONE station_id. That is the
416
+ # id contract, not a defect here — but it must be said out loud. Without this, the build
417
+ # dies in cfdb's coord-uniqueness check ('The data for coords must be unique.'), which
418
+ # names neither station, and before canonicalisation it did something worse: wrote two
419
+ # rows carrying the same id and failed much later inside catalogue validation.
420
+ if len(set(ids)) != len(ids):
421
+ seen: dict = {}
422
+ clashes = []
423
+ for ref, sid, p in zip(refs, ids, points, strict=True):
424
+ if sid in seen:
425
+ first_ref, first_p = seen[sid]
426
+ clashes.append(
427
+ f'{first_ref!r} ({first_p.x}, {first_p.y}) and {ref!r} ({p.x}, {p.y}) -> {sid}'
428
+ )
429
+ else:
430
+ seen[sid] = (ref, p)
431
+ msg = (
432
+ 'stations collapse to the same station_id (identical to 5 decimal places, ~1 m): '
433
+ + '; '.join(clashes)
434
+ + '. A station_id IS its rounded location, so these are one station to envlib — '
435
+ 'drop one, or correct the coordinates if they are wrong.'
436
+ )
437
+ raise ValueError(msg)
398
438
  return points, ids, names, refs
399
439
 
400
440
 
@@ -683,6 +723,11 @@ def merge_dataset(ds, stations: dict, series: dict, *, variable: str):
683
723
  active = list(non_empty)
684
724
  sub = {r: stations[r] for r in active}
685
725
  points, ids, names, refs = _points_ids_names(sub)
726
+ # ONE derivation per station per merge, reused by the write loop below. That loop used to
727
+ # recompute the id from stations[ref] independently, which meant the store path and the
728
+ # row-lookup path each had their own spelling of "the id for this station" and nothing
729
+ # forced them to agree.
730
+ ref_to_sid = dict(zip(refs, ids, strict=True))
686
731
  # validated up front, BEFORE any row mutation: a junk/non-finite altitude then raises
687
732
  # pre-append (never leaving a half-written station row), and the check is uniform — merge
688
733
  # is as loud on bad altitude as build, regardless of new-vs-existing or var presence.
@@ -753,9 +798,7 @@ def merge_dataset(ds, stations: dict, series: dict, *, variable: str):
753
798
  n_before = 0
754
799
  widest = 0
755
800
  for ref, (t, v, ex) in non_empty.items():
756
- d = stations[ref]
757
- sid = envlib.compute_station_id(shapely.Point(float(d['lon']), float(d['lat'])))
758
- row = id_to_row[sid]
801
+ row = id_to_row[ref_to_sid[ref]]
759
802
  col_abs = _step_index(t, t0, step_us)
760
803
  n_before += int((col_abs < 0).sum()) # window straddles the axis start: pre-axis values
761
804
  keep = col_abs >= 0
@@ -13,7 +13,10 @@ dependencies = [
13
13
  # Released PyPI stack only - ingest repos are arm's-length consumers.
14
14
  # Deliberately pandas-free: the API is numpy tuples/dicts (pandas objects still
15
15
  # work as *inputs* by duck-typing).
16
- "envlib>=0.1.3",
16
+ # >=0.1.4 is a HARD floor, not hygiene: tsortho calls envlib.canonical_station_point,
17
+ # which does not exist before 0.1.4 — an older envlib makes EVERY ts_ortho build and
18
+ # merge die with AttributeError in _points_ids_names.
19
+ "envlib>=0.1.4",
17
20
  # >=0.9.4 is a HARD floor: older cfdb fabricates values when its packed encoder meets
18
21
  # NaN/out-of-range data (cfdb changelog 0.9.4); tsortho also enforces this at runtime.
19
22
  "cfdb>=0.9.4",
@@ -21,6 +24,7 @@ dependencies = [
21
24
  "numpy",
22
25
  "shapely>=2.0",
23
26
  "sentry-sdk",
27
+ "booklet>=0.12.10",
24
28
  ]
25
29
 
26
30
  [dependency-groups]