10
10
from pygmt .src import grdcut , which
11
11
12
12
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 ):
15
15
r"""
16
16
Load Earth relief grids (topography and bathymetry) in various resolutions.
17
17
@@ -50,6 +50,13 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
50
50
a pixel-registered grid is returned unless only the
51
51
gridline-registered grid is available.
52
52
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
+
53
60
Returns
54
61
-------
55
62
grid : :class:`xarray.DataArray`
@@ -73,12 +80,21 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
73
80
>>> grid = load_earth_relief(
74
81
... "05m", region=[120, 160, 30, 60], registration="gridline"
75
82
... )
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
+ ... )
76
90
"""
77
91
78
92
# earth relief data stored as single grids for low resolutions
79
93
non_tiled_resolutions = ["01d" , "30m" , "20m" , "15m" , "10m" , "06m" ]
80
94
# earth relief data stored as tiles for high resolutions
81
95
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" ]
82
98
83
99
if registration in ("pixel" , "gridline" , None ):
84
100
# If None, let GMT decide on Pixel/Gridline type
@@ -103,21 +119,25 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
103
119
f"resolution '{ resolution } ' is not supported."
104
120
)
105
121
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
+
106
127
# different ways to load tiled and non-tiled earth relief data
107
128
# Known issue: tiled grids don't support slice operation
108
129
# See https://github.com/GenericMappingTools/pygmt/issues/524
109
130
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 :
116
132
raise GMTInvalidInput (
117
133
f"'region' is required for Earth relief resolution '{ resolution } '."
118
134
)
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
119
139
else :
120
- grid = grdcut (f"@earth_relief_ { resolution } { reg } " , region = region )
140
+ grid = grdcut (f"@{ earth_relief_prefix } { resolution } { reg } " , region = region )
121
141
122
142
# Add some metadata to the grid
123
143
grid .name = "elevation"
0 commit comments