-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent definition of inside/outside Nightshade feature geometry #2469
Comments
Thanks for the clear report @Eliam76. Everything seems fine if we plot in the projection in which dummy_nightshade = Nightshade()
proj = dummy_nightshade.crs |
Thank you for your answer. Yes it seems that there are many projections in which the
which gives the same result as in my initial post
Looking at the
|
I have done a little more digging... The decision whether we have the interior or exterior of a polygon is based on the Shapely Lines 1181 to 1185 in d5a07ab
I intercepted the relevant ring for the "Refraction = 8" case. The From the Shapely docs, it appears poly = sgeom.Polygon(ring)
geoms = shapely.make_valid(poly)
[find useful polygons within geoms]
new_ring = new_poly.exterior Unfortunately this process does not preserve the direction of the vertices. So I still have no idea for a fix :( |
I'm actually somewhat surprised the positive refraction angles give valid geometries at all. We are creating initial geometries with -98 -> +98 latitudes in that situation. cartopy/lib/cartopy/feature/nightshade.py Lines 73 to 75 in d5a07ab
I'm not entirely clear whether we would want to do some validation on the refraction angle (raise if it isn't negative?), or immediately take the negative absolute value for users |
Description
For a project, I want to plot the intersection between the Earth and specific planes facing the Sun. For this, I use the Nightshade feature : I take advantage of the refraction parameter to adjusts the day/night geometry boundary, which has the same result as shifting a plane facing the Sun. I use stereographic projection, so all the resulting projected polygons are discs or circular holes.
However, the behavior of the feature is inconsistent when the refraction value is positive (normally the value is zero or negative), especially at dates close to summer solstices (but not always at the exact solstice). The definition of the inside/outside of the polygon seems randomly wrong, as if the points weren't ordered correctly.
These are pretty extreme values for the refraction but it may underline an issue with the source code. As a suggestion, since the Nightshade feature compute the solar position
lat, lon = _solar_position(date)
it should be possible to determine the correct orientation as the projected polygon (representing the shaded part of the Earth) should be the one not containing this point.
Code to reproduce
Full environment definition
Operating system
Windows 10 Family, 64bits edition
Cartopy version
0.23.0
pip list
py -3.12 -m pip list
The text was updated successfully, but these errors were encountered: