Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

greglucas
Copy link
Contributor

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

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
y[pole_points] = np.sign(y) * pole_cutoff
y[pole_points] = np.sign(y[pole_points]) * pole_cutoff

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! Updated now.

@lgolston
Copy link
Contributor

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.

greglucas and others added 4 commits August 28, 2023 20:07
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quiver with all projections: bad direction of arrows
4 participants