-
Notifications
You must be signed in to change notification settings - Fork 368
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: Invalid Polygon from Contouring #2463
base: main
Are you sure you want to change the base?
Conversation
Hi @Clarmy, thanks for updating here and sorry it has taken me a while to look at this. I was just playing with the branch and found that the new tests do not fail for me against I do not know what change would have made the difference. We have obviously made changes in this area but none of them specifically targeted that error. I am also looking at different versions of Shapely (2.0.4 to 2.0.6) and Pyproj (3.6.1 to 3.7.0) so possibly something changed outside of Cartopy to fix this. |
@rcomer Yes, it still fails when I test with import numpy as np
import cartopy
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
print(f"cartopy version: {cartopy.__version__}")
def test_contourf_with_conflict_points():
"""Testing the issue mentioned in #2370"""
lons = [96.75, 97.0, 97.25]
lats = np.arange(17.25, 15.9, -0.25)
lons, lats = np.meshgrid(lons, lats)
data = [
[26.9, 43.7, 26.8],
[33.2, 65.8, 34.6],
[54.7, 66.9, 55.5],
[65.3, 65.0, 65.7],
[65.9, 65.0, 65.6],
[65.8, 65.2, 65.5],
]
fig = plt.figure()
ax = fig.add_subplot(projection=ccrs.Mercator())
ax.contourf(lons, lats, data, levels=[60, 65], transform=ccrs.PlateCarree())
if __name__ == "__main__":
test_contourf_with_conflict_points() |
@rcomer I created a brand new python=3.10 virtual environment using conda, and only installed the latest version of cartopy==0.24.1 released on pip (without installing any other packages). Then I ran the code directly, and this is the error that occurred. Were your tests based on the code from the main branch rather than the most recent release package on PyPI? |
Could you please follow these steps to see if you can reproduce the error I encountered: $ conda create -n py312 python=3.12 -y
$ conda activate py312
$ pip install -U cartopy
$ python test.py Here, |
@rcomer Or, I think there's an even more convincing way to test this: add |
Good idea to use the CI. I made this change so I can test within my fork, and the test fails for every setup. However, that test passes for me locally with the conda environment I created from the conda yml. I am very confused. |
I have confirmed that if I install Cartopy with
I do not get the error. |
When installing from conda, I get geos version 3.13 which only came out in September. If I go again with
I reproduce the error. So it seems like the latest geos did something to fix this. The only other difference I see in the two environments is I get a different shapely build. conda-forge tends to rebuild things independently of package maintainers, whereas pypi only has what maintainers build when the package is released. |
@rcomer Thank you for your testing. Indeed, it seems that the error disappeared when I used |
Shapely depends on GEOS, and it installs a pre-compiled GEOS wheel during its installation. If the version of GEOS that Shapely is built against could be updated to 3.13, the issue might be resolved. |
I just took a closer look at the installation section of the Shapely documentation. It mentions that if users want to customize the version of the GEOS package, they can install their preferred version of GEOS and then use |
While reading through the Shapely code repository, I found their GEOS version definition for the build process: here. Indeed, they are building against version 3.12. So, I submitted a PR to GEOS to upgrade the GEOS version number: shapely/shapely#2187 this PR is merged, then we might only need to adjust the version requirement for Shapely in Cartopy to fix the issue. |
Rationale
Resolve the issue mentioned in #2370
New PR from #2373
Implications
This change will affect the behavior of contourf and essentially fixes a bug in the contourf function.