Improve accuracy for high-resolution images in reproject_exact#589
Merged
astrofrog merged 8 commits intoastropy:mainfrom Mar 24, 2026
Merged
Improve accuracy for high-resolution images in reproject_exact#589astrofrog merged 8 commits intoastropy:mainfrom
astrofrog merged 8 commits intoastropy:mainfrom
Conversation
Use planar approximation (shoelace formula) instead of Girard's theorem for small spherical polygons, avoiding catastrophic cancellation in the area = sum_of_angles - (N-2)*pi computation. This fixes flux conservation for pixel scales down to ~0.001 arcsec (previously failed below ~0.07 arcsec), which is important for instruments like JWST NIRCam.
…xels For small pixels, bypass both the spherical polygon intersection (ComputeIntersection) and Girard's theorem by doing the full overlap computation in a local tangent plane using Sutherland-Hodgman 2D polygon clipping and the shoelace formula. This eliminates all precision issues from the TOLERANCE constant and spherical geometry for sub-arcsecond pixels, extending accurate flux conservation down to ~1e-6 arcsec (previously failed below ~0.07 arcsec).
Member
Author
|
@acikota - your example from Dropbox now returns: which seems ok? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #589 +/- ##
=======================================
Coverage 91.06% 91.06%
=======================================
Files 30 30
Lines 1858 1858
=======================================
Hits 1692 1692
Misses 166 166 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
Author
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




As described in #199, the reproject_exact function suffers from precision issues when reprojecting images with sub-arcsecond pixel scales, which is particularly problematic for instruments like JWST NIRCam (0.03" pixels). There are two reasons for this:
This PR fixes both issues by adding a planar approximation path in computeOverlap. When all vertices of both the input and output pixels are within ~3.4 arcmin of their centroid, the code projects them onto a local tangent plane and performs the entire overlap computation in 2D — using Sutherland-Hodgman polygon clipping and the shoelace formula instead of the spherical intersection and Girard's theorem. This avoids all sources of precision loss, since coordinate values in the tangent plane are proportional to the polygon size rather than being tiny perturbations on a unit sphere. The same planar approximation is also applied as a fallback within the Girard function itself, to handle the edge case of tiny sliver overlaps between large pixels. With these changes, flux conservation is accurate down to ~1e-5 arcsec, compared to the previous limit of ~0.07 arcsec.
Here's an updated plot of accuracy vs resolution based on this PR:
For comparison, the original plot looked like: