1
1
"""
2
2
Function to download the Earth relief datasets from the GMT data server, and
3
- load as DataArray.
3
+ load as :class:`xarray. DataArray` .
4
4
5
5
The grids are available in various resolutions.
6
6
"""
12
12
13
13
@kwargs_to_strings (region = "sequence" )
14
14
def load_earth_relief (resolution = "01d" , region = None , registration = None ):
15
- """
15
+ r """
16
16
Load Earth relief grids (topography and bathymetry) in various resolutions.
17
17
18
18
The grids are downloaded to a user data directory
@@ -21,8 +21,11 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
21
21
So you'll need an internet connection the first time around.
22
22
23
23
These grids can also be accessed by passing in the file name
24
- ``'@earth_relief_rru[_reg]'`` to any grid plotting/processing function.
25
- Refer to :gmt-docs:`datasets/remote-data.html` for more details.
24
+ **@earth_relief**\_\ *res*\[_\ *reg*] to any grid plotting/processing
25
+ function. *res* is the grid resolution (see below), and *reg* is grid
26
+ registration type (**p** for pixel registration or *g* for gridline
27
+ registration). Refer to :gmt-docs:`datasets/remote-data.html` for more
28
+ details.
26
29
27
30
Parameters
28
31
----------
@@ -35,7 +38,7 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
35
38
36
39
region : str or list
37
40
The subregion of the grid to load. Required for Earth relief grids with
38
- resolutions <= 05m.
41
+ resolutions higher than 5 arc-minute (i.e., `` 05m``) .
39
42
40
43
registration : str
41
44
Grid registration type. Either ``pixel`` for pixel registration or
@@ -45,14 +48,15 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
45
48
46
49
Returns
47
50
-------
48
- grid : xarray.DataArray
51
+ grid : :class:` xarray.DataArray`
49
52
The Earth relief grid. Coordinates are latitude and longitude in
50
53
degrees. Relief is in meters.
51
54
52
55
Notes
53
56
-----
54
- The DataArray doesn's support slice operation, for Earth relief data with
55
- resolutions higher than "05m", which are stored as smaller tiles.
57
+ The :class:`xarray.DataArray` grid doesn't support slice operation, for
58
+ Earth relief data with resolutions higher than "05m", which are stored as
59
+ smaller tiles.
56
60
57
61
Examples
58
62
--------
@@ -83,26 +87,24 @@ def load_earth_relief(resolution="01d", region=None, registration=None):
83
87
"gridline-registered grid is available."
84
88
)
85
89
90
+ if resolution not in non_tiled_resolutions + tiled_resolutions :
91
+ raise GMTInvalidInput (f"Invalid Earth relief resolution '{ resolution } '." )
92
+
86
93
# different ways to load tiled and non-tiled earth relief data
87
- if resolution in non_tiled_resolutions :
88
- if region is not None :
89
- raise NotImplementedError (
90
- f"'region' is not supported for Earth relief resolution '{ resolution } '"
91
- )
92
- fname = which (f"@earth_relief_{ resolution } { reg } " , download = "a" )
93
- with xr .open_dataarray (fname ) as dataarray :
94
- grid = dataarray .load ()
95
- _ = grid .gmt # load GMTDataArray accessor information
96
- elif resolution in tiled_resolutions :
97
- # Titled grid can't be sliced.
98
- # See https://github.com/GenericMappingTools/pygmt/issues/524
99
- if region is None :
94
+ # Known issue: tiled grids don't support slice operation
95
+ # See https://github.com/GenericMappingTools/pygmt/issues/524
96
+ if region is None :
97
+ if resolution in non_tiled_resolutions :
98
+ fname = which (f"@earth_relief_{ resolution } { reg } " , download = "a" )
99
+ with xr .open_dataarray (fname ) as dataarray :
100
+ grid = dataarray .load ()
101
+ _ = grid .gmt # load GMTDataArray accessor information
102
+ else :
100
103
raise GMTInvalidInput (
101
- f"'region' is required for Earth relief resolution '{ resolution } '"
104
+ f"'region' is required for Earth relief resolution '{ resolution } '. "
102
105
)
103
- grid = grdcut (f"@earth_relief_{ resolution } { reg } " , region = region )
104
106
else :
105
- raise GMTInvalidInput ( f'Invalid Earth relief resolution " { resolution } "' )
107
+ grid = grdcut ( f"@earth_relief_ { resolution } { reg } " , region = region )
106
108
107
109
# Add some metadata to the grid
108
110
grid .name = "elevation"
0 commit comments