Linestring / multi-linestring morton coverage + metric buffer helper#26
Conversation
CMR registers the collection as version '2' (the file asset is named InSAR_GL_Antarctica_v02.1.gpkg, which is where '2.1' came from). Use the canonical short_name='NSIDC-0498' directly and drop the candidate-list fallback. Verified earthaccess.search_data returns granules. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #26 +/- ##
==========================================
+ Coverage 87.30% 88.27% +0.97%
==========================================
Files 15 17 +2
Lines 2000 2192 +192
==========================================
+ Hits 1746 1935 +189
- Misses 254 257 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 10.39%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | order6[100] |
414.7 µs | 363 µs | +14.23% |
| ❌ | test_coverage_triangle_order6 |
618.5 µs | 690.2 µs | -10.39% |
| ⚡ | test_coverage_triangle_order4 |
307.2 µs | 272 µs | +12.93% |
Comparing feature/morton-linestring-coverage (5da9f28) with main (b87f65e)
Summary
Adds
mortie.linestring_coverage()— morton-index coverage of open polylines — andmortie.morton_buffer_meters(), a metric-width convenience wrapper aroundmorton_buffer(from #17). Includes a real-data example notebook that queries the NSIDC InSAR Antarctic grounding line dataset. Closes #25.What's new
linestring_coverage(lats, lons, order=18)— Python interface over a new Rust module (src_rust/src/linestring.rs). Rasterizes each segment between consecutive vertices by sampling the great-circle arc at half-cell-resolution spacing, guaranteeing a contiguous cell chain. Reuses the Phase A interpolation helpers fromcoverage.rs(madepub(crate)), so there's one source of truth for the vertex-neighbor logic introduced in #17.Return shape:
np.ndarrayof morton indices.listof arrays, one per input line. Lengths may differ; per-line results are not deduplicated across lines.morton_buffer_meters(cells, width_m)— wrapsmorton_buffer. Infers order from the input cells, computesk = ceil(width_m / cell_width_m)usingR_earth · sqrt(π/3) / 2^order, and returns the resulting border ring. The docstring is explicit that this is approximate: the achieved width is rounded up to the nearest whole cell width, so the buffer always covers at leastwidth_m.Why this API shape
Lat/lon array input (rather than shapely geometries) keeps
mortiedependency-free. The example notebook shows the idiomatic pattern:earthaccess→geopandas→ unpack shapelyLineString/MultiLineStringinto arrays →linestring_coverage. The multi-line return is alist(not a 2-D array or single concatenated 1-D array) because per-line lengths differ, and callers who want the union can trivially donp.unique(np.concatenate(per_line)).Files
src_rust/src/linestring.rs— new Rust module withlinestring_to_morton_coverage(10 unit tests).src_rust/src/coverage.rs— three Phase A helpers promoted topub(crate). No behavior change.src_rust/src/lib.rs—rust_linestring_coveragepyfunction registered in_rustie.mortie/linestring.py—linestring_coveragePython wrapper, validation, multi dispatch.mortie/tools.py—morton_buffer_metershelper.mortie/__init__.py— public exports.mortie/tests/test_linestring.py— 27 tests (single/multi shape, sort/unique, endpoints present, interpolation fills gaps, hemisphere signs, order-range validation, NaN/inf rejection, meter-buffer monotonicity + equivalence tok).examples/morton_linestring_insar_gl.ipynb— self-contained example: synthetic linestring → real NSIDC-0498 v2 InSAR grounding line viaearthaccess→ south-polar-stereographic plot → buffer demo (k=1,k=3,~50 kmmetric).pyproject.toml— newdocsextra for the example notebook (jupyterlab,notebook,ipykernel,matplotlib,shapely,geopandas,pyogrio,earthaccess,cartopy,healpy,requests).Test plan
cargo test— 67 Rust tests pass (10 new linestring tests).pytest mortie/tests/— 203 passed, 3 skipped (27 new linestring tests).NSIDC-0498 v2.Clarifying Q&A
Design decisions and the implementation plan are documented as comments on #25 for reproducibility.
🤖 Generated with Claude Code