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

Feature: add etopo plotting to stock_img #1747

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from cartopy import config
import cartopy.crs as ccrs
import cartopy.feature
from cartopy.io import Downloader
import cartopy.mpl.contour
import cartopy.mpl.feature_artist as feature_artist
import cartopy.mpl.geocollection
Expand Down Expand Up @@ -1003,20 +1004,32 @@ def stock_img(self, name='ne_shaded'):
"""
Add a standard image to the map.

Currently, the only (and default) option is a downsampled version of
the Natural Earth shaded relief raster.
Currently, there are 2 options:

1. 'ne_shaded'(default) a downsampled version of the Natural Earth
shaded relief raster.
2. 'etopo' a downsampled version of global relief model of Earth's
surface that integrates land topography and ocean bathymetry. This
option is the same as the etopo from Basemap.
smartlixx marked this conversation as resolved.
Show resolved Hide resolved
https://www.ngdc.noaa.gov/mgg/image/color_etopo1_ice_low.jpg
"""
smartlixx marked this conversation as resolved.
Show resolved Hide resolved
if name not in ['ne_shaded', 'etopo']:
raise ValueError('Unknown stock image %r.' % name)

source_proj = ccrs.PlateCarree()
if name == 'ne_shaded':
source_proj = ccrs.PlateCarree()
fname = (config["repo_data_dir"] / 'raster' / 'natural_earth'
/ '50-natural-earth-1-downsampled.png')

return self.imshow(imread(fname), origin='upper',
transform=source_proj,
extent=[-180, 180, -90, 90])
else:
raise ValueError('Unknown stock image %r.' % name)
elif name == 'etopo':
url_template = 'https://www.ngdc.noaa.gov/mgg/image/{name}.jpg'
target_path_template = str(
Path(config["data_dir"] / 'raster' / '{name}.jpg'))
d = Downloader(url_template, target_path_template)
fname = d.path({'name': 'color_etopo1_ice_low'})

return self.imshow(imread(fname), origin='upper',
transform=source_proj,
extent=[-180, 180, -90, 90])

def background_img(self, name='ne_shaded', resolution='low', extent=None,
cache=False):
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions lib/cartopy/tests/mpl/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ def test_stock_img():
return ax.figure


@pytest.mark.mpl_image_compare(filename='imshow_etopo_ortho.png')
def test_stock_img_etopo():
smartlixx marked this conversation as resolved.
Show resolved Hide resolved
ax = plt.axes(projection=ccrs.Orthographic())
smartlixx marked this conversation as resolved.
Show resolved Hide resolved
ax.stock_img(name='etopo')
return ax.figure


@pytest.mark.mpl_image_compare(filename='imshow_natural_earth_ortho.png')
def test_pil_Image():
img = Image.open(NATURAL_EARTH_IMG)
Expand Down