Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_load_remote_dataset: Add the 'kind' attribute to explicitly specify if data is a grid or image #3688

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions pygmt/datasets/load_remote_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class GMTRemoteDataset(NamedTuple):

Attributes
----------
kind
The kind of the dataset source. Valid values are ``"grid"`` and ``"image"``.
description
The name assigned as an attribute to the DataArray.
The name assigned as an attribute to the DataArray.
units
The units of the values in the DataArray.
resolutions
Expand All @@ -48,6 +50,7 @@ class GMTRemoteDataset(NamedTuple):
A dictionary of extra or unique attributes of the dataset.
"""

kind: Literal["grid", "image"]
description: str
units: str | None
resolutions: dict[str, Resolution]
Expand All @@ -56,6 +59,7 @@ class GMTRemoteDataset(NamedTuple):

datasets = {
"earth_age": GMTRemoteDataset(
kind="grid",
description="EarthByte Earth seafloor crustal age",
units="Myr",
extra_attributes={"horizontal_datum": "WGS84"},
Expand All @@ -74,6 +78,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"earth_day": GMTRemoteDataset(
kind="image",
description="NASA Day Images",
units=None,
extra_attributes={"long_name": "blue_marble", "horizontal_datum": "WGS84"},
Expand All @@ -93,6 +98,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"earth_faa": GMTRemoteDataset(
kind="grid",
description="IGPP Earth free-air anomaly",
units="mGal",
extra_attributes={"horizontal_datum": "WGS84"},
Expand All @@ -111,6 +117,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"earth_gebco": GMTRemoteDataset(
kind="grid",
description="GEBCO Earth relief",
units="meters",
extra_attributes={"vertical_datum": "EGM96", "horizontal_datum": "WGS84"},
Expand All @@ -133,6 +140,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"earth_geoid": GMTRemoteDataset(
kind="grid",
description="EGM2008 Earth geoid",
units="m",
extra_attributes={"horizontal_datum": "WGS84"},
Expand All @@ -151,6 +159,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"earth_igpp": GMTRemoteDataset(
kind="grid",
description="IGPP Earth relief",
units="meters",
extra_attributes={"vertical_datum": "EGM96", "horizontal_datum": "WGS84"},
Expand All @@ -173,6 +182,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"earth_mag": GMTRemoteDataset(
kind="grid",
description="EMAG2 Earth Magnetic Anomaly Model",
units="nT",
extra_attributes={"horizontal_datum": "WGS84"},
Expand All @@ -190,6 +200,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"earth_mask": GMTRemoteDataset(
kind="grid",
description="GSHHG Earth mask",
units=None,
extra_attributes={"horizontal_datum": "WGS84"},
Expand All @@ -210,6 +221,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"earth_night": GMTRemoteDataset(
kind="image",
description="NASA Night Images",
units=None,
extra_attributes={"long_name": "black_marble", "horizontal_datum": "WGS84"},
Expand All @@ -229,6 +241,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"earth_vgg": GMTRemoteDataset(
kind="grid",
description="IGPP Earth vertical gravity gradient",
units="Eotvos",
extra_attributes={"horizontal_datum": "WGS84"},
Expand All @@ -247,6 +260,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"earth_wdmam": GMTRemoteDataset(
kind="grid",
description="WDMAM World Digital Magnetic Anomaly Map",
units="nT",
extra_attributes={"horizontal_datum": "WGS84"},
Expand All @@ -263,6 +277,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"mars_relief": GMTRemoteDataset(
kind="grid",
description="NASA Mars (MOLA) relief",
units="meters",
extra_attributes={},
Expand All @@ -284,6 +299,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"moon_relief": GMTRemoteDataset(
kind="grid",
description="USGS Moon (LOLA) relief",
units="meters",
extra_attributes={},
Expand All @@ -305,6 +321,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"mercury_relief": GMTRemoteDataset(
kind="grid",
description="USGS Mercury relief",
units="meters",
extra_attributes={},
Expand All @@ -324,6 +341,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"pluto_relief": GMTRemoteDataset(
kind="grid",
description="USGS Pluto relief",
units="meters",
extra_attributes={},
Expand All @@ -343,6 +361,7 @@ class GMTRemoteDataset(NamedTuple):
},
),
"venus_relief": GMTRemoteDataset(
kind="grid",
description="NASA Magellan Venus relief",
units="meters",
extra_attributes={},
Expand Down Expand Up @@ -442,15 +461,16 @@ def _load_remote_dataset(
raise GMTInvalidInput(msg)

fname = f"@{prefix}_{resolution}_{reg}"
kind = "image" if name in {"earth_day", "earth_night"} else "grid"
kwdict = {"R": region, "T": {"grid": "g", "image": "i"}[kind]}
kwdict = {"R": region, "T": {"grid": "g", "image": "i"}[dataset.kind]}
with Session() as lib:
with lib.virtualfile_out(kind=kind) as voutgrd:
with lib.virtualfile_out(kind=dataset.kind) as voutgrd:
lib.call_module(
module="read",
args=[fname, voutgrd, *build_arg_list(kwdict)],
)
grid = lib.virtualfile_to_raster(kind=kind, outgrid=None, vfname=voutgrd)
grid = lib.virtualfile_to_raster(
kind=dataset.kind, outgrid=None, vfname=voutgrd
)

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