Skip to content

refactor(s2): validate CRS/EPSG and bbox attrs via typed constructors (#180 parity) - #217

Draft
lhoupert wants to merge 1 commit into
s1-tilingfrom
refactor/s2-crs-typing
Draft

refactor(s2): validate CRS/EPSG and bbox attrs via typed constructors (#180 parity)#217
lhoupert wants to merge 1 commit into
s1-tilingfrom
refactor/s2-crs-typing

Conversation

@lhoupert

Copy link
Copy Markdown
Contributor

Follow-up to #180: extends the typed-CRS/bbox refactor (9ebad3e) to the S2/generic conversion code. Stacked on #216 — retarget to main once it merges.

Summary

  • eopf_geozarr.types: add EPSGCode NewType + make_epsg_code validating constructor (integer sibling of CRSCode/make_crs_code; accepts 32631, "32631", "EPSG:32631"), with unit tests.
  • Route all untyped proj:epsg / CPM-2.6.0 CRS reads in s2_converter.py, s2_multiscale.py and conversion/geozarr.py through it; _as_bbox now delegates to make_bounding_box; the store-root bbox walker validates proj:code and carries BoundingBox2D.
  • BACKSCATTER_CF_ATTRS gains its missing Final annotation.

For reviewers

Typing/validation only — no conversion-logic or on-disk changes. The one intentional behavior change: corrupt CRS attrs now fail early with a clear TypeError instead of pyproj's CRSError deeper in the stack (see updated test_write_geo_metadata_invalid_crs). Verified: pyright 0 errors, pre-commit green, full non-network suite passes.

Author attestation

  • I am a human, these are my changes, and I have reviewed and understood
    every change and can explain why each is correct.

Implemented with AI assistance (Claude Code); reviewed by me and verified via pyright, pre-commit and the full non-network test suite.

…#180 parity)

Extend the typed-CRS/bbox idiom from the S1 RTC review (9ebad3e) to the
pre-existing S2/generic conversion code:

- types.py: add EPSGCode NewType + make_epsg_code validating constructor,
  the integer-code sibling of CRSCode/make_crs_code. Accepts 32631, "32631"
  and "EPSG:32631" (the forms found in stored attrs and CPM 2.6.0 metadata);
  corrupt values fail loudly with a clear TypeError.
- s2_converter.py: route the CPM-2.6.0 hand-parsing and the proj:epsg read
  through make_epsg_code; _as_bbox delegates to make_bounding_box (keeping
  its lenient skip-on-malformed walker semantics); the store-root bbox
  walker validates proj:code via make_crs_code and carries BoundingBox2D.
- conversion/geozarr.py, s2_multiscale.py: proj:epsg / CPM-2.6.0 reads via
  make_epsg_code.
- s1_ingest.py: BACKSCATTER_CF_ATTRS gains the Final annotation its sibling
  TIME_CF_ATTRS already has.
- tests: make_epsg_code unit tests; test_write_geo_metadata_invalid_crs now
  expects the earlier, typed error (TypeError vs pyproj CRSError deeper in
  the stack) — the one intentional behavior change.

No on-disk output changes. Full-project pyright: 0 errors; pre-commit green;
full non-network suite passes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant