-
Notifications
You must be signed in to change notification settings - Fork 24
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 plotting issues by mapping from lon/lat manually #14
Conversation
A number of plotting problems are fixed by first mapping coordinates from lon/lat to projection coordinates and then plotting, rather than using the latlon argument to the basemap plot routine. Added some output so users are aware of what is being plotted and get a sense of how long it will take.
I tested the plotting on two ocean basins (Arctic and Southern ocean), one Greenland and one Antarctic land-ice basin, and one ice-shelf basin: The plots now appear to be consistent with one another and with the plots of the individual regions on GitHub: |
@pwolfram, let me know if these fixes also work for you. I only tested the default 4 and the new 5 projections (so there are still 8 I didn't test). |
@xylar, thanks for figuring out the solution. I was surprised this was a simple solution and looked into it further. This appears to be an unanticipated side-effect of https://github.com/matplotlib/basemap/blob/master/lib/mpl_toolkits/basemap/__init__.py#L510. The coordinates are being shifted for the option Using your target regions listed above, here is the test for The plots are not quite working correctly if the points are outside the map, but do work if they are contained within the map (e.g., https://github.com/MPAS-Dev/geometric_features/blob/master/landice/region/southGreenland1/region.geojson). The test for The results plotted appear to be quite reasonable, with the exception of the Rhone_1 region on the |
Fix plotting issues by mapping from lon/lat manually This resolves an unanticipated side-effect of https://github.com/matplotlib/basemap/blob/master/lib/mpl_toolkits/basemap/__init__.py#L510. The coordinates are also being shifted for the option latlon=True before they are converted to map coordinates, viz https://github.com/matplotlib/basemap/blob/master/lib/mpl_toolkits/basemap/__init__.py#L543. It removes strange plotting errors that occur using standard basemap plotting with the latlon=True option. The fix produces reasonable plots for standard plot type options, e.g., `['mill2','mill', 'northpole', 'southpole']` with demonstrated success for the following regions: https://github.com/MPAS-Dev/geometric_features/blob/master/ocean/region/Arctic_Ocean/region.geojson https://github.com/MPAS-Dev/geometric_features/blob/master/ocean/region/Southern_Ocean/region.geojson https://github.com/MPAS-Dev/geometric_features/blob/master/landice/region/Antarctica_IMBIE2/region.geojson https://github.com/MPAS-Dev/geometric_features/blob/master/landice/region/southGreenland1/region.geojson https://github.com/MPAS-Dev/geometric_features/blob/master/iceshelves/region/Ronne_1/region.geojson
@xylar, as you may have surmised I cannot delete your branch either... thanks for the really clean solution here. |
@pwolfram, thanks for reviewing this. It seems there's still some work to do. By the way, do you know why are the 'europe' and 'northamerica' plots named in that way? It seems like the 'europe' plot shows the Americas and the 'northamerica' plot shows Asia and the Indian Ocean. |
@pwolfram, by the way, I do think there's a bug in shiftdata. It tries to find the second biggest jump between longitudes and use that as a threshold for determining where the jump in longitude happens: When I get a chance, I'll put together a simpler example that reproduces the problem and file a bug report. |
@pwolfram, this seems to be a known issue that you have also commented on: matplotlib/basemap#126 It seems like latlon=True is only useful for longitude data that is monotonic (except that it's periodic), which is obviously not the case for our polygons. |
I don't know how important it is to you to be able to plot geometries on arbitrary maps, but you may be interested in cartopy, whose bread-and-butter is geometry transformations of this kind (e.g. http://scitools.org.uk/cartopy/docs/latest/examples/rotated_pole.html). For sure Basemap is more mature as a package, but Cartopy takes the approach you've taken here @xylar, in that it is cartopy's responsibility to transform the coordinates, not the user. This means it has all of the context it needs to understand datelines, poles etc. Anyway, nice plots! 👍 |
@pelson, Thank for the tip. I had heard of cartopy but haven't used it before. It sounds like that's what we should have been using from the start. I'll look into it further. |
Our colleagues @milenaveneziani and @akturner have been using it for their global ocean / sea-ice analysis metrics and I think they have found it useful. |
A number of plotting problems are fixed by first mapping coordinates
from lon/lat to projection coordinates and then plotting, rather than
using the latlon argument to the basemap plot routine.
Added some output so users are aware of what is being plotted and
get a sense of how long it will take.