-
Notifications
You must be signed in to change notification settings - Fork 359
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
contourf fails with lat/lon coordinates and transform for Stereographic projection but works correctly with projection coordinates #2312
Comments
Hello @guziy, thanks for the report and the reproducing code. Unfortunately pickle files are not portable across python environments, so it is unlikely that we will be able to run the reproducing example as-is. Could you save in some other format? NetCDF should be fine if you are used to using that. It would also be useful to know what versions of other packages you are using, particularly shapely and matplotlib. I note that the error is being raised in shapely. |
Here are the versions of matplotlib and shapely:
I've updated the code and uploaded the input netcdf file. |
Thanks @guziy I confirm I have reproduced the error with our |
The specific error here is caused by this line Line 1210 in 97c6a64
It seems that adding a zero buffer to a Polygon can create a MultiPolygon .
I tried this diff --git a/lib/cartopy/crs.py b/lib/cartopy/crs.py
index ba505dab..1c6c7f2d 100644
--- a/lib/cartopy/crs.py
+++ b/lib/cartopy/crs.py
@@ -1226,7 +1226,11 @@ class Projection(CRS, metaclass=ABCMeta):
polygon = boundary_poly.intersection(polygon)
if not polygon.is_empty:
- polygon_bits.append(polygon)
+ if isinstance(polygon, sgeom.MultiPolygon):
+ polygon_bits.extend(polygon.geoms)
+ print('multipoly')
+ else:
+ polygon_bits.append(polygon)
if polygon_bits:
multi_poly = sgeom.MultiPolygon(polygon_bits) which does get us past the error. However the plot that comes out looks like when it should look more like So my patch appears to treat one symptom rather than the cause of the problem. |
Description
I am trying to plot a field on a stereographic projection with contourf. The contourf fails if lat/lon are provided along with the transformation. It seems to be working if I project the coordinates first and pass the projected coordinates to contourf. If I convert the data array into a plain numpy array contourf does not fail but the plot is wrong.
Below I provide the input file along with the code to reproduce the problem.
Code to reproduce
input file 2024010400-dump.nc.zip
Traceback
Full environment definition
Operating system
Linux
Cartopy version
0.21.1
conda list
pip list
The text was updated successfully, but these errors were encountered: