-
Notifications
You must be signed in to change notification settings - Fork 365
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
PlateCarree projection errors cause gridline and view limit problems when cental longitude != 0 #1751
Comments
Have tested on the master branch and still exists, also upgrading Proj to 8.0.0 didn't fix it (was using 5.1.0 before). |
You're correct, I hadn't reinstalled Cartopy properly - some @dopplershift so having rebuilt Cartopy against 7.2.1 (and checking _crs.PROJ4_RELEASE to make sure I did it properly):
Code on the master branch fixes the missing latitude labels. The error in projecting the view limit still exists (x1=179.999656677246 across all configurations I tried). |
Description
I've been working on a global map centered on Australia (longitude 132) by using a PlateCarree projection centered on 132 for the axes. I set the extent using a 0-centered PlateCarree CRS, using coordinates relative to it to center on 132 (west = -48, east = 312, south = -90, north = 90).
Gridline labels worked fine with a 0 centered CRS, but not with the 132 CRS. The right labels are missing (bottom labels missing is intentional):
I found that point transforms when using PlateCarree not centered on 0 give strange results:
180 will always transform to -180, along with some floating point error.
This line
cartopy/lib/cartopy/mpl/gridliner.py
Line 527 in 4ca93c1
in gridliner projects the latitude and longitude gridlines to the axes CRS. As I'm using the 132 centered CRS for both the axes and gridlines, it transforms against itself. This turns the start and end of the longitude lines to -180, -180, rather than -180, 180. So any labels intersecting 180 actually get placed at -180 (or at least I think they do, I expected setting
left_labels
to False andright_labels
to True would cause the left labels to appear, but it doesn't - either way it stops the right labels from being drawn).My workaround for this was to only perform the projection if the gridliner CRS != axes CRS. This gives me the right labels, but I'm still missing the rightmost longitude label:
This is due to precision error when
set_extent
projects the extent values:In this case there's precision error transforming between the 0 CRS and the 132 CRS.
The longitude gridlines now correctly span -180 to 180, but because the right-hand map boundary is less than 180, the longitude gridline doesn't intersect with the map
cartopy/lib/cartopy/mpl/gridliner.py
Line 534 in 4ca93c1
so the label doesn't get drawn. The solution to this has been to set xlim and ylim manually (
set_global
also works provided you want 90 south to 90 north):With that said, thanks for working on Cartopy. Besides the odd issue here and there, it's been really great to use.
Code to reproduce
Operating system
Ubuntu 18.04
Cartopy version
0.18, Python 3.7.9
pip list
The text was updated successfully, but these errors were encountered: