Skip to content

Commit

Permalink
Add etopo1 option to stock_img
Browse files Browse the repository at this point in the history
  • Loading branch information
smartlixx committed Oct 15, 2021
1 parent 0baa5e0 commit 5779145
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import cartopy.mpl.feature_artist as feature_artist
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__ >= '3.1', \
Expand Down Expand Up @@ -988,9 +990,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
Expand All @@ -999,6 +1005,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])
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions lib/cartopy/tests/mpl/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ 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')


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

0 comments on commit 5779145

Please sign in to comment.