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

fetch_tile returns different size images #2268

Closed
AdamTheisen opened this issue Oct 9, 2023 · 2 comments · Fixed by #2269
Closed

fetch_tile returns different size images #2268

AdamTheisen opened this issue Oct 9, 2023 · 2 comments · Fixed by #2269
Milestone

Comments

@AdamTheisen
Copy link

Description

The images returned in fetch_tile (L74, img_tiles.py) are not the same size at times which causes _merge_tiles to error out on line 646. In testing, this happens when a tile is of size 512x512 and the other tiles are 256x256. Note, that this doesn't happen all the time and is dependent on the fetched tiles. The code below reproduces it about once every 3-4 tries. Note, we are also seeing this failure in our CI for act-atmos in that it's randomly failing and not consistent.

Code to reproduce

import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.io.img_tiles import Stamen
import matplotlib.pyplot as plt

# Set projection and lat/lon extent
projection = ccrs.PlateCarree()
ax = plt.axes(projection=projection)
plt.subplots_adjust(left=0.01, right=0.99, bottom=0.05, top=0.93)
ax.set_extent([-65.38219661712647, -63.99097232818603, -33.219947052001956, -31.828722763061524], crs=projection)

# Set up tiles
tiler = Stamen('terrain')
ax.add_image(tiler, 8)

plt.show()

Traceback

Traceback (most recent call last):
  File "/opt/anaconda3/lib/python3.11/site-packages/matplotlib/backend_bases.py", line 1226, in _on_timer
    ret = func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/lib/python3.11/site-packages/matplotlib/backends/backend_macosx.py", line 68, in callback_func
    callback()
  File "/opt/anaconda3/lib/python3.11/site-packages/matplotlib/backends/backend_macosx.py", line 88, in _draw_idle
    self.draw()
  File "/opt/anaconda3/lib/python3.11/site-packages/matplotlib/backends/backend_macosx.py", line 50, in draw
    super().draw()
  File "/opt/anaconda3/lib/python3.11/site-packages/matplotlib/backends/backend_agg.py", line 400, in draw
    self.figure.draw(self.renderer)
  File "/opt/anaconda3/lib/python3.11/site-packages/matplotlib/artist.py", line 95, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/lib/python3.11/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/lib/python3.11/site-packages/matplotlib/figure.py", line 3140, in draw
    mimage._draw_list_compositing_images(
  File "/opt/anaconda3/lib/python3.11/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
    a.draw(renderer)
  File "/opt/anaconda3/lib/python3.11/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/lib/python3.11/site-packages/cartopy/mpl/geoaxes.py", line 531, in draw
    img, extent, origin = factory.image_for_domain(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/lib/python3.11/site-packages/cartopy/io/img_tiles.py", line 98, in image_for_domain
    img, extent, origin = _merge_tiles(tiles)
                          ^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/lib/python3.11/site-packages/cartopy/io/img_tiles.py", line 646, in _merge_tiles
    img[img_slice] = tile_img
    ~~~^^^^^^^^^^^
ValueError: could not broadcast input array from shape (512,512,3) into shape (766,766,3)
Full environment definition

Operating system

macOS Ventura 13.6

Cartopy version

Tested on both
0.21.1
0.22.0

conda list

# Name                    Version                   Build  Channel
blas                      1.0                         mkl  
brotli                    1.0.9                hca72f7f_7  
brotli-bin                1.0.9                hca72f7f_7  
bzip2                     1.0.8                h1de35cc_0  
c-ares                    1.19.1               h6c40b1e_0  
ca-certificates           2023.08.22           hecd8cb5_0    anaconda
cartopy                   0.22.0          py311hab14417_0    conda-forge
certifi                   2023.7.22       py311hecd8cb5_0    anaconda
contourpy                 1.0.5           py311ha357a0b_0  
cycler                    0.11.0             pyhd3eb1b0_0  
fonttools                 4.25.0             pyhd3eb1b0_0  
freetype                  2.12.1               hd8bbffd_0  
geos                      3.8.0                hb1e8313_0  
giflib                    5.2.1                h6c40b1e_3  
intel-openmp              2023.1.0         ha357a0b_43547  
jpeg                      9e                   h6c40b1e_1  
kiwisolver                1.4.4           py311hcec6c5f_0  
krb5                      1.20.1               h428f121_1  
lcms2                     2.12                 hf1fd2bf_0  
lerc                      3.0                  he9d5cce_0  
libbrotlicommon           1.0.9                hca72f7f_7  
libbrotlidec              1.0.9                hca72f7f_7  
libbrotlienc              1.0.9                hca72f7f_7  
libcurl                   8.2.1                hf20ceda_0  
libcxx                    16.0.6               hd57cbcb_0    conda-forge
libdeflate                1.17                 hb664fd8_1  
libedit                   3.1.20221030         h6c40b1e_0  
libev                     4.33                 h9ed2024_1  
libffi                    3.4.4                hecd8cb5_0  
libgfortran               5.0.0           11_3_0_hecd8cb5_28    anaconda
libgfortran5              11.3.0              h9dfd629_28    anaconda
libnghttp2                1.52.0               h9beae6a_1  
libpng                    1.6.39               h6c40b1e_0  
libssh2                   1.10.0               h04015c4_2  
libtiff                   4.5.1                hcec6c5f_0  
libwebp                   1.3.2                hf6ce154_0  
libwebp-base              1.3.2                h6c40b1e_0  
llvm-openmp               14.0.6               h0dcd299_0    anaconda
lz4-c                     1.9.4                hcec6c5f_0  
matplotlib-base           3.7.2           py311h8251f7d_0  
mkl                       2023.1.0         h8e150cf_43559  
mkl-service               2.4.0           py311h6c40b1e_1  
mkl_fft                   1.3.8           py311h6c40b1e_0  
mkl_random                1.2.4           py311ha357a0b_0  
munkres                   1.1.4                      py_0  
ncurses                   6.4                  hcec6c5f_0  
numpy                     1.26.0          py311h728a8a3_0  
numpy-base                1.26.0          py311h53bf9ac_0  
openjpeg                  2.4.0                h66ea3da_0  
openssl                   3.0.11               hca72f7f_2    anaconda
packaging                 23.1            py311hecd8cb5_0  
pillow                    10.0.1          py311h7d39338_0  
pip                       23.2.1          py311hecd8cb5_0  
proj                      8.2.1                hd69def0_0  
pyparsing                 3.0.9           py311hecd8cb5_0  
pyproj                    3.4.1           py311h089a554_0  
pyshp                     2.1.3              pyhd3eb1b0_0  
python                    3.11.5               hf27a42d_0  
python-dateutil           2.8.2              pyhd3eb1b0_0  
python_abi                3.11                    2_cp311    conda-forge
readline                  8.2                  hca72f7f_0  
scipy                     1.11.3          py311h224febf_0    anaconda
setuptools                68.0.0          py311hecd8cb5_0  
shapely                   2.0.1           py311ha6175ea_0  
six                       1.16.0             pyhd3eb1b0_1  
sqlite                    3.41.2               h6c40b1e_0  
tbb                       2021.8.0             ha357a0b_0  
tk                        8.6.12               h5d9f67b_0  
tzdata                    2023c                h04d1e81_0  
wheel                     0.41.2          py311hecd8cb5_0  
xz                        5.4.2                h6c40b1e_0  
zlib                      1.2.13               h4dc903c_0  
zstd                      1.5.5                hc035e20_0  

pip list

@lgolston
Copy link
Contributor

lgolston commented Oct 9, 2023

Hello @AdamTheisen, this should be because the server is returning a warning tile some of the time due to a phaseout of the current service. There is a fix in the works at: #2266:
122-2

@AdamTheisen
Copy link
Author

Thanks @lgolston, that is good to know! We'll have to update our processes accordingly.

@rcomer rcomer linked a pull request Oct 13, 2023 that will close this issue
@QuLogic QuLogic added this to the Next Release milestone Oct 20, 2023
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

Successfully merging a pull request may close this issue.

3 participants