Skip to content
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

stock_img() fails with scipy 1.11 #2212

Closed
brian-rose opened this issue Jul 12, 2023 · 1 comment
Closed

stock_img() fails with scipy 1.11 #2212

brian-rose opened this issue Jul 12, 2023 · 1 comment

Comments

@brian-rose
Copy link

Description

Calling ax.stock_img() on a GeoAxes object fails in an environment with scipy 1.11.1 and Cartopy 0.21.1

The same code works as expected in an environment with scipy 1.10.1 and Cartopy 0.21.1.

Code to reproduce

import matplotlib.pyplot as plt
from cartopy import crs as ccrs
fig = plt.figure(figsize=(11, 8.5))
ax = plt.subplot(1, 1, 1, projection=ccrs.Mollweide(central_longitude=0))
ax.stock_img()

Traceback

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[1], line 5
      3 fig = plt.figure(figsize=(11, 8.5))
      4 ax = plt.subplot(1, 1, 1, projection=ccrs.Mollweide(central_longitude=0))
----> 5 ax.stock_img()

File ~/miniconda3/envs/test-cartopy/lib/python3.11/site-packages/cartopy/mpl/geoaxes.py:1019, in GeoAxes.stock_img(self, name)
   1014     source_proj = ccrs.PlateCarree()
   1015     fname = os.path.join(config["repo_data_dir"],
   1016                          'raster', 'natural_earth',
   1017                          '50-natural-earth-1-downsampled.png')
-> 1019     return self.imshow(imread(fname), origin='upper',
   1020                        transform=source_proj,
   1021                        extent=[-180, 180, -90, 90])
   1022 else:
   1023     raise ValueError('Unknown stock image %r.' % name)

File ~/miniconda3/envs/test-cartopy/lib/python3.11/site-packages/cartopy/mpl/geoaxes.py:318, in _add_transform.<locals>.wrapper(self, *args, **kwargs)
    313     raise ValueError(f'Invalid transform: Spherical {func.__name__} '
    314                      'is not supported - consider using '
    315                      'PlateCarree/RotatedPole.')
    317 kwargs['transform'] = transform
--> 318 return func(self, *args, **kwargs)

File ~/miniconda3/envs/test-cartopy/lib/python3.11/site-packages/cartopy/mpl/geoaxes.py:1331, in GeoAxes.imshow(self, img, *args, **kwargs)
   1329 from cartopy.img_transform import warp_array
   1330 original_extent = extent
-> 1331 img, extent = warp_array(img,
   1332                          source_proj=transform,
   1333                          source_extent=original_extent,
   1334                          target_proj=self.projection,
   1335                          target_res=regrid_shape,
   1336                          target_extent=target_extent,
   1337                          mask_extrapolated=True,
   1338                          )
   1339 alpha = kwargs.pop('alpha', None)
   1340 if np.array(alpha).ndim == 2:

File ~/miniconda3/envs/test-cartopy/lib/python3.11/site-packages/cartopy/img_transform.py:192, in warp_array(array, target_proj, source_proj, target_res, source_extent, target_extent, mask_extrapolated)
    186 # XXX Take into account the extents of the original to determine
    187 # target_extents?
    188 target_native_x, target_native_y, extent = mesh_projection(
    189     target_proj, target_res[0], target_res[1],
    190     x_extents=target_x_extents, y_extents=target_y_extents)
--> 192 array = regrid(array, source_native_xy[0], source_native_xy[1],
    193                source_proj, target_proj,
    194                target_native_x, target_native_y,
    195                mask_extrapolated)
    196 return array, extent

File ~/miniconda3/envs/test-cartopy/lib/python3.11/site-packages/cartopy/img_transform.py:278, in regrid(array, source_x_coords, source_y_coords, source_proj, target_proj, target_x_points, target_y_points, mask_extrapolated)
    274 else:
    275     # Versions of scipy >= v0.16 added the balanced_tree argument,
    276     # which caused the KDTree to hang with this input.
    277     kdtree = scipy.spatial.cKDTree(xyz, balanced_tree=False)
