Skip to content

Commit f2ea4fe

Browse files
committed
Add etopo1 option to stock_img
1 parent 2a5c843 commit f2ea4fe

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

lib/cartopy/mpl/geoaxes.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import cartopy.mpl.patch as cpatch
4242
from cartopy.mpl.slippy_image_artist import SlippyImageArtist
4343
from cartopy.vector_transform import vector_scalar_to_grid
44+
from cartopy.io import Downloader
4445

4546

4647
assert mpl.__version__ >= '1.5.1', ('Cartopy is only supported with '
@@ -1005,9 +1006,13 @@ def stock_img(self, name='ne_shaded'):
10051006
"""
10061007
Add a standard image to the map.
10071008
1008-
Currently, the only (and default) option is a downsampled version of
1009-
the Natural Earth shaded relief raster.
1009+
Currently, there are 2 options:
10101010
1011+
1. 'ne_shaded'(default) a downsampled version of the Natural Earth
1012+
shaded relief raster.
1013+
2. 'etopo' a downsampled version of global relief model of Earth's
1014+
surface that integrates land topography and ocean bathymetry. This
1015+
option is the same as the etopo from Basemap.
10111016
"""
10121017
if name == 'ne_shaded':
10131018
import os
@@ -1016,6 +1021,19 @@ def stock_img(self, name='ne_shaded'):
10161021
'raster', 'natural_earth',
10171022
'50-natural-earth-1-downsampled.png')
10181023

1024+
return self.imshow(imread(fname), origin='upper',
1025+
transform=source_proj,
1026+
extent=[-180, 180, -90, 90])
1027+
elif name == 'etopo':
1028+
import os
1029+
source_proj = ccrs.PlateCarree()
1030+
1031+
url_template = 'https://www.ngdc.noaa.gov/mgg/image/{name}.jpg'
1032+
target_path_template = os.path.join(config["data_dir"],
1033+
'raster', '{name}.jpg')
1034+
d = Downloader(url_template, target_path_template)
1035+
fname = d.path({'name': 'color_etopo1_ice_low'})
1036+
10191037
return self.imshow(imread(fname), origin='upper',
10201038
transform=source_proj,
10211039
extent=[-180, 180, -90, 90])
511 KB
Loading

lib/cartopy/tests/mpl/test_images.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ def test_stock_img():
179179
ax.stock_img()
180180

181181

182+
@pytest.mark.xfail((5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0),
183+
reason='Proj Orthographic projection is buggy.',
184+
strict=True)
185+
@ImageTesting(['imshow_etopo_ortho'], tolerance=0.7)
186+
def test_stock_img_etopo():
187+
ax = plt.axes(projection=ccrs.Orthographic())
188+
ax.stock_img(name='etopo')
189+
190+
182191
@pytest.mark.xfail((5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0),
183192
reason='Proj Orthographic projection is buggy.',
184193
strict=True)

0 commit comments

Comments
 (0)