-
Notifications
You must be signed in to change notification settings - Fork 416
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
Quick patch to bypass scale validation in new Cartopy #1371
Conversation
This pull request introduces 1 alert when merging a4aeb54 into c3df3bc - view on LGTM.com new alerts:
|
Investigating the test failures has led to the following:
|
Okay, as best as I can figure out at this point, it seems to be something with the Cartopy 0.18 update related to I also drafted some test code and if you don't set a projection, the clip_on setting works, once you add a projection then it no longer clips. Testing this same code on Cartopy 0.17 works for both instances. So it appears to be Cartopy, but not absolutely sure what or where this is being caused. import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from metpy.plots import StationPlot
import numpy as np
lat = np.linspace(40, 30, 11)
lon = np.linspace(-90, -80, 11)
lon, lat = np.meshgrid(lon, lat)
T = np.ones(lon.shape)*25
# Create the figure and an axes set to the projection.
fig = plt.figure(figsize=(8, 8))
ax = fig.add_subplot(1, 1, 1)
#ax.set_extent([-88, -86, 32, 38])
ax.set_xlim(-88, -84)
stationplot = StationPlot(ax, lon.ravel(), lat.ravel(), fontsize=10, clip_on=True)
stationplot.plot_parameter('C', T.ravel()) And now adding a projection and making it a GeoAxes... # Create the figure and an axes set to the projection.
fig = plt.figure(figsize=(8, 8))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
#ax.set_extent([-88, -86, 32, 38])
ax.set_xlim(-88, -84)
stationplot = StationPlot(ax, lon.ravel(), lat.ravel(), fontsize=10, clip_on=True)
stationplot.plot_parameter('C', T.ravel()) |
Okay, I've continued digging and not found much, but here is a summary of what I have found/tried... Clearly we are able to clip appropriately when not using a Geo-referenced Axes, so MetPy and Matplotlib are working okay together. It also seems like clipping happens okay with geo-referenced axes when there is a wrapped Matplotlib function in Cartopy (read: contour, contourf, barbs, etc.), but not for the |
@kgoebber Thank you for digging into this and investigating! It's a lot more than I've been able to do. At this point, does the "fix" have to come down to pinning v0.12.2 to Cartopy <=0.17? I've had this issue come up a few times with supporting people, so it would be great to have at least some form of a resolution ASAP. |
This fix will allow things to work with Cartopy 0.18 - the only user issue would be if they are wanting to plot surface observations - they won't clip properly, which is really a different issue from this one. So if we are okay committing over CI failures (which are all just image issues within this PR; some resulting from this change, others unrelated (e.g., clipping issues)), then this works just fine with Cartopy 0.18. |
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.
Overcomes import hurdles when using Cartopy 0.18. This quick fix gets the job done for that. There are still other Cartopy 0.18 issues. We should update the test images for the ones that change as the result of the updated adaptive scaler and gridline issues.
I found a work around for the clipping! The clipbox attribute was not being set correctly (or unset?), but the bbox that was created in Adding the following code at line 105 in # Update the clipbox based on bbox
text_obj.clipbox = self.bbox |
Good find @kgoebber. So the chain is that, as noted in SciTools/cartopy#1526, after SciTools/cartopy#1422 the default patch is a bit more complicated; most importantly it is not an instance of breathes So I think the clipping issue is actually a bug in matplotlib that has been made a problem for us by changes in CartoPy. I think we can do something like @kgoebber notes above until the bug is fixed in matplotlib. |
Closing in favor of @dopplershift's #1372. |
Description Of Changes
Quick patch of the
__init__
method ofMetPyMapFeature
to fix the breakage caused by the scale validation added in Cartopy 0.18 toNaturalEarthFeature
. Not a long term fix, since it assumes an exact set of attributes forNaturalEarthFeature
and particular behavior ofNaturalEarthFeature
's parent classFeature
. A more robust fix will be discussed for 1.0 in #1368 / #1370.