-
Notifications
You must be signed in to change notification settings - Fork 368
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
FIX: Change PlateCarree Vector Handling #1926
base: main
Are you sure you want to change the base?
Conversation
80a94e0
to
5be87fa
Compare
lib/cartopy/crs.py
Outdated
warnings.warn('Vector transforms near the pole ' | ||
'may not have been transformed correctly') | ||
# Move the pole points away from the pole ever so slightly | ||
y[pole_points] = np.sign(y) * pole_cutoff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
y[pole_points] = np.sign(y) * pole_cutoff | |
y[pole_points] = np.sign(y[pole_points]) * pole_cutoff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch! Updated now.
This seems like a good solution given this feature has been requested multiple times, and represents a common use case. It is too bad you didn't already get some feedback! I ran some test cases for Antarctica (similar to what was presented by @jabadge in #1179) and the behavior looks right. The pole cutoff of 89.99 was plenty conservative in this test. The only thing I didn't initially realize that the section in step 4 starting if isinstance(self, PlateCarree): doesn't apply when transforming from lat-lon to a different projection, and have not tested that part. |
If a PlateCarree projection is used for transforming vectors, users likely have their data in longitude/latitude for the locations and the measurement of the field is in North/South. To handle this situation with PlateCarree requires an additional scaling by the latitude of the point. This also requires some additional care for handling points near the pole when applying this scaling.
This adds a parameterization for the vector transform tests on the boundary. The previous values were incorrect. They should be at an angle, not all in vertical/horizontal coordinates. This can be thought of by "wrapping" around the pole with a vector pointing up and right at the corner (180, 90) turning into a down and left vector under transform to stereographic.
Move crs_transform_vectors tests into the test_vector_transforms file.
Contains the updated images based on the updated vector transform routines.
5be87fa
to
4ef0b66
Compare
Update of #1920 (Apparently you can't reopen a closed PR when you've force-pushed to your branch)
If a PlateCarree projection is used for transforming vectors, users likely have their data in longitude/latitude for the locations and the measurement of the field is in geographic North/South (NOT PlateCarree coordinates). To handle this situation with PlateCarree requires an additional scaling by the latitude of the point.
This requires some additional care for handling points near the pole when applying the scaling (due to near-zero values in the cos(lat) scaling). To handle this, we can apply an artificial cutoff within the vector transform of 89.99, which pushes the point of the vector transforms ever so slightly away from the pole. This cutoff does not get propagated up to the x/y locations of the plot, only the points that are used within the vector transform. Additionally, this also indicates that the current vector directions we are testing against are incorrect, where I think I've convinced myself this new version is correct with what I would expect.
I haven't updated the image tests yet, as I thought it might be easiest to leave them failing for now so people can download the diff and see what they look like. Overall, I think this is an improvement, but it comes at the cost of special-casing the PlateCarree transform. We could also add a keyword argument 'latlon=True', or something similar to keep this as an opt-in and not change any of the old behavior.
Note
If we want to generalize this to all projections, perhaps we should try to leverage pyproj's
get_factors()
and apply the meridional and parallel scale factors to the u/v components.https://pyproj4.github.io/pyproj/stable/api/proj.html#pyproj.Proj.get_factors
closes #1179