Densify the geostationary bounding polygon before reprojecting in AreaSlicer - #729
Conversation
…aSlicer AreaSlicer.get_polygon_to_contain builds the bounding polygon of a geostationary source disk and reprojects it into the destination projection to compute the source slice. When the source is a partial disk (rapid scan or region of interest data), clipping the disk to its area extent introduces straight chord edges with only two vertices. Those chords are not straight in the destination projection, so the reprojected polygon cuts the corner and the source slice comes out too small, leaving part of the destination without data. Densify the polygon with segmentize before reprojecting it, so the chord edges keep enough vertices to follow their true shape in the destination projection.
|
Thanks for this PR! I just wanted to let you know that we're not ignoring you, but most of us are on vacation or (like me) don't have time to review this right now. I hope to review it next week though. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #729 +/- ##
=======================================
Coverage 93.68% 93.69%
=======================================
Files 89 89
Lines 13715 13725 +10
=======================================
+ Hits 12849 12859 +10
Misses 866 866
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Manny7717
left a comment
There was a problem hiding this comment.
Review
Verified locally on head 99f9c93c: 19/19 tests in pyresample/test/test_slicer.py pass (shapely 2.1.2). The approach is sound — densifying in the source projection before the inverse transform is exactly where the straight chord edges need intermediate vertices, since chords in the geos projection become curves in the destination CRS.
Two things to look at (inline): a Shapely minimum-version concern for segmentize, and a degenerate-extent crash in the segment_length computation. Both are cheap to guard.
| # vertices the reprojected polygon cuts the corner and the computed slice | ||
| # is too small, leaving part of the destination without data. | ||
| segment_length = np.max(np.abs(self.area_to_crop.area_extent)) / 100 | ||
| geos_poly = geos_poly.segmentize(segment_length) |
There was a problem hiding this comment.
segmentize requires Shapely >= 2.0 (GEOS >= 3.10), but pyproject.toml declares just "shapely" with no minimum. On a Shapely 1.8 install this raises AttributeError. Worth confirming the minimum supported Shapely version and either pinning it or guarding with a hasattr/fallback.
| # are not straight in the destination crs, so without intermediate | ||
| # vertices the reprojected polygon cuts the corner and the computed slice | ||
| # is too small, leaving part of the destination without data. | ||
| segment_length = np.max(np.abs(self.area_to_crop.area_extent)) / 100 |
There was a problem hiding this comment.
If area_extent is degenerate (e.g. all zeros), segment_length becomes 0 and segmentize(0) raises GEOSException: Tolerance must be positive (verified against shapely 2.1.2). A if segment_length > 0: guard (or max(segment_length, 1e-9)) would make this robust. Also: with the 1/100 divisor, a very small partial-disk extent produces a fine mesh — worth a sanity bound if performance matters.
AreaSlicer.get_polygon_to_containbuilds the bounding polygon of a geostationary source disk and reprojects it into the destination projection to compute the source slice. When the source is a partial disk (rapid scan or region of interest data), clipping the disk to its area extent introduces straight chord edges with only two vertices. Those chords are not straight in the destination projection, so the reprojected polygon cuts the corner and the source slice comes out too small, leaving part of the destination empty. A full disk source is unaffected, because its whole boundary is the densely sampled disk arc.This densifies the polygon with
segmentizebefore reprojecting it, so the chord edges keep enough vertices to follow their true shape in the destination projection. The problem was found in satpy when resampling MSG rapid scan data to a polar stereographic area withgradient_search.segmentizeneeds shapely 2.0 or newer. shapely is currently unpinned in the dependencies, so ashapely>=2.0pin can be added if you want it explicit.