Fix boundaries losing precision for accurate polygon calculations#677
Fix boundaries losing precision for accurate polygon calculations#677djhoese merged 1 commit intopytroll:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #677 +/- ##
=======================================
Coverage 94.01% 94.01%
=======================================
Files 89 89
Lines 13614 13621 +7
=======================================
+ Hits 12799 12806 +7
Misses 815 815
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hey @djhoese ! It has been a while that I have worked on it. i wonder if sooner or later we should try to replace the use of spherical class/functions with spherely. I see the development stop 6 months ago, so I don't know what is their plan for the future. But it's a wrapper around s2geometry C++ code, so migrating to spherely should also I guess speed up a lot area intersection stuffs and remapping ! |
|
Oh awesome. Yeah the people who created it are very active in this type of software. |
|
@djhoese - Thanks for looking at this! I am likely doing somethign wrong, but I tried those changes on my polar2grid 3.1, but I think some of the other parts of polar2grid must need updating, as it fails for me later in the process with an odd error: |
|
@spruceboy I've moved that error/issue back to the P2G issue for now. I think it is unrelated to this fix/PR. |
|
Indeed, spherely looks really interesting! |
In a real world case identified by @spruceboy, if a 32-bit coordinate is given to
AreaBoundary(or any boundary class) that is exactly at 90 degrees north, the conversion to radians and then validity checks in the spherical polygon class will raise an error.What I discovered is that due to precision issues you end up with the input coordinate being
4.371139006309477e-08greater thannp.pi / 2and failing the validity check. See ssec/polar2grid#766 for more info.The alternative solution could be allowing an epsilon greater/less than 90/-90 in the validity check but then the question becomes how to handle that coordinate? Should it be clipped? Should it be left alone and hope that the math is "good enough". Maybe it is just better to be more accurate with this PR's fix.
CC @ghiggi
@spruceboy, feel free to hack your Polar2Grid installation and add the
dtype=np.float64shown in the changes here forpyresample/boundary/legacy_boundary.py.