--> 278     _, indices = kdtree.query(target_xyz, k=1)
    279 mask = indices >= len(xyz)
    280 indices[mask] = 0

File _ckdtree.pyx:795, in scipy.spatial._ckdtree.cKDTree.query()

ValueError: 'x' must be finite, check for nan or inf values

Full environment definition

Operating system

Mac OS Monterey Version 12.6.7

Cartopy version

0.21.1

conda list

# packages in environment at /Users/br546577/miniconda3/envs/test-cartopy:
#
# Name                    Version                   Build  Channel
anyio                     3.7.1              pyhd8ed1ab_0    conda-forge
appnope                   0.1.3              pyhd8ed1ab_0    conda-forge
argon2-cffi               21.3.0             pyhd8ed1ab_0    conda-forge
argon2-cffi-bindings      21.2.0          py311he2be06e_3    conda-forge
asttokens                 2.2.1              pyhd8ed1ab_0    conda-forge
attrs                     23.1.0             pyh71513ae_1    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                pyhd8ed1ab_3    conda-forge
backports.functools_lru_cache 1.6.5              pyhd8ed1ab_0    conda-forge
beautifulsoup4            4.12.2             pyha770c72_0    conda-forge
bleach                    6.0.0              pyhd8ed1ab_0    conda-forge
brotli                    1.0.9                h1a8c8d9_9    conda-forge
brotli-bin                1.0.9                h1a8c8d9_9    conda-forge
brotli-python             1.0.9           py311ha397e9f_9    conda-forge
bzip2                     1.0.8                h3422bc3_4    conda-forge
c-ares                    1.19.1               hb547adb_0    conda-forge
ca-certificates           2023.5.7             hf0a4a13_0    conda-forge
cartopy                   0.21.1          py311hbf64cf6_1    conda-forge
certifi                   2023.5.7           pyhd8ed1ab_0    conda-forge
cffi                      1.15.1          py311hae827db_3    conda-forge
charset-normalizer        3.2.0              pyhd8ed1ab_0    conda-forge
comm                      0.1.3              pyhd8ed1ab_0    conda-forge
contourpy                 1.1.0           py311he4fd1f5_0    conda-forge
cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
debugpy                   1.6.7           py311ha397e9f_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
entrypoints               0.4                pyhd8ed1ab_0    conda-forge
exceptiongroup            1.1.2              pyhd8ed1ab_0    conda-forge
executing                 1.2.0              pyhd8ed1ab_0    conda-forge
flit-core                 3.9.0              pyhd8ed1ab_0    conda-forge
fonttools                 4.40.0          py311heffc1b2_0    conda-forge
freetype                  2.12.1               hd633e50_1    conda-forge
geos                      3.11.2               hb7217d7_0    conda-forge
idna                      3.4                pyhd8ed1ab_0    conda-forge
importlib-metadata        6.8.0              pyha770c72_0    conda-forge
importlib_metadata        6.8.0                hd8ed1ab_0    conda-forge
importlib_resources       6.0.0              pyhd8ed1ab_1    conda-forge
ipykernel                 6.24.0             pyh5fb750a_0    conda-forge
ipython                   8.14.0             pyhd1c38e8_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                8.0.7              pyhd8ed1ab_0    conda-forge
jedi                      0.18.2             pyhd8ed1ab_0    conda-forge
jinja2                    3.1.2              pyhd8ed1ab_1    conda-forge
jsonschema                4.18.1             pyhd8ed1ab_0    conda-forge
jsonschema-specifications 2023.6.1           pyhd8ed1ab_0    conda-forge
jupyter                   1.0.0           py311h267d04e_8    conda-forge
jupyter_client            8.3.0              pyhd8ed1ab_0    conda-forge
jupyter_console           6.6.3              pyhd8ed1ab_0    conda-forge
jupyter_core              5.3.1           py311h267d04e_0    conda-forge
jupyter_events            0.6.3              pyhd8ed1ab_0    conda-forge
jupyter_server            2.7.0              pyhd8ed1ab_0    conda-forge
jupyter_server_terminals  0.4.4              pyhd8ed1ab_1    conda-forge
jupyterlab_pygments       0.2.2              pyhd8ed1ab_0    conda-forge
jupyterlab_widgets        3.0.8              pyhd8ed1ab_0    conda-forge
kiwisolver                1.4.4           py311hd6ee22a_1    conda-forge
krb5                      1.20.1               h69eda48_0    conda-forge
lcms2                     2.15                 hd835a16_1    conda-forge
lerc                      4.0.0                h9a09cb3_0    conda-forge
libblas                   3.9.0           17_osxarm64_openblas    conda-forge
libbrotlicommon           1.0.9                h1a8c8d9_9    conda-forge
libbrotlidec              1.0.9                h1a8c8d9_9    conda-forge
libbrotlienc              1.0.9                h1a8c8d9_9    conda-forge
libcblas                  3.9.0           17_osxarm64_openblas    conda-forge
libcurl                   8.1.2                h912dcd9_0    conda-forge
libcxx                    16.0.6               h4653b0c_0    conda-forge
libdeflate                1.18                 h1a8c8d9_0    conda-forge
libedit                   3.1.20191231         hc8eb9b7_2    conda-forge
libev                     4.33                 h642e427_1    conda-forge
libexpat                  2.5.0                hb7217d7_1    conda-forge
libffi                    3.4.2                h3422bc3_5    conda-forge
libgfortran               5.0.0           12_2_0_hd922786_31    conda-forge
libgfortran5              12.2.0              h0eea778_31    conda-forge
libjpeg-turbo             2.1.5.1              h1a8c8d9_0    conda-forge
liblapack                 3.9.0           17_osxarm64_openblas    conda-forge
libnghttp2                1.52.0               hae82a92_0    conda-forge
libopenblas               0.3.23          openmp_hc731615_0    conda-forge
libpng                    1.6.39               h76d750c_0    conda-forge
libsodium                 1.0.18               h27ca646_1    conda-forge
libsqlite                 3.42.0               hb31c410_0    conda-forge
libssh2                   1.11.0               h7a5bd25_0    conda-forge
libtiff                   4.5.1                h23a1a89_0    conda-forge
libwebp-base              1.3.1                hb547adb_0    conda-forge
libxcb                    1.15                 hf346824_0    conda-forge
libzlib                   1.2.13               h53f4e23_5    conda-forge
llvm-openmp               16.0.6               h1c12783_0    conda-forge
markupsafe                2.1.3           py311heffc1b2_0    conda-forge
matplotlib-base           3.7.2           py311h3bc9839_0    conda-forge
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
mistune                   3.0.0              pyhd8ed1ab_0    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
nbclassic                 1.0.0              pyhb4ecaf3_1    conda-forge
nbclient                  0.8.0              pyhd8ed1ab_0    conda-forge
nbconvert                 7.6.0              pyhd8ed1ab_0    conda-forge
nbconvert-core            7.6.0              pyhd8ed1ab_0    conda-forge
nbconvert-pandoc          7.6.0              pyhd8ed1ab_0    conda-forge
nbformat                  5.9.1              pyhd8ed1ab_0    conda-forge
ncurses                   6.4                  h7ea286d_0    conda-forge
nest-asyncio              1.5.6              pyhd8ed1ab_0    conda-forge
notebook                  6.5.4              pyha770c72_0    conda-forge
notebook-shim             0.2.3              pyhd8ed1ab_0    conda-forge
numpy                     1.25.1          py311hb8f3215_0    conda-forge
openjpeg                  2.5.0                hbc2ba62_2    conda-forge
openssl                   3.1.1                h53f4e23_1    conda-forge
overrides                 7.3.1              pyhd8ed1ab_0    conda-forge
packaging                 23.1               pyhd8ed1ab_0    conda-forge
pandoc                    3.1.3                hce30654_0    conda-forge
pandocfilters             1.5.0              pyhd8ed1ab_0    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
pexpect                   4.8.0              pyh1a96a4e_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    10.0.0          py311h095fde6_0    conda-forge
pip                       23.1.2             pyhd8ed1ab_0    conda-forge
pkgutil-resolve-name      1.3.10             pyhd8ed1ab_0    conda-forge
platformdirs              3.8.1              pyhd8ed1ab_0    conda-forge
pooch                     1.7.0              pyha770c72_3    conda-forge
proj                      9.2.1                h8fdea58_0    conda-forge
prometheus_client         0.17.1             pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.39             pyha770c72_0    conda-forge
prompt_toolkit            3.0.39               hd8ed1ab_0    conda-forge
psutil                    5.9.5           py311he2be06e_0    conda-forge
pthread-stubs             0.4               h27ca646_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pygments                  2.15.1             pyhd8ed1ab_0    conda-forge
pyobjc-core               9.2             py311hb702dc4_0    conda-forge
pyobjc-framework-cocoa    9.2             py311hb702dc4_0    conda-forge
pyparsing                 3.0.9              pyhd8ed1ab_0    conda-forge
pyproj                    3.6.0           py311h280d66e_1    conda-forge
pyshp                     2.3.1              pyhd8ed1ab_0    conda-forge
pysocks                   1.7.1              pyha2e5f31_6    conda-forge
python                    3.11.4          h47c9636_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-fastjsonschema     2.17.1             pyhd8ed1ab_0    conda-forge
python-json-logger        2.0.7              pyhd8ed1ab_0    conda-forge
python_abi                3.11                    3_cp311    conda-forge
pyyaml                    6.0             py311he2be06e_5    conda-forge
pyzmq                     25.1.0          py311hb1af645_0    conda-forge
readline                  8.2                  h92ec313_1    conda-forge
referencing               0.29.1             pyhd8ed1ab_0    conda-forge
requests                  2.31.0             pyhd8ed1ab_0    conda-forge
rfc3339-validator         0.1.4              pyhd8ed1ab_0    conda-forge
rfc3986-validator         0.1.1              pyh9f0ad1d_0    conda-forge
rpds-py                   0.8.10          py311h0563b04_0    conda-forge
scipy                     1.11.1          py311h93d07a4_0    conda-forge
send2trash                1.8.2              pyhd1c38e8_0    conda-forge
setuptools                68.0.0             pyhd8ed1ab_0    conda-forge
shapely                   2.0.1           py311h7f8cfc4_1    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
sniffio                   1.3.0              pyhd8ed1ab_0    conda-forge
soupsieve                 2.3.2.post1        pyhd8ed1ab_0    conda-forge
sqlite                    3.42.0               h203b68d_0    conda-forge
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
terminado                 0.17.1             pyhd1c38e8_0    conda-forge
tinycss2                  1.2.1              pyhd8ed1ab_0    conda-forge
tk                        8.6.12               he1e0b03_0    conda-forge
tornado                   6.3.2           py311heffc1b2_0    conda-forge
traitlets                 5.9.0              pyhd8ed1ab_0    conda-forge
typing-extensions         4.7.1                hd8ed1ab_0    conda-forge
typing_extensions         4.7.1              pyha770c72_0    conda-forge
typing_utils              0.1.0              pyhd8ed1ab_0    conda-forge
tzdata                    2023c                h71feb2d_0    conda-forge
urllib3                   2.0.3              pyhd8ed1ab_1    conda-forge
wcwidth                   0.2.6              pyhd8ed1ab_0    conda-forge
webencodings              0.5.1                      py_1    conda-forge
websocket-client          1.6.1              pyhd8ed1ab_0    conda-forge
wheel                     0.40.0             pyhd8ed1ab_0    conda-forge
widgetsnbextension        4.0.8              pyhd8ed1ab_0    conda-forge
xorg-libxau               1.0.11               hb547adb_0    conda-forge
xorg-libxdmcp             1.1.3                h27ca646_0    conda-forge
xz                        5.2.6                h57fd34a_0    conda-forge
yaml                      0.2.5                h3422bc3_2    conda-forge
zeromq                    4.3.4                hbdafb3b_1    conda-forge
zipp                      3.16.0             pyhd8ed1ab_1    conda-forge
zstd                      1.5.2                h4f39d0f_7    conda-forge

