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 Nov 19, 2021
1 parent 0baa5e0 commit 16d7d95
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
31 changes: 23 additions & 8 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import cartopy.mpl.feature_artist as feature_artist
import cartopy.mpl.patch as cpatch
from cartopy.mpl.slippy_image_artist import SlippyImageArtist
from cartopy.io import Downloader


assert mpl.__version__ >= '3.1', \
Expand Down Expand Up @@ -988,22 +989,36 @@ 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.
https://github.com/SciTools/cartopy/blob/master/lib/cartopy/data/raster/natural_earth/50-natural-earth-1-downsampled.png
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)

import os
source_proj = ccrs.PlateCarree()

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

return self.imshow(imread(fname), origin='upper',
elif name == 'etopo':
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])
else:
raise ValueError('Unknown stock image %r.' % name)

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 @@ -173,6 +173,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)
Expand Down

0 comments on commit 16d7d95

Please sign in to comment.