diff --git a/lib/cartopy/mpl/geoaxes.py b/lib/cartopy/mpl/geoaxes.py index 18e38a400..e044c888f 100644 --- a/lib/cartopy/mpl/geoaxes.py +++ b/lib/cartopy/mpl/geoaxes.py @@ -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 @@ -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. + https://www.ngdc.noaa.gov/mgg/image/color_etopo1_ice_low.jpg """ + 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): diff --git a/lib/cartopy/tests/mpl/baseline_images/mpl/test_images/imshow_etopo_ortho.png b/lib/cartopy/tests/mpl/baseline_images/mpl/test_images/imshow_etopo_ortho.png new file mode 100644 index 000000000..5c5ae07ed Binary files /dev/null and b/lib/cartopy/tests/mpl/baseline_images/mpl/test_images/imshow_etopo_ortho.png differ diff --git a/lib/cartopy/tests/mpl/test_images.py b/lib/cartopy/tests/mpl/test_images.py index 8613afd22..76849aab4 100644 --- a/lib/cartopy/tests/mpl/test_images.py +++ b/lib/cartopy/tests/mpl/test_images.py @@ -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(): + ax = plt.axes(projection=ccrs.Orthographic()) + 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)