pip list

Package                       Version
----------------------------- -----------
anyio                         3.7.1
appnope                       0.1.3
argon2-cffi                   21.3.0
argon2-cffi-bindings          21.2.0
asttokens                     2.2.1
attrs                         23.1.0
backcall                      0.2.0
backports.functools-lru-cache 1.6.5
beautifulsoup4                4.12.2
bleach                        6.0.0
Brotli                        1.0.9
Cartopy                       0.21.1
certifi                       2023.5.7
cffi                          1.15.1
charset-normalizer            3.2.0
comm                          0.1.3
contourpy                     1.1.0
cycler                        0.11.0
debugpy                       1.6.7
decorator                     5.1.1
defusedxml                    0.7.1
entrypoints                   0.4
exceptiongroup                1.1.2
executing                     1.2.0
fastjsonschema                2.17.1
flit_core                     3.9.0
fonttools                     4.40.0
idna                          3.4
importlib-metadata            6.8.0
importlib-resources           6.0.0
ipykernel                     6.24.0
ipython                       8.14.0
ipython-genutils              0.2.0
ipywidgets                    8.0.7
jedi                          0.18.2
Jinja2                        3.1.2
jsonschema                    4.18.1
jsonschema-specifications     2023.6.1
jupyter                       1.0.0
jupyter_client                8.3.0
jupyter-console               6.6.3
jupyter_core                  5.3.1
jupyter-events                0.6.3
jupyter_server                2.7.0
jupyter_server_terminals      0.4.4
jupyterlab-pygments           0.2.2
jupyterlab-widgets            3.0.8
kiwisolver                    1.4.4
MarkupSafe                    2.1.3
matplotlib                    3.7.2
matplotlib-inline             0.1.6
mistune                       3.0.0
munkres                       1.1.4
nbclassic                     1.0.0
nbclient                      0.8.0
nbconvert                     7.6.0
nbformat                      5.9.1
nest-asyncio                  1.5.6
notebook                      6.5.4
notebook_shim                 0.2.3
numpy                         1.25.1
overrides                     7.3.1
packaging                     23.1
pandocfilters                 1.5.0
parso                         0.8.3
pexpect                       4.8.0
pickleshare                   0.7.5
Pillow                        10.0.0
pip                           23.1.2
pkgutil_resolve_name          1.3.10
platformdirs                  3.8.1
pooch                         1.7.0
prometheus-client             0.17.1
prompt-toolkit                3.0.39
psutil                        5.9.5
ptyprocess                    0.7.0
pure-eval                     0.2.2
pycparser                     2.21
Pygments                      2.15.1
pyobjc-core                   9.2
pyobjc-framework-Cocoa        9.2
pyparsing                     3.0.9
pyproj                        3.6.0
pyshp                         2.3.1
PySocks                       1.7.1
python-dateutil               2.8.2
python-json-logger            2.0.7
PyYAML                        6.0
pyzmq                         25.1.0
referencing                   0.29.1
requests                      2.31.0
rfc3339-validator             0.1.4
rfc3986-validator             0.1.1
rpds-py                       0.8.10
scipy                         1.11.1
Send2Trash                    1.8.2
setuptools                    68.0.0
shapely                       2.0.1
six                           1.16.0
sniffio                       1.3.0
soupsieve                     2.3.2.post1
stack-data                    0.6.2
terminado                     0.17.1
tinycss2                      1.2.1
tornado                       6.3.2
traitlets                     5.9.0
typing_extensions             4.7.1
typing-utils                  0.1.0
urllib3                       2.0.3
wcwidth                       0.2.6
webencodings                  0.5.1
websocket-client              1.6.1
wheel                         0.40.0
widgetsnbextension            4.0.8
zipp                          3.16.0
@greglucas
Copy link
Contributor

Duplicate of #2199 which does have a PR linked to fix it. The underlying issue is with scipy so if you downgrade that package or install pykdtree it should work again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants