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

background_img displays downsampled images #2428

Open
giodecillis opened this issue Aug 30, 2024 · 0 comments
Open

background_img displays downsampled images #2428

giodecillis opened this issue Aug 30, 2024 · 0 comments

Comments

@giodecillis
Copy link

giodecillis commented Aug 30, 2024

Description

The method background_img() currently displays background images at a lower resolution compared to the original files.
The issue is similar to #1708 and in fact I managed to solve it by modifing the source file adding the regrid_shape argument, set to 5000.
Below I report a test case and the output images, with and without the regrid_shape argument.
I think that it would be beneficial to add regrid_shape as optional argument to background_img().

arctic_high
arctic_low

Code to reproduce

import cartopy.crs as ccrs
import matplotlib
matplotlib.use('TKAgg')
import matplotlib.pyplot as plt
import os
import subprocess
import json


def get_bkg_image(url, fname):
    command = ["curl", "-o", fname, url]
    subprocess.run(command, check=True)

def write_json(fname):
    # Data to be written
    imgdict ={"TEST": {
            "__comment__": "",
            "__source__": "",
            "__projection__": "PlateCarree",
            "high": fname
            }
        }

    # Serializing json
    json_object = json.dumps(imgdict, indent=4)

    # Writing to sample.json
    with open("images.json", "w") as outfile:
        outfile.write(json_object)

if __name__=='__main__':

    # Download background image
    url = "https://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73826/world.topo.bathy.200410.3x5400x2700.jpg"
    get_bkg_image(url, 'image.jpg')

    # Write images.json
    write_json('image.jpg')

    # setup environment
    os.environ["CARTOPY_USER_BACKGROUNDS"] = os.getcwd()



    # setup projection and background_img
    proj = ccrs.Stereographic(central_latitude=90.0, central_longitude=0.0)
    ax = plt.axes(projection=proj)
    ax.background_img(name='TEST', resolution='high', extent = ([-180, 180, 45, 90]))


    ax.set_extent([-180, 180, 90, 60], ccrs.PlateCarree())
Full environment definition

Operating system

Ubuntu 18.04.4 LTS on WSL

Cartopy version

0.23.0

conda list

# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
asttokens                 2.4.1              pyhd8ed1ab_0    conda-forge
blas                      1.0                    openblas
bottleneck                1.3.7           py312ha883a20_0
brotli                    1.0.9                h5eee18b_8
brotli-bin                1.0.9                h5eee18b_8
bzip2                     1.0.8                h5eee18b_6
c-ares                    1.19.1               h5eee18b_0
ca-certificates           2024.7.4             hbcca054_0    conda-forge
cartopy                   0.23.0          py312h1d6d2e6_1    conda-forge
certifi                   2024.7.4        py312h06a4308_0
cftime                    1.6.2           py312ha883a20_1
comm                      0.2.2              pyhd8ed1ab_0    conda-forge
contourpy                 1.2.1                    pypi_0    pypi
cycler                    0.12.1                   pypi_0    pypi
cyrus-sasl                2.1.28               h52b45da_1
dbus                      1.13.18              hb2f20db_0
debugpy                   1.6.7           py312h6a678d5_0
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
exceptiongroup            1.2.2              pyhd8ed1ab_0    conda-forge
executing                 2.0.1              pyhd8ed1ab_0    conda-forge
expat                     2.6.2                h6a678d5_0
fontconfig                2.14.1               hef1e5e3_0
fonttools                 4.53.1                   pypi_0    pypi
freetype                  2.12.1               h4a9f257_0
geos                      3.8.0                he6710b0_0
glib                      2.78.4               h6a678d5_0
glib-tools                2.78.4               h6a678d5_0
gst-plugins-base          1.14.1               h6a678d5_1
gstreamer                 1.14.1               h5eee18b_1
hdf4                      4.2.13               h3ca952b_2
hdf5                      1.12.1               h2b7332f_3
icu                       58.2                 he6710b0_3
importlib-metadata        8.0.0              pyha770c72_0    conda-forge
importlib_metadata        8.0.0                hd8ed1ab_0    conda-forge
ipykernel                 6.29.5             pyh3099207_0    conda-forge
ipympl                    0.9.4                    pypi_0    pypi
ipython                   8.26.0             pyh707e725_0    conda-forge
ipython-genutils          0.2.0                    pypi_0    pypi
ipywidgets                8.1.3                    pypi_0    pypi
jedi                      0.19.1             pyhd8ed1ab_0    conda-forge
jpeg                      9e                   h5eee18b_2
jupyter_client            8.6.2              pyhd8ed1ab_0    conda-forge
jupyter_core              5.7.2           py312h06a4308_0
jupyterlab-widgets        3.0.11                   pypi_0    pypi
kiwisolver                1.4.5                    pypi_0    pypi
krb5                      1.20.1               h143b758_1
lcms2                     2.12                 h3be6417_0
ld_impl_linux-64          2.38                 h1181459_1
lerc                      3.0                  h295c915_0
libbrotlicommon           1.0.9                h5eee18b_8
libbrotlidec              1.0.9                h5eee18b_8
libbrotlienc              1.0.9                h5eee18b_8
libclang                  14.0.6          default_hc6dbbc7_1
libclang13                14.0.6          default_he11475f_1
libcups                   2.4.2                h2d74bed_1
libcurl                   8.7.1                h251f7ec_0
libdeflate                1.17                 h5eee18b_1
libedit                   3.1.20230828         h5eee18b_0
libev                     4.33                 h7f8727e_1
libexpat                  2.6.2                h59595ed_0    conda-forge
libffi                    3.4.4                h6a678d5_1
libgcc-ng                 14.1.0               h77fa898_0    conda-forge
libgfortran-ng            11.2.0               h00389a5_1
libgfortran5              11.2.0               h1234567_1
libglib                   2.78.4               hdc74915_0
libgomp                   14.1.0               h77fa898_0    conda-forge
libiconv                  1.16                 h5eee18b_3
libllvm14                 14.0.6               hdb19cb5_3
libnetcdf                 4.8.1                h14805e7_4
libnghttp2                1.57.0               h2d74bed_0
libnsl                    2.0.1                hd590300_0    conda-forge
libopenblas               0.3.21               h043d6bf_0
libpng                    1.6.39               h5eee18b_0
libpq                     12.17                hdbd6064_0
libsodium                 1.0.18               h36c2ea0_1    conda-forge
libsqlite                 3.46.0               hde9e2c9_0    conda-forge
libssh2                   1.11.0               h251f7ec_0
libstdcxx-ng              14.1.0               hc0a3c3a_0    conda-forge
libtiff                   4.5.1                h6a678d5_0
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libwebp-base              1.3.2                h5eee18b_0
libxcb                    1.15                 h7f8727e_0
libxcrypt                 4.4.36               hd590300_1    conda-forge
libxkbcommon              1.0.1                hfa300c1_0
libxml2                   2.9.14               h74e7548_0
libzip                    1.8.0                h6ac8c49_1
libzlib                   1.2.13               h4ab18f5_6    conda-forge
lz4-c                     1.9.4                h6a678d5_1
matplotlib                3.9.1                    pypi_0    pypi
matplotlib-base           3.8.4           py312h526ad5a_0
matplotlib-inline         0.1.7              pyhd8ed1ab_0    conda-forge
mysql                     5.7.24               h721c034_2
nc-time-axis              1.4.1              pyhd8ed1ab_0    conda-forge
ncurses                   6.4                  h6a678d5_0
nest-asyncio              1.6.0              pyhd8ed1ab_0    conda-forge
netcdf4                   1.6.2           py312h33ae428_0
numexpr                   2.8.7           py312he7dcb8a_0
numpy                     2.0.1                    pypi_0    pypi
numpy-base                1.26.4          py312he1a6c75_0
openjpeg                  2.4.0                h9ca470c_2
openssl                   3.3.1                h4bc722e_2    conda-forge
packaging                 24.1               pyhd8ed1ab_0    conda-forge
pandas                    2.2.2           py312h526ad5a_0
parso                     0.8.4              pyhd8ed1ab_0    conda-forge
pcre2                     10.42                hebb0a14_1
pexpect                   4.9.0              pyhd8ed1ab_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    10.4.0          py312h5eee18b_0
pip                       24.0            py312h06a4308_0
platformdirs              4.2.2              pyhd8ed1ab_0    conda-forge
ply                       3.11            py312h06a4308_1
proj                      9.3.1                he5811b7_0
prompt-toolkit            3.0.47             pyha770c72_0    conda-forge
psutil                    5.9.0           py312h5eee18b_0
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pure_eval                 0.2.3              pyhd8ed1ab_0    conda-forge
pybind11-abi              5                    hd3eb1b0_0
pygments                  2.18.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.1.2                    pypi_0    pypi
pyproj                    3.6.1           py312h6268720_0
pyqt                      5.15.10         py312h6a678d5_0
pyqt5-sip                 12.13.0         py312h5eee18b_0
pyshp                     2.3.1           py312h06a4308_0
python                    3.12.2          hab00c5b_0_cpython    conda-forge
python-dateutil           2.9.0.post0              pypi_0    pypi
python-tzdata             2023.3             pyhd3eb1b0_0
python_abi                3.12                    5_cp312    conda-forge
pytz                      2024.1          py312h06a4308_0
pyzmq                     25.1.2          py312h6a678d5_0
qt-main                   5.15.2               h7358343_9
readline                  8.2                  h5eee18b_0
scipy                     1.13.1          py312h2809609_0
setuptools                69.5.1          py312h06a4308_0
shapely                   2.0.5           py312h1789038_0
sip                       6.7.12          py312h6a678d5_0
six                       1.16.0             pyh6c4a22f_0    conda-forge
sqlite                    3.45.3               h5eee18b_0
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
tk                        8.6.14               h39e8969_0
tornado                   6.4.1           py312h5eee18b_0
traitlets                 5.14.3             pyhd8ed1ab_0    conda-forge
typing_extensions         4.12.2             pyha770c72_0    conda-forge
tzdata                    2024a                h04d1e81_0
unicodedata2              15.1.0          py312h5eee18b_0
wcwidth                   0.2.13             pyhd8ed1ab_0    conda-forge
wheel                     0.43.0          py312h06a4308_0
widgetsnbextension        4.0.11                   pypi_0    pypi
xarray                    2023.6.0        py312h06a4308_0
xz                        5.4.6                h5eee18b_1
zeromq                    4.3.5                h6a678d5_0
zipp                      3.19.2             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               h4ab18f5_6    conda-forge
zstd                      1.5.5                hc292b87_2

pip list

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

1 participant