-
Notifications
You must be signed in to change notification settings - Fork 364
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
potential bug: regression in cartopy 0.19 ? #1955
Comments
Does this work if you remove the CartoPy projections and use plain matplotlib? |
yes. import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
data = np.random.random_sample((10, 10))
fig = plt.figure()
ax = fig.add_axes((0, 0, 1, 1))
cax = fig.add_axes((1, 1, 1, 1))
im = ax.imshow(
data,
extent=[-180.0, 180.0, -90.0, 90.0],
norm=LogNorm(),
)
cb = fig.colorbar(im, cax=cax)
fig.savefig("/tmp/demo.png") |
I'd say definitely a bug in cartopy then. |
My guess is that this is because the reprojection of the image fails and produces an all-masked result. If this is only a test, then you probably want to change |
I think there might be several things going on here
If anyone could try out my script with an older version of cartopy that doesn't crash and post the image it would be helpful.
Indeed, if we remove the
ok this part is probably a bug in yt, because the extent are not user-defined as in my minimal reproducer script. What's user-specified is a str |
Unfortunately, I purposefully decided to change the projection coordinates on some projections because they were using non-sensical globes to make the numbers closer to pseudo-lat/lon (of which, Miller appears to be one of those). Thanks, Ruth! I think that image will actually be different in v0.20 too due to another change in image interpolation that turns those "waves" into straight lines now. Removing the geocentric pivot in this commit: 017f989 So, indeed @neutrinoceros, you hit multiple breaking changes here, sorry about that! |
That's okay ! I'd be happy to declare cartopy 0.20 as the new minimal compatible version. I may need assistance to perform the necessary changes there however. |
@greglucas I confirm that the Actually we're imitating a user asking for a Is there a more suited default I can associate with the Miller transform, and in general, is there any way to determine a compatible projection at runtime, given a transform ? |
I'm not exactly clear what the data_projection vs data_transform is in yt... Is data_projection, what the MPL Axes are in, or is there a secondary pivot/transform somewhere along the path? I don't know where your original test was failing, because for the reproducer here I think the key is ax = plt.axes(..., transform=ccrs.Miller())
ax.set_global()
ax.get_extent() |
correct !
not that I can tell
It's effectively what happens in our test but it's pretty hard to track down where these values are coming from. I won't go too much into the details but it's not from the test suite, it's definitely in the code base itself. Unfortunately the reason why the code is disabled is only vaguely documented:
But I think that there's a good chance that the patch we need has to be happen here (and possibly nowhere else). attempt 1: determine extent dynamically as suggestedself.axes.set_global()
extent = self.axes.get_extent() attempt 2: reactivating the commented codeself.axes.set_extent(extent) The following error is logged a few dozen times
Both patches still lead to the original error |
That comment has a few interesting tidbits. The kdtree to produce inf's is essentially what I think is going on here, except now it is nan's/masked everywhere for the small domain instead of inf's, which is what is causing issues with your LogNorm scaling. Also, the comment in that code seems related to this issue here of when the extent gets updated: #1468 so we should look into that some more on Cartopy's side as well. The extent should be defined in the |
Thank you so much for your insight ! For reference, I've proposed a patch on the yt side base on your reply here yt-project/yt#3708 |
The yt patch has been merged, I don't think there's anything left to do here. |
Description
yt's test suite exercises a couple test cases using cartopy. Since August yt has been pinning cartopy to 0.18 to mitigate some compatibility issues while #1140 was being worked on.
Now that the original problem seems to be fixed on your side, I've allowed more recent cartopy versions to install, and discovered that one of our tests is now broken. See downstream issue yt-project/yt#3705
See bellow for a reproducer that doesn't use yt.
I'm very open to considering that we're doing something wrong here and that this script shouldn't work, which would imply that the bug is actually on the yt side, but given my limited understanding of it, I wanted to check in with cartopy devs first.
Code to reproduce
Traceback
Full environment definition
Operating system
I'm seeing this both on Windows (on CI) and MacOS
Cartopy version
0.20.1
I think I saw it too in 0.19.0.post1 but I've lost track of it and I can't easily install this version on my machine.
conda list
pip list
The text was updated successfully, but these errors were encountered: