1010from pygmt .src import grdcut , which
1111
1212
13- @kwargs_to_strings (region = "sequence" )
14- def load_earth_relief (resolution = "01d" , region = None , registration = None ):
13+ @kwargs_to_strings (convert_bools = False , region = "sequence" )
14+ def load_earth_relief (resolution = "01d" , region = None , registration = None , use_srtm = False ):
1515 r"""
1616 Load Earth relief grids (topography and bathymetry) in various resolutions.
1717
@@ -50,6 +50,13 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
5050 a pixel-registered grid is returned unless only the
5151 gridline-registered grid is available.
5252
53+ use_srtm : bool
54+ By default, the land-only SRTM tiles from NASA are used to generate the
55+ ``'03s'`` and ``'01s'`` grids, and the missing ocean values are filled
56+ by up-sampling the SRTM15+V2.1 tiles which have a resolution of 15
57+ arc-second (i.e., ``'15s'``). If True, will only load the original
58+ land-only SRTM tiles.
59+
5360 Returns
5461 -------
5562 grid : :class:`xarray.DataArray`
@@ -73,12 +80,21 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
7380 >>> grid = load_earth_relief(
7481 ... "05m", region=[120, 160, 30, 60], registration="gridline"
7582 ... )
83+ >>> # load the original 3 arc-second land-only SRTM tiles from NASA
84+ >>> grid = load_earth_relief(
85+ ... "03s",
86+ ... region=[135, 136, 35, 36],
87+ ... registration="gridline",
88+ ... use_srtm=True,
89+ ... )
7690 """
7791
7892 # earth relief data stored as single grids for low resolutions
7993 non_tiled_resolutions = ["01d" , "30m" , "20m" , "15m" , "10m" , "06m" ]
8094 # earth relief data stored as tiles for high resolutions
8195 tiled_resolutions = ["05m" , "04m" , "03m" , "02m" , "01m" , "30s" , "15s" , "03s" , "01s" ]
96+ # resolutions of original land-only SRTM tiles from NASA
97+ land_only_srtm_resolutions = ["03s" , "01s" ]
8298
8399 if registration in ("pixel" , "gridline" , None ):
84100 # If None, let GMT decide on Pixel/Gridline type
@@ -103,21 +119,25 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
103119 f"resolution '{ resolution } ' is not supported."
104120 )
105121
122+ # Choose earth relief data prefix
123+ earth_relief_prefix = "earth_relief_"
124+ if use_srtm and resolution in land_only_srtm_resolutions :
125+ earth_relief_prefix = "srtm_relief_"
126+
106127 # different ways to load tiled and non-tiled earth relief data
107128 # Known issue: tiled grids don't support slice operation
108129 # See https://github.com/GenericMappingTools/pygmt/issues/524
109130 if region is None :
110- if resolution in non_tiled_resolutions :
111- fname = which (f"@earth_relief_{ resolution } { reg } " , download = "a" )
112- with xr .open_dataarray (fname ) as dataarray :
113- grid = dataarray .load ()
114- _ = grid .gmt # load GMTDataArray accessor information
115- else :
131+ if resolution not in non_tiled_resolutions :
116132 raise GMTInvalidInput (
117133 f"'region' is required for Earth relief resolution '{ resolution } '."
118134 )
135+ fname = which (f"@earth_relief_{ resolution } { reg } " , download = "a" )
136+ with xr .open_dataarray (fname ) as dataarray :
137+ grid = dataarray .load ()
138+ _ = grid .gmt # load GMTDataArray accessor information
119139 else :
120- grid = grdcut (f"@earth_relief_ { resolution } { reg } " , region = region )
140+ grid = grdcut (f"@{ earth_relief_prefix } { resolution } { reg } " , region = region )
121141
122142 # Add some metadata to the grid
123143 grid .name = "elevation"
0 commit comments