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 15, 2021
1 parent 0baa5e0 commit 1d35964
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
27 changes: 22 additions & 5 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,38 @@ 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)

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')
elif name == 'etopo':
import os
source_proj = ccrs.PlateCarree()

return self.imshow(imread(fname), origin='upper',
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 1d35964

Please sign in to comment.