Skip to content

Commit aeaf33f

Browse files
authored
_load_remote_dataset: Add the "kind" attribute to explicitly specify if data is a grid or image (#3688)
1 parent 448e44c commit aeaf33f

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

pygmt/datasets/load_remote_dataset.py

+31-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ class GMTRemoteDataset(NamedTuple):
3939
Attributes
4040
----------
4141
description
42-
The name assigned as an attribute to the DataArray.
42+
The name assigned as an attribute to the DataArray.
43+
kind
44+
The kind of the dataset source. Valid values are ``"grid"`` and ``"image"``.
4345
units
4446
The units of the values in the DataArray.
4547
resolutions
@@ -49,6 +51,7 @@ class GMTRemoteDataset(NamedTuple):
4951
"""
5052

5153
description: str
54+
kind: Literal["grid", "image"]
5255
units: str | None
5356
resolutions: dict[str, Resolution]
5457
extra_attributes: dict[str, Any]
@@ -57,6 +60,7 @@ class GMTRemoteDataset(NamedTuple):
5760
datasets = {
5861
"earth_age": GMTRemoteDataset(
5962
description="EarthByte Earth seafloor crustal age",
63+
kind="grid",
6064
units="Myr",
6165
extra_attributes={"horizontal_datum": "WGS84"},
6266
resolutions={
@@ -75,6 +79,7 @@ class GMTRemoteDataset(NamedTuple):
7579
),
7680
"earth_day": GMTRemoteDataset(
7781
description="NASA Day Images",
82+
kind="image",
7883
units=None,
7984
extra_attributes={"long_name": "blue_marble", "horizontal_datum": "WGS84"},
8085
resolutions={
@@ -94,6 +99,7 @@ class GMTRemoteDataset(NamedTuple):
9499
),
95100
"earth_dist": GMTRemoteDataset(
96101
description="GSHHG Earth distance to shoreline",
102+
kind="grid",
97103
units="kilometers",
98104
extra_attributes={"horizontal_datum": "WGS84"},
99105
resolutions={
@@ -112,6 +118,7 @@ class GMTRemoteDataset(NamedTuple):
112118
),
113119
"earth_edefl": GMTRemoteDataset(
114120
description="IGPP Earth east-west deflection",
121+
kind="grid",
115122
units="micro-radians",
116123
extra_attributes={"horizontal_datum": "WGS84"},
117124
resolutions={
@@ -130,6 +137,7 @@ class GMTRemoteDataset(NamedTuple):
130137
),
131138
"earth_faa": GMTRemoteDataset(
132139
description="IGPP Earth free-air anomaly",
140+
kind="grid",
133141
units="mGal",
134142
extra_attributes={"horizontal_datum": "WGS84"},
135143
resolutions={
@@ -148,6 +156,7 @@ class GMTRemoteDataset(NamedTuple):
148156
),
149157
"earth_faaerror": GMTRemoteDataset(
150158
description="IGPP Earth free-air anomaly errors",
159+
kind="grid",
151160
units="mGal",
152161
extra_attributes={"horizontal_datum": "WGS84"},
153162
resolutions={
@@ -166,6 +175,7 @@ class GMTRemoteDataset(NamedTuple):
166175
),
167176
"earth_gebco": GMTRemoteDataset(
168177
description="GEBCO Earth relief",
178+
kind="grid",
169179
units="meters",
170180
extra_attributes={"vertical_datum": "EGM96", "horizontal_datum": "WGS84"},
171181
resolutions={
@@ -188,6 +198,7 @@ class GMTRemoteDataset(NamedTuple):
188198
),
189199
"earth_geoid": GMTRemoteDataset(
190200
description="EGM2008 Earth geoid",
201+
kind="grid",
191202
units="meters",
192203
extra_attributes={"horizontal_datum": "WGS84"},
193204
resolutions={
@@ -206,6 +217,7 @@ class GMTRemoteDataset(NamedTuple):
206217
),
207218
"earth_igpp": GMTRemoteDataset(
208219
description="IGPP Earth relief",
220+
kind="grid",
209221
units="meters",
210222
extra_attributes={"vertical_datum": "EGM96", "horizontal_datum": "WGS84"},
211223
resolutions={
@@ -228,6 +240,7 @@ class GMTRemoteDataset(NamedTuple):
228240
),
229241
"earth_mag": GMTRemoteDataset(
230242
description="EMAG2 Earth Magnetic Anomaly Model",
243+
kind="grid",
231244
units="nT",
232245
extra_attributes={"horizontal_datum": "WGS84"},
233246
resolutions={
@@ -245,6 +258,7 @@ class GMTRemoteDataset(NamedTuple):
245258
),
246259
"earth_mask": GMTRemoteDataset(
247260
description="GSHHG Earth mask",
261+
kind="grid",
248262
units=None,
249263
extra_attributes={"horizontal_datum": "WGS84"},
250264
resolutions={
@@ -265,6 +279,7 @@ class GMTRemoteDataset(NamedTuple):
265279
),
266280
"earth_mss": GMTRemoteDataset(
267281
description="CNES Earth mean sea surface",
282+
kind="grid",
268283
units="meters",
269284
extra_attributes={"horizontal_datum": "WGS84"},
270285
resolutions={
@@ -283,6 +298,7 @@ class GMTRemoteDataset(NamedTuple):
283298
),
284299
"earth_night": GMTRemoteDataset(
285300
description="NASA Night Images",
301+
kind="image",
286302
units=None,
287303
extra_attributes={"long_name": "black_marble", "horizontal_datum": "WGS84"},
288304
resolutions={
@@ -302,6 +318,7 @@ class GMTRemoteDataset(NamedTuple):
302318
),
303319
"earth_mdt": GMTRemoteDataset(
304320
description="CNES Earth mean dynamic topography",
321+
kind="grid",
305322
units="meters",
306323
extra_attributes={"horizontal_datum": "WGS84"},
307324
resolutions={
@@ -315,6 +332,7 @@ class GMTRemoteDataset(NamedTuple):
315332
),
316333
"earth_ndefl": GMTRemoteDataset(
317334
description="IGPP Earth north-south deflection",
335+
kind="grid",
318336
units="micro-radians",
319337
extra_attributes={"horizontal_datum": "WGS84"},
320338
resolutions={
@@ -333,6 +351,7 @@ class GMTRemoteDataset(NamedTuple):
333351
),
334352
"earth_vgg": GMTRemoteDataset(
335353
description="IGPP Earth vertical gravity gradient",
354+
kind="grid",
336355
units="Eotvos",
337356
extra_attributes={"horizontal_datum": "WGS84"},
338357
resolutions={
@@ -351,6 +370,7 @@ class GMTRemoteDataset(NamedTuple):
351370
),
352371
"earth_wdmam": GMTRemoteDataset(
353372
description="WDMAM World Digital Magnetic Anomaly Map",
373+
kind="grid",
354374
units="nT",
355375
extra_attributes={"horizontal_datum": "WGS84"},
356376
resolutions={
@@ -367,6 +387,7 @@ class GMTRemoteDataset(NamedTuple):
367387
),
368388
"mars_relief": GMTRemoteDataset(
369389
description="NASA Mars (MOLA) relief",
390+
kind="grid",
370391
units="meters",
371392
extra_attributes={},
372393
resolutions={
@@ -388,6 +409,7 @@ class GMTRemoteDataset(NamedTuple):
388409
),
389410
"moon_relief": GMTRemoteDataset(
390411
description="USGS Moon (LOLA) relief",
412+
kind="grid",
391413
units="meters",
392414
extra_attributes={},
393415
resolutions={
@@ -409,6 +431,7 @@ class GMTRemoteDataset(NamedTuple):
409431
),
410432
"mercury_relief": GMTRemoteDataset(
411433
description="USGS Mercury relief",
434+
kind="grid",
412435
units="meters",
413436
extra_attributes={},
414437
resolutions={
@@ -428,6 +451,7 @@ class GMTRemoteDataset(NamedTuple):
428451
),
429452
"pluto_relief": GMTRemoteDataset(
430453
description="USGS Pluto relief",
454+
kind="grid",
431455
units="meters",
432456
extra_attributes={},
433457
resolutions={
@@ -447,6 +471,7 @@ class GMTRemoteDataset(NamedTuple):
447471
),
448472
"venus_relief": GMTRemoteDataset(
449473
description="NASA Magellan Venus relief",
474+
kind="grid",
450475
units="meters",
451476
extra_attributes={},
452477
resolutions={
@@ -545,15 +570,16 @@ def _load_remote_dataset(
545570
raise GMTInvalidInput(msg)
546571

547572
fname = f"@{prefix}_{resolution}_{reg}"
548-
kind = "image" if name in {"earth_day", "earth_night"} else "grid"
549-
kwdict = {"R": region, "T": {"grid": "g", "image": "i"}[kind]}
573+
kwdict = {"R": region, "T": {"grid": "g", "image": "i"}[dataset.kind]}
550574
with Session() as lib:
551-
with lib.virtualfile_out(kind=kind) as voutgrd:
575+
with lib.virtualfile_out(kind=dataset.kind) as voutgrd:
552576
lib.call_module(
553577
module="read",
554578
args=[fname, voutgrd, *build_arg_list(kwdict)],
555579
)
556-
grid = lib.virtualfile_to_raster(kind=kind, outgrid=None, vfname=voutgrd)
580+
grid = lib.virtualfile_to_raster(
581+
kind=dataset.kind, outgrid=None, vfname=voutgrd
582+
)
557583

558584
# Full path to the grid if not tiled grids.
559585
source = which(fname, download="a") if not resinfo.tiled else None

0 commit comments

Comments
 (0)