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 Apr 6, 2021
1 parent 2a5c843 commit f2ea4fe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down Expand Up @@ -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
Expand All @@ -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])
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions lib/cartopy/tests/mpl/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f2ea4fe

Please sign in to comment.