Skip to content

Commit 5234b52

Browse files
Remote Datasets: Adjust attributes - remove "title", use default of "name" and "long_name", introduce "description" (#3048)
Co-authored-by: Dongdong Tian <[email protected]>
1 parent 9aa2780 commit 5234b52

22 files changed

+135
-126
lines changed

examples/tutorials/advanced/grid_equalization.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
grid = pygmt.datasets.load_earth_relief(
2121
resolution="03s", region=[-119.825, -119.4, 37.6, 37.825]
2222
)
23-
grid_dist = pygmt.grd2xyz(grid=grid, output_type="pandas")["elevation"]
23+
grid_dist = pygmt.grd2xyz(grid=grid, output_type="pandas")["z"]
2424

2525

2626
# %%

pygmt/datasets/earth_free_air_anomaly.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Function to download the IGPP Earth Free-Air Anomaly dataset from the GMT data server,
2+
Function to download the IGPP Earth free-air anomaly dataset from the GMT data server,
33
and load as :class:`xarray.DataArray`.
44
55
The grids are available in various resolutions.
@@ -20,13 +20,13 @@ def load_earth_free_air_anomaly(
2020
registration: Literal["gridline", "pixel", None] = None,
2121
):
2222
r"""
23-
Load the IGPP Earth Free-Air Anomaly dataset in various resolutions.
23+
Load the IGPP Earth free-air anomaly dataset in various resolutions.
2424
2525
.. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_faa.jpg
2626
:width: 80 %
2727
:align: center
2828
29-
IGPP Earth Free-Air Anomaly dataset.
29+
IGPP Earth free-air anomaly dataset.
3030
3131
The grids are downloaded to a user data directory
3232
(usually ``~/.gmt/server/earth/earth_faa/``) the first time you invoke
@@ -102,7 +102,7 @@ def load_earth_free_air_anomaly(
102102
... )
103103
"""
104104
grid = _load_remote_dataset(
105-
dataset_name="earth_free_air_anomaly",
105+
dataset_name="earth_faa",
106106
dataset_prefix="earth_faa_",
107107
resolution=resolution,
108108
region=region,

pygmt/datasets/earth_geoid.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Function to download the EGM2008 Earth Geoid dataset from the GMT data server, and load
2+
Function to download the EGM2008 Earth geoid dataset from the GMT data server, and load
33
as :class:`xarray.DataArray`.
44
55
The grids are available in various resolutions.
@@ -20,13 +20,13 @@ def load_earth_geoid(
2020
registration: Literal["gridline", "pixel"] = "gridline",
2121
):
2222
r"""
23-
Load the EGM2008 Earth Geoid dataset in various resolutions.
23+
Load the EGM2008 Earth geoid dataset in various resolutions.
2424
2525
.. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_geoid.jpg
2626
:width: 80 %
2727
:align: center
2828
29-
EGM2008 Earth Geoid dataset.
29+
EGM2008 Earth geoid dataset.
3030
3131
The grids are downloaded to a user data directory
3232
(usually ``~/.gmt/server/earth/earth_geoid/``) the first time you invoke

pygmt/datasets/earth_magnetic_anomaly.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def load_earth_magnetic_anomaly(
147147
"Valid values are 'emag2', 'emag2_4km', and 'wdmam'."
148148
)
149149
dataset_prefix = magnetic_anomaly_sources[data_source]
150-
dataset_name = "earth_wdmam" if data_source == "wdmam" else "earth_magnetic_anomaly"
150+
dataset_name = "earth_wdmam" if data_source == "wdmam" else "earth_mag"
151151
grid = _load_remote_dataset(
152152
dataset_name=dataset_name,
153153
dataset_prefix=dataset_prefix,

pygmt/datasets/earth_mask.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ def load_earth_mask(
2020
registration: Literal["gridline", "pixel"] = "gridline",
2121
):
2222
r"""
23-
Load the GSHHG Earth Mask dataset in various resolutions.
23+
Load the GSHHG Earth mask dataset in various resolutions.
2424
2525
.. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_mask.jpg
2626
:width: 80 %
2727
:align: center
2828
29-
GSHHG Earth Mask dataset.
29+
GSHHG Earth mask dataset.
3030
3131
The grids are downloaded to a user data directory
3232
(usually ``~/.gmt/server/earth/earth_mask/``) the first time you invoke

pygmt/datasets/earth_relief.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,14 @@ def load_earth_relief(
161161
)
162162
else:
163163
dataset_prefix = earth_relief_sources[data_source]
164-
164+
# Choose earth relief dataset
165+
match data_source:
166+
case "igpp" | "synbath":
167+
dataset_name = "earth_igpp"
168+
case "gebco" | "gebcosi":
169+
dataset_name = "earth_gebco"
165170
grid = _load_remote_dataset(
166-
dataset_name="earth_relief",
171+
dataset_name=dataset_name,
167172
dataset_prefix=dataset_prefix,
168173
resolution=resolution,
169174
region=region,

pygmt/datasets/earth_vertical_gravity_gradient.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Function to download the IGPP Earth Vertical Gravity Gradient dataset from the GMT data
2+
Function to download the IGPP Earth vertical gravity gradient dataset from the GMT data
33
server, and load as :class:`xarray.DataArray`.
44
55
The grids are available in various resolutions.
@@ -20,13 +20,13 @@ def load_earth_vertical_gravity_gradient(
2020
registration: Literal["gridline", "pixel", None] = None,
2121
):
2222
r"""
23-
Load the IGPP Earth Vertical Gravity Gradient dataset in various resolutions.
23+
Load the IGPP Earth vertical gravity gradient dataset in various resolutions.
2424
2525
.. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_vgg.jpg
2626
:width: 80 %
2727
:align: center
2828
29-
IGPP Earth Vertical Gravity Gradient dataset.
29+
IGPP Earth vertical gravity gradient dataset.
3030
3131
The grids are downloaded to a user data directory
3232
(usually ``~/.gmt/server/earth/earth_vgg/``) the first time you invoke

pygmt/datasets/load_remote_dataset.py

+66-77
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,25 @@ class GMTRemoteDataset(NamedTuple):
4141
4242
Attributes
4343
----------
44-
title : str
45-
The title of the dataset, used in error messages.
46-
name : str
47-
The name assigned as an attribute to the DataArray.
48-
long_name : str
49-
The long name assigned as an attribute to the DataArray.
50-
units : str
44+
description : str
45+
The name assigned as an attribute to the DataArray.
46+
units : str, None
5147
The units of the values in the DataArray.
5248
resolutions : dict
5349
Dictionary of available resolution as keys and Resolution objects as values.
5450
extra_attributes : dict
5551
A dictionary of extra or unique attributes of the dataset.
5652
"""
5753

58-
title: str
59-
name: str
60-
long_name: str
54+
description: str
6155
units: str | None
6256
resolutions: dict[str, Resolution]
6357
extra_attributes: dict
6458

6559

6660
datasets = {
6761
"earth_age": GMTRemoteDataset(
68-
title="seafloor age",
69-
name="seafloor_age",
70-
long_name="age of seafloor crust",
62+
description="EarthByte Earth seafloor crustal age",
7163
units="Myr",
7264
extra_attributes={"horizontal_datum": "WGS84"},
7365
resolutions={
@@ -84,10 +76,8 @@ class GMTRemoteDataset(NamedTuple):
8476
"01m": Resolution("01m", registrations=["gridline"], tiled=True),
8577
},
8678
),
87-
"earth_free_air_anomaly": GMTRemoteDataset(
88-
title="free air anomaly",
89-
name="free_air_anomaly",
90-
long_name="IGPP Earth Free-Air Anomaly",
79+
"earth_faa": GMTRemoteDataset(
80+
description="IGPP Earth free-air anomaly",
9181
units="mGal",
9282
extra_attributes={"horizontal_datum": "WGS84"},
9383
resolutions={
@@ -104,10 +94,30 @@ class GMTRemoteDataset(NamedTuple):
10494
"01m": Resolution("01m", registrations=["pixel"], tiled=True),
10595
},
10696
),
97+
"earth_gebco": GMTRemoteDataset(
98+
description="GEBCO Earth relief",
99+
units="meters",
100+
extra_attributes={"vertical_datum": "EGM96", "horizontal_datum": "WGS84"},
101+
resolutions={
102+
"01d": Resolution("01d"),
103+
"30m": Resolution("30m"),
104+
"20m": Resolution("20m"),
105+
"15m": Resolution("15m"),
106+
"10m": Resolution("10m"),
107+
"06m": Resolution("06m"),
108+
"05m": Resolution("05m", tiled=True),
109+
"04m": Resolution("04m", tiled=True),
110+
"03m": Resolution("03m", tiled=True),
111+
"02m": Resolution("02m", tiled=True),
112+
"01m": Resolution("01m", tiled=True),
113+
"30s": Resolution("30s", tiled=True),
114+
"15s": Resolution("15s", registrations=["pixel"], tiled=True),
115+
"03s": Resolution("03s", registrations=["gridline"], tiled=True),
116+
"01s": Resolution("01s", registrations=["gridline"], tiled=True),
117+
},
118+
),
107119
"earth_geoid": GMTRemoteDataset(
108-
title="Earth geoid",
109-
name="earth_geoid",
110-
long_name="EGM2008 Earth Geoid",
120+
description="EGM2008 Earth geoid",
111121
units="m",
112122
extra_attributes={"horizontal_datum": "WGS84"},
113123
resolutions={
@@ -124,10 +134,30 @@ class GMTRemoteDataset(NamedTuple):
124134
"01m": Resolution("01m", registrations=["gridline"], tiled=True),
125135
},
126136
),
127-
"earth_magnetic_anomaly": GMTRemoteDataset(
128-
title="Earth magnetic anomaly",
129-
name="magnetic_anomaly",
130-
long_name="Earth magnetic anomaly",
137+
"earth_igpp": GMTRemoteDataset(
138+
description="IGPP Earth relief",
139+
units="meters",
140+
extra_attributes={"vertical_datum": "EGM96", "horizontal_datum": "WGS84"},
141+
resolutions={
142+
"01d": Resolution("01d"),
143+
"30m": Resolution("30m"),
144+
"20m": Resolution("20m"),
145+
"15m": Resolution("15m"),
146+
"10m": Resolution("10m"),
147+
"06m": Resolution("06m"),
148+
"05m": Resolution("05m", tiled=True),
149+
"04m": Resolution("04m", tiled=True),
150+
"03m": Resolution("03m", tiled=True),
151+
"02m": Resolution("02m", tiled=True),
152+
"01m": Resolution("01m", tiled=True),
153+
"30s": Resolution("30s", tiled=True),
154+
"15s": Resolution("15s", registrations=["pixel"], tiled=True),
155+
"03s": Resolution("03s", registrations=["gridline"], tiled=True),
156+
"01s": Resolution("01s", registrations=["gridline"], tiled=True),
157+
},
158+
),
159+
"earth_mag": GMTRemoteDataset(
160+
description="EMAG2 Earth Magnetic Anomaly Model",
131161
units="nT",
132162
extra_attributes={"horizontal_datum": "WGS84"},
133163
resolutions={
@@ -144,9 +174,7 @@ class GMTRemoteDataset(NamedTuple):
144174
},
145175
),
146176
"earth_mask": GMTRemoteDataset(
147-
title="Earth mask",
148-
name="earth_mask",
149-
long_name="Mask of land and water features",
177+
description="GSHHG Earth mask",
150178
units=None,
151179
extra_attributes={"horizontal_datum": "WGS84"},
152180
resolutions={
@@ -165,34 +193,8 @@ class GMTRemoteDataset(NamedTuple):
165193
"15s": Resolution("15s"),
166194
},
167195
),
168-
"earth_relief": GMTRemoteDataset(
169-
title="Earth relief",
170-
name="elevation",
171-
long_name="Earth elevation relative to the geoid",
172-
units="meters",
173-
extra_attributes={"vertical_datum": "EGM96", "horizontal_datum": "WGS84"},
174-
resolutions={
175-
"01d": Resolution("01d"),
176-
"30m": Resolution("30m"),
177-
"20m": Resolution("20m"),
178-
"15m": Resolution("15m"),
179-
"10m": Resolution("10m"),
180-
"06m": Resolution("06m"),
181-
"05m": Resolution("05m", tiled=True),
182-
"04m": Resolution("04m", tiled=True),
183-
"03m": Resolution("03m", tiled=True),
184-
"02m": Resolution("02m", tiled=True),
185-
"01m": Resolution("01m", tiled=True),
186-
"30s": Resolution("30s", tiled=True),
187-
"15s": Resolution("15s", registrations=["pixel"], tiled=True),
188-
"03s": Resolution("03s", registrations=["gridline"], tiled=True),
189-
"01s": Resolution("01s", registrations=["gridline"], tiled=True),
190-
},
191-
),
192196
"earth_vgg": GMTRemoteDataset(
193-
title="Earth vertical gravity gradient",
194-
name="earth_vgg",
195-
long_name="IGPP Earth Vertical Gravity Gradient",
197+
description="IGPP Earth vertical gravity gradient",
196198
units="Eotvos",
197199
extra_attributes={"horizontal_datum": "WGS84"},
198200
resolutions={
@@ -210,9 +212,7 @@ class GMTRemoteDataset(NamedTuple):
210212
},
211213
),
212214
"earth_wdmam": GMTRemoteDataset(
213-
title="WDMAM magnetic anomaly",
214-
name="wdmam",
215-
long_name="World Digital Magnetic Anomaly Map",
215+
description="WDMAM World Digital Magnetic Anomaly Map",
216216
units="nT",
217217
extra_attributes={"horizontal_datum": "WGS84"},
218218
resolutions={
@@ -228,9 +228,7 @@ class GMTRemoteDataset(NamedTuple):
228228
},
229229
),
230230
"mars_relief": GMTRemoteDataset(
231-
title="Mars relief",
232-
name="mars_relief",
233-
long_name="NASA Mars (MOLA) relief",
231+
description="NASA Mars (MOLA) relief",
234232
units="meters",
235233
extra_attributes={},
236234
resolutions={
@@ -251,9 +249,7 @@ class GMTRemoteDataset(NamedTuple):
251249
},
252250
),
253251
"moon_relief": GMTRemoteDataset(
254-
title="Moon relief",
255-
name="moon_relief",
256-
long_name="USGS Moon (LOLA) relief",
252+
description="USGS Moon (LOLA) relief",
257253
units="meters",
258254
extra_attributes={},
259255
resolutions={
@@ -274,9 +270,7 @@ class GMTRemoteDataset(NamedTuple):
274270
},
275271
),
276272
"mercury_relief": GMTRemoteDataset(
277-
title="Mercury relief",
278-
name="mercury_relief",
279-
long_name="USGS Mercury relief",
273+
description="USGS Mercury relief",
280274
units="meters",
281275
extra_attributes={},
282276
resolutions={
@@ -295,9 +289,7 @@ class GMTRemoteDataset(NamedTuple):
295289
},
296290
),
297291
"pluto_relief": GMTRemoteDataset(
298-
title="Pluto relief",
299-
name="pluto_relief",
300-
long_name="USGS Pluto relief",
292+
description="USGS Pluto relief",
301293
units="meters",
302294
extra_attributes={},
303295
resolutions={
@@ -316,9 +308,7 @@ class GMTRemoteDataset(NamedTuple):
316308
},
317309
),
318310
"venus_relief": GMTRemoteDataset(
319-
title="Venus relief",
320-
name="venus_relief",
321-
long_name="NASA Magellan Venus relief",
311+
description="NASA Magellan Venus relief",
322312
units="meters",
323313
extra_attributes={},
324314
resolutions={
@@ -388,7 +378,7 @@ def _load_remote_dataset(
388378
# Check resolution
389379
if resolution not in dataset.resolutions:
390380
raise GMTInvalidInput(
391-
f"Invalid resolution '{resolution}' for {dataset.title} dataset. "
381+
f"Invalid resolution '{resolution}' for {dataset.description} dataset. "
392382
f"Available resolutions are: {', '.join(dataset.resolutions)}."
393383
)
394384
resinfo = dataset.resolutions[resolution]
@@ -401,7 +391,7 @@ def _load_remote_dataset(
401391
if registration not in resinfo.registrations:
402392
raise GMTInvalidInput(
403393
f"{registration} registration is not available for the "
404-
f"{resolution} {dataset.title} dataset. Only "
394+
f"{resolution} {dataset.description} dataset. Only "
405395
f"{resinfo.registrations[0]} registration is available."
406396
)
407397
else:
@@ -414,7 +404,7 @@ def _load_remote_dataset(
414404
fname = f"@{dataset_prefix}{resolution}_{registration[0]}"
415405
if resinfo.tiled and region is None:
416406
raise GMTInvalidInput(
417-
f"'region' is required for {dataset.title} resolution '{resolution}'."
407+
f"'region' is required for {dataset.description} resolution '{resolution}'."
418408
)
419409

420410
# Currently, only grids are supported. Will support images in the future.
@@ -434,8 +424,7 @@ def _load_remote_dataset(
434424
grid.encoding["source"] = source
435425

436426
# Add some metadata to the grid
437-
grid.name = dataset.name
438-
grid.attrs["long_name"] = dataset.long_name
427+
grid.attrs["description"] = dataset.description
439428
if dataset.units:
440429
grid.attrs["units"] = dataset.units
441430
for key, value in dataset.extra_attributes.items():

0 commit comments

Comments
 (0)