From e21189d4708143121443eae8f312fb9dfdf11da5 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 13 Dec 2024 16:02:59 +0800 Subject: [PATCH 1/3] _load_remote_dataset: Add the 'kind' attribute to explicitly specify if data is a grid or image --- pygmt/datasets/load_remote_dataset.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index 168a93583b2..c36d7681994 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -48,6 +48,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 +57,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 +76,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 +96,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "earth_faa": GMTRemoteDataset( + kind="grid", description="IGPP Earth free-air anomaly", units="mGal", extra_attributes={"horizontal_datum": "WGS84"}, @@ -111,6 +115,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 +138,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "earth_geoid": GMTRemoteDataset( + kind="grid", description="EGM2008 Earth geoid", units="m", extra_attributes={"horizontal_datum": "WGS84"}, @@ -151,6 +157,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 +180,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "earth_mag": GMTRemoteDataset( + kind="grid", description="EMAG2 Earth Magnetic Anomaly Model", units="nT", extra_attributes={"horizontal_datum": "WGS84"}, @@ -190,6 +198,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "earth_mask": GMTRemoteDataset( + kind="grid", description="GSHHG Earth mask", units=None, extra_attributes={"horizontal_datum": "WGS84"}, @@ -210,6 +219,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 +239,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "earth_vgg": GMTRemoteDataset( + kind="grid", description="IGPP Earth vertical gravity gradient", units="Eotvos", extra_attributes={"horizontal_datum": "WGS84"}, @@ -247,6 +258,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 +275,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "mars_relief": GMTRemoteDataset( + kind="grid", description="NASA Mars (MOLA) relief", units="meters", extra_attributes={}, @@ -284,6 +297,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "moon_relief": GMTRemoteDataset( + kind="grid", description="USGS Moon (LOLA) relief", units="meters", extra_attributes={}, @@ -305,6 +319,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "mercury_relief": GMTRemoteDataset( + kind="grid", description="USGS Mercury relief", units="meters", extra_attributes={}, @@ -324,6 +339,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "pluto_relief": GMTRemoteDataset( + kind="grid", description="USGS Pluto relief", units="meters", extra_attributes={}, @@ -343,6 +359,7 @@ class GMTRemoteDataset(NamedTuple): }, ), "venus_relief": GMTRemoteDataset( + kind="grid", description="NASA Magellan Venus relief", units="meters", extra_attributes={}, @@ -442,15 +459,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 From e9884e4329e9b76a793431bbee25f073d4fb5ecb Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 16 Dec 2024 11:41:34 +0800 Subject: [PATCH 2/3] Update docstrings --- pygmt/datasets/load_remote_dataset.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index c36d7681994..3842ee33b09 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 From 58d7be11e3feaed0a4afa81113a8373aa97bca42 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 16 Dec 2024 19:31:02 +0800 Subject: [PATCH 3/3] Fix styling --- pygmt/datasets/load_remote_dataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index 3842ee33b09..7fdbe5754f7 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -38,7 +38,7 @@ class GMTRemoteDataset(NamedTuple): Attributes ---------- - kind + kind The kind of the dataset source. Valid values are ``"grid"`` and ``"image"``. description The name assigned as an attribute to the DataArray.