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

Merged
merged 6 commits into from
Jan 8, 2025
Merged
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
36 changes: 31 additions & 5 deletions pygmt/datasets/load_remote_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class GMTRemoteDataset(NamedTuple):
Attributes
----------
description
The name assigned as an attribute to the DataArray.
The name assigned as an attribute to the DataArray.
kind
The kind of the dataset source. Valid values are ``"grid"`` and ``"image"``.
units
The units of the values in the DataArray.
resolutions
Expand All @@ -49,6 +51,7 @@ class GMTRemoteDataset(NamedTuple):
"""

description: str
kind: Literal["grid", "image"]
units: str | None
resolutions: dict[str, Resolution]
extra_attributes: dict[str, Any]
Expand All @@ -57,6 +60,7 @@ class GMTRemoteDataset(NamedTuple):
datasets = {
"earth_age": GMTRemoteDataset(
description="EarthByte Earth seafloor crustal age",
kind="grid",
units="Myr",
extra_attributes={"horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -75,6 +79,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_day": GMTRemoteDataset(
description="NASA Day Images",
kind="image",
units=None,
extra_attributes={"long_name": "blue_marble", "horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -94,6 +99,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_dist": GMTRemoteDataset(
description="GSHHG Earth distance to shoreline",
kind="grid",
units="kilometers",
extra_attributes={"horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -112,6 +118,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_edefl": GMTRemoteDataset(
description="IGPP Earth east-west deflection",
kind="grid",
units="micro-radians",
extra_attributes={"horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -130,6 +137,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_faa": GMTRemoteDataset(
description="IGPP Earth free-air anomaly",
kind="grid",
units="mGal",
extra_attributes={"horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -148,6 +156,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_faaerror": GMTRemoteDataset(
description="IGPP Earth free-air anomaly errors",
kind="grid",
units="mGal",
extra_attributes={"horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -166,6 +175,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_gebco": GMTRemoteDataset(
description="GEBCO Earth relief",
kind="grid",
units="meters",
extra_attributes={"vertical_datum": "EGM96", "horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -188,6 +198,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_geoid": GMTRemoteDataset(
description="EGM2008 Earth geoid",
kind="grid",
units="meters",
extra_attributes={"horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -206,6 +217,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_igpp": GMTRemoteDataset(
description="IGPP Earth relief",
kind="grid",
units="meters",
extra_attributes={"vertical_datum": "EGM96", "horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -228,6 +240,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_mag": GMTRemoteDataset(
description="EMAG2 Earth Magnetic Anomaly Model",
kind="grid",
units="nT",
extra_attributes={"horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -245,6 +258,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_mask": GMTRemoteDataset(
description="GSHHG Earth mask",
kind="grid",
units=None,
extra_attributes={"horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -265,6 +279,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_mss": GMTRemoteDataset(
description="CNES Earth mean sea surface",
kind="grid",
units="meters",
extra_attributes={"horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -283,6 +298,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_night": GMTRemoteDataset(
description="NASA Night Images",
kind="image",
units=None,
extra_attributes={"long_name": "black_marble", "horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -302,6 +318,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_mdt": GMTRemoteDataset(
description="CNES Earth mean dynamic topography",
kind="grid",
units="meters",
extra_attributes={"horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -315,6 +332,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_ndefl": GMTRemoteDataset(
description="IGPP Earth north-south deflection",
kind="grid",
units="micro-radians",
extra_attributes={"horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -333,6 +351,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_vgg": GMTRemoteDataset(
description="IGPP Earth vertical gravity gradient",
kind="grid",
units="Eotvos",
extra_attributes={"horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -351,6 +370,7 @@ class GMTRemoteDataset(NamedTuple):
),
"earth_wdmam": GMTRemoteDataset(
description="WDMAM World Digital Magnetic Anomaly Map",
kind="grid",
units="nT",
extra_attributes={"horizontal_datum": "WGS84"},
resolutions={
Expand All @@ -367,6 +387,7 @@ class GMTRemoteDataset(NamedTuple):
),
"mars_relief": GMTRemoteDataset(
description="NASA Mars (MOLA) relief",
kind="grid",
units="meters",
extra_attributes={},
resolutions={
Expand All @@ -388,6 +409,7 @@ class GMTRemoteDataset(NamedTuple):
),
"moon_relief": GMTRemoteDataset(
description="USGS Moon (LOLA) relief",
kind="grid",
units="meters",
extra_attributes={},
resolutions={
Expand All @@ -409,6 +431,7 @@ class GMTRemoteDataset(NamedTuple):
),
"mercury_relief": GMTRemoteDataset(
description="USGS Mercury relief",
kind="grid",
units="meters",
extra_attributes={},
resolutions={
Expand All @@ -428,6 +451,7 @@ class GMTRemoteDataset(NamedTuple):
),
"pluto_relief": GMTRemoteDataset(
description="USGS Pluto relief",
kind="grid",
units="meters",
extra_attributes={},
resolutions={
Expand All @@ -447,6 +471,7 @@ class GMTRemoteDataset(NamedTuple):
),
"venus_relief": GMTRemoteDataset(
description="NASA Magellan Venus relief",
kind="grid",
units="meters",
extra_attributes={},
resolutions={
Expand Down Expand Up @@ -545,15 +570,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