diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index 168a93583b2..7fdbe5754f7 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -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 @@ -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] @@ -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"}, @@ -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"}, @@ -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"}, @@ -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"}, @@ -133,6 +140,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "earth_geoid": GMTRemoteDataset( + kind="grid", description="EGM2008 Earth geoid", units="m", extra_attributes={"horizontal_datum": "WGS84"}, @@ -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"}, @@ -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"}, @@ -190,6 +200,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "earth_mask": GMTRemoteDataset( + kind="grid", description="GSHHG Earth mask", units=None, extra_attributes={"horizontal_datum": "WGS84"}, @@ -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"}, @@ -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"}, @@ -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"}, @@ -263,6 +277,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "mars_relief": GMTRemoteDataset( + kind="grid", description="NASA Mars (MOLA) relief", units="meters", extra_attributes={}, @@ -284,6 +299,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "moon_relief": GMTRemoteDataset( + kind="grid", description="USGS Moon (LOLA) relief", units="meters", extra_attributes={}, @@ -305,6 +321,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "mercury_relief": GMTRemoteDataset( + kind="grid", description="USGS Mercury relief", units="meters", extra_attributes={}, @@ -324,6 +341,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "pluto_relief": GMTRemoteDataset( + kind="grid", description="USGS Pluto relief", units="meters", extra_attributes={}, @@ -343,6 +361,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "venus_relief": GMTRemoteDataset( + kind="grid", description="NASA Magellan Venus relief", units="meters", extra_attributes={}, @@ -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