diff --git a/lib/cartopy/mpl/geoaxes.py b/lib/cartopy/mpl/geoaxes.py index 0152301e17..2e0f53c7f7 100644 --- a/lib/cartopy/mpl/geoaxes.py +++ b/lib/cartopy/mpl/geoaxes.py @@ -41,6 +41,7 @@ import cartopy.mpl.patch as cpatch from cartopy.mpl.slippy_image_artist import SlippyImageArtist from cartopy.vector_transform import vector_scalar_to_grid +from cartopy.io import Downloader assert mpl.__version__ >= '1.5.1', ('Cartopy is only supported with ' @@ -1005,9 +1006,13 @@ 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. """ if name == 'ne_shaded': import os @@ -1016,6 +1021,19 @@ def stock_img(self, name='ne_shaded'): 'raster', 'natural_earth', '50-natural-earth-1-downsampled.png') + return self.imshow(imread(fname), origin='upper', + transform=source_proj, + extent=[-180, 180, -90, 90]) + elif name == 'etopo': + import os + source_proj = ccrs.PlateCarree() + + url_template = 'https://www.ngdc.noaa.gov/mgg/image/{name}.jpg' + target_path_template = os.path.join(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]) 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 0000000000..5c5ae07ed5 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 6d49acfa84..0d26a9f1bc 100644 --- a/lib/cartopy/tests/mpl/test_images.py +++ b/lib/cartopy/tests/mpl/test_images.py @@ -179,6 +179,15 @@ def test_stock_img(): ax.stock_img() +@pytest.mark.xfail((5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0), + reason='Proj Orthographic projection is buggy.', + strict=True) +@ImageTesting(['imshow_etopo_ortho'], tolerance=0.7) +def test_stock_img_etopo(): + ax = plt.axes(projection=ccrs.Orthographic()) + ax.stock_img(name='etopo') + + @pytest.mark.xfail((5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0), reason='Proj Orthographic projection is buggy.', strict=True)