From 6eee89e36ea93241479f38f11ad3ecea139acf3f Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 27 Dec 2023 00:17:32 +0800 Subject: [PATCH 01/10] Refactor the internal _load_remote_dataset function to simplify the dataset definitions --- pygmt/datasets/load_remote_dataset.py | 339 +++++++++++++------------- 1 file changed, 171 insertions(+), 168 deletions(-) diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index 6f75946aea8..72730dd55c4 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -3,7 +3,7 @@ """ from __future__ import annotations -from typing import NamedTuple +from typing import ClassVar, NamedTuple from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import kwargs_to_strings @@ -27,8 +27,9 @@ class Resolution(NamedTuple): argument for ``region``. """ - registrations: list - tiled: bool + code : str + registrations: ClassVar = ["gridline", "pixel"] + tiled: bool = False class GMTRemoteDataset(NamedTuple): @@ -61,7 +62,7 @@ class GMTRemoteDataset(NamedTuple): name: str long_name: str units: str | None - resolutions: dict[str, Resolution] + resolutions: [Resolution] extra_attributes: dict @@ -72,163 +73,163 @@ class GMTRemoteDataset(NamedTuple): long_name="age of seafloor crust", units="Myr", extra_attributes={"horizontal_datum": "WGS84"}, - resolutions={ - "01d": Resolution(["gridline", "pixel"], False), - "30m": Resolution(["gridline", "pixel"], False), - "20m": Resolution(["gridline", "pixel"], False), - "15m": Resolution(["gridline", "pixel"], False), - "10m": Resolution(["gridline", "pixel"], False), - "06m": Resolution(["gridline", "pixel"], False), - "05m": Resolution(["gridline", "pixel"], True), - "04m": Resolution(["gridline", "pixel"], True), - "03m": Resolution(["gridline", "pixel"], True), - "02m": Resolution(["gridline", "pixel"], True), - "01m": Resolution(["gridline"], True), - }, - ), - "earth_free_air_anomaly": GMTRemoteDataset( - title="free air anomaly", - name="free_air_anomaly", - long_name="IGPP Earth Free-Air Anomaly", - units="mGal", - extra_attributes={"horizontal_datum": "WGS84"}, - resolutions={ - "01d": Resolution(["gridline", "pixel"], False), - "30m": Resolution(["gridline", "pixel"], False), - "20m": Resolution(["gridline", "pixel"], False), - "15m": Resolution(["gridline", "pixel"], False), - "10m": Resolution(["gridline", "pixel"], False), - "06m": Resolution(["gridline", "pixel"], False), - "05m": Resolution(["gridline", "pixel"], True), - "04m": Resolution(["gridline", "pixel"], True), - "03m": Resolution(["gridline", "pixel"], True), - "02m": Resolution(["gridline", "pixel"], True), - "01m": Resolution(["pixel"], True), - }, - ), - "earth_geoid": GMTRemoteDataset( - title="Earth geoid", - name="earth_geoid", - long_name="EGM2008 Earth Geoid", - units="m", - extra_attributes={"horizontal_datum": "WGS84"}, - resolutions={ - "01d": Resolution(["gridline", "pixel"], False), - "30m": Resolution(["gridline", "pixel"], False), - "20m": Resolution(["gridline", "pixel"], False), - "15m": Resolution(["gridline", "pixel"], False), - "10m": Resolution(["gridline", "pixel"], False), - "06m": Resolution(["gridline", "pixel"], False), - "05m": Resolution(["gridline", "pixel"], True), - "04m": Resolution(["gridline", "pixel"], True), - "03m": Resolution(["gridline", "pixel"], True), - "02m": Resolution(["gridline", "pixel"], True), - "01m": Resolution(["gridline"], True), - }, - ), - "earth_magnetic_anomaly": GMTRemoteDataset( - title="Earth magnetic anomaly", - name="magnetic_anomaly", - long_name="Earth magnetic anomaly", - units="nT", - extra_attributes={"horizontal_datum": "WGS84"}, - resolutions={ - "01d": Resolution(["gridline", "pixel"], False), - "30m": Resolution(["gridline", "pixel"], False), - "20m": Resolution(["gridline", "pixel"], False), - "15m": Resolution(["gridline", "pixel"], False), - "10m": Resolution(["gridline", "pixel"], False), - "06m": Resolution(["gridline", "pixel"], False), - "05m": Resolution(["gridline", "pixel"], True), - "04m": Resolution(["gridline", "pixel"], True), - "03m": Resolution(["gridline", "pixel"], True), - "02m": Resolution(["pixel"], True), - }, - ), - "earth_mask": GMTRemoteDataset( - title="Earth mask", - name="earth_mask", - long_name="Mask of land and water features", - units=None, - extra_attributes={"horizontal_datum": "WGS84"}, - resolutions={ - "01d": Resolution(["gridline", "pixel"], False), - "30m": Resolution(["gridline", "pixel"], False), - "20m": Resolution(["gridline", "pixel"], False), - "15m": Resolution(["gridline", "pixel"], False), - "10m": Resolution(["gridline", "pixel"], False), - "06m": Resolution(["gridline", "pixel"], False), - "05m": Resolution(["gridline", "pixel"], False), - "04m": Resolution(["gridline", "pixel"], False), - "03m": Resolution(["gridline", "pixel"], False), - "02m": Resolution(["gridline", "pixel"], False), - "01m": Resolution(["gridline", "pixel"], False), - "30s": Resolution(["gridline", "pixel"], False), - "15s": Resolution(["gridline", "pixel"], False), - }, - ), - "earth_relief": GMTRemoteDataset( - title="Earth relief", - name="elevation", - long_name="Earth elevation relative to the geoid", - units="meters", - extra_attributes={"vertical_datum": "EGM96", "horizontal_datum": "WGS84"}, - resolutions={ - "01d": Resolution(["gridline", "pixel"], False), - "30m": Resolution(["gridline", "pixel"], False), - "20m": Resolution(["gridline", "pixel"], False), - "15m": Resolution(["gridline", "pixel"], False), - "10m": Resolution(["gridline", "pixel"], False), - "06m": Resolution(["gridline", "pixel"], False), - "05m": Resolution(["gridline", "pixel"], True), - "04m": Resolution(["gridline", "pixel"], True), - "03m": Resolution(["gridline", "pixel"], True), - "02m": Resolution(["gridline", "pixel"], True), - "01m": Resolution(["gridline", "pixel"], True), - "30s": Resolution(["gridline", "pixel"], True), - "15s": Resolution(["pixel"], True), - "03s": Resolution(["gridline"], True), - "01s": Resolution(["gridline"], True), - }, - ), - "earth_vgg": GMTRemoteDataset( - title="Earth vertical gravity gradient", - name="earth_vgg", - long_name="IGPP Earth Vertical Gravity Gradient", - units="Eotvos", - extra_attributes={"horizontal_datum": "WGS84"}, - resolutions={ - "01d": Resolution(["gridline", "pixel"], False), - "30m": Resolution(["gridline", "pixel"], False), - "20m": Resolution(["gridline", "pixel"], False), - "15m": Resolution(["gridline", "pixel"], False), - "10m": Resolution(["gridline", "pixel"], False), - "06m": Resolution(["gridline", "pixel"], False), - "05m": Resolution(["gridline", "pixel"], True), - "04m": Resolution(["gridline", "pixel"], True), - "03m": Resolution(["gridline", "pixel"], True), - "02m": Resolution(["gridline", "pixel"], True), - "01m": Resolution(["pixel"], True), - }, - ), - "earth_wdmam": GMTRemoteDataset( - title="WDMAM magnetic anomaly", - name="wdmam", - long_name="World Digital Magnetic Anomaly Map", - units="nT", - extra_attributes={"horizontal_datum": "WGS84"}, - resolutions={ - "01d": Resolution(["gridline", "pixel"], False), - "30m": Resolution(["gridline", "pixel"], False), - "20m": Resolution(["gridline", "pixel"], False), - "15m": Resolution(["gridline", "pixel"], False), - "10m": Resolution(["gridline", "pixel"], False), - "06m": Resolution(["gridline", "pixel"], False), - "05m": Resolution(["gridline", "pixel"], True), - "04m": Resolution(["gridline", "pixel"], True), - "03m": Resolution(["gridline"], True), - }, + resolutions=[ + Resolution("01d"), + Resolution("30m"), + Resolution("20m"), + Resolution("15m"), + Resolution("10m"), + Resolution("06m"), + Resolution("05m", tiled=True), + Resolution("04m", tiled=True), + Resolution("03m", tiled=True), + Resolution("02m", tiled=True), + Resolution("01m", registrations=["gridline"], tiled=True), + ] ), + # "earth_free_air_anomaly": GMTRemoteDataset( + # title="free air anomaly", + # name="free_air_anomaly", + # long_name="IGPP Earth Free-Air Anomaly", + # units="mGal", + # extra_attributes={"horizontal_datum": "WGS84"}, + # resolutions={ + # "01d": Resolution(["gridline", "pixel"], False), + # "30m": Resolution(["gridline", "pixel"], False), + # "20m": Resolution(["gridline", "pixel"], False), + # "15m": Resolution(["gridline", "pixel"], False), + # "10m": Resolution(["gridline", "pixel"], False), + # "06m": Resolution(["gridline", "pixel"], False), + # "05m": Resolution(["gridline", "pixel"], True), + # "04m": Resolution(["gridline", "pixel"], True), + # "03m": Resolution(["gridline", "pixel"], True), + # "02m": Resolution(["gridline", "pixel"], True), + # "01m": Resolution(["pixel"], True), + # }, + # ), + # "earth_geoid": GMTRemoteDataset( + # title="Earth geoid", + # name="earth_geoid", + # long_name="EGM2008 Earth Geoid", + # units="m", + # extra_attributes={"horizontal_datum": "WGS84"}, + # resolutions={ + # "01d": Resolution(["gridline", "pixel"], False), + # "30m": Resolution(["gridline", "pixel"], False), + # "20m": Resolution(["gridline", "pixel"], False), + # "15m": Resolution(["gridline", "pixel"], False), + # "10m": Resolution(["gridline", "pixel"], False), + # "06m": Resolution(["gridline", "pixel"], False), + # "05m": Resolution(["gridline", "pixel"], True), + # "04m": Resolution(["gridline", "pixel"], True), + # "03m": Resolution(["gridline", "pixel"], True), + # "02m": Resolution(["gridline", "pixel"], True), + # "01m": Resolution(["gridline"], True), + # }, + # ), + # "earth_magnetic_anomaly": GMTRemoteDataset( + # title="Earth magnetic anomaly", + # name="magnetic_anomaly", + # long_name="Earth magnetic anomaly", + # units="nT", + # extra_attributes={"horizontal_datum": "WGS84"}, + # resolutions={ + # "01d": Resolution(["gridline", "pixel"], False), + # "30m": Resolution(["gridline", "pixel"], False), + # "20m": Resolution(["gridline", "pixel"], False), + # "15m": Resolution(["gridline", "pixel"], False), + # "10m": Resolution(["gridline", "pixel"], False), + # "06m": Resolution(["gridline", "pixel"], False), + # "05m": Resolution(["gridline", "pixel"], True), + # "04m": Resolution(["gridline", "pixel"], True), + # "03m": Resolution(["gridline", "pixel"], True), + # "02m": Resolution(["pixel"], True), + # }, + # ), + # "earth_mask": GMTRemoteDataset( + # title="Earth mask", + # name="earth_mask", + # long_name="Mask of land and water features", + # units=None, + # extra_attributes={"horizontal_datum": "WGS84"}, + # resolutions={ + # "01d": Resolution(["gridline", "pixel"], False), + # "30m": Resolution(["gridline", "pixel"], False), + # "20m": Resolution(["gridline", "pixel"], False), + # "15m": Resolution(["gridline", "pixel"], False), + # "10m": Resolution(["gridline", "pixel"], False), + # "06m": Resolution(["gridline", "pixel"], False), + # "05m": Resolution(["gridline", "pixel"], False), + # "04m": Resolution(["gridline", "pixel"], False), + # "03m": Resolution(["gridline", "pixel"], False), + # "02m": Resolution(["gridline", "pixel"], False), + # "01m": Resolution(["gridline", "pixel"], False), + # "30s": Resolution(["gridline", "pixel"], False), + # "15s": Resolution(["gridline", "pixel"], False), + # }, + # ), + # "earth_relief": GMTRemoteDataset( + # title="Earth relief", + # name="elevation", + # long_name="Earth elevation relative to the geoid", + # units="meters", + # extra_attributes={"vertical_datum": "EGM96", "horizontal_datum": "WGS84"}, + # resolutions={ + # "01d": Resolution(["gridline", "pixel"], False), + # "30m": Resolution(["gridline", "pixel"], False), + # "20m": Resolution(["gridline", "pixel"], False), + # "15m": Resolution(["gridline", "pixel"], False), + # "10m": Resolution(["gridline", "pixel"], False), + # "06m": Resolution(["gridline", "pixel"], False), + # "05m": Resolution(["gridline", "pixel"], True), + # "04m": Resolution(["gridline", "pixel"], True), + # "03m": Resolution(["gridline", "pixel"], True), + # "02m": Resolution(["gridline", "pixel"], True), + # "01m": Resolution(["gridline", "pixel"], True), + # "30s": Resolution(["gridline", "pixel"], True), + # "15s": Resolution(["pixel"], True), + # "03s": Resolution(["gridline"], True), + # "01s": Resolution(["gridline"], True), + # }, + # ), + # "earth_vgg": GMTRemoteDataset( + # title="Earth vertical gravity gradient", + # name="earth_vgg", + # long_name="IGPP Earth Vertical Gravity Gradient", + # units="Eotvos", + # extra_attributes={"horizontal_datum": "WGS84"}, + # resolutions={ + # "01d": Resolution(["gridline", "pixel"], False), + # "30m": Resolution(["gridline", "pixel"], False), + # "20m": Resolution(["gridline", "pixel"], False), + # "15m": Resolution(["gridline", "pixel"], False), + # "10m": Resolution(["gridline", "pixel"], False), + # "06m": Resolution(["gridline", "pixel"], False), + # "05m": Resolution(["gridline", "pixel"], True), + # "04m": Resolution(["gridline", "pixel"], True), + # "03m": Resolution(["gridline", "pixel"], True), + # "02m": Resolution(["gridline", "pixel"], True), + # "01m": Resolution(["pixel"], True), + # }, + # ), + # "earth_wdmam": GMTRemoteDataset( + # title="WDMAM magnetic anomaly", + # name="wdmam", + # long_name="World Digital Magnetic Anomaly Map", + # units="nT", + # extra_attributes={"horizontal_datum": "WGS84"}, + # resolutions={ + # "01d": Resolution(["gridline", "pixel"], False), + # "30m": Resolution(["gridline", "pixel"], False), + # "20m": Resolution(["gridline", "pixel"], False), + # "15m": Resolution(["gridline", "pixel"], False), + # "10m": Resolution(["gridline", "pixel"], False), + # "06m": Resolution(["gridline", "pixel"], False), + # "05m": Resolution(["gridline", "pixel"], True), + # "04m": Resolution(["gridline", "pixel"], True), + # "03m": Resolution(["gridline"], True), + # }, + # ), } @@ -275,22 +276,24 @@ def _load_remote_dataset( dataset = datasets[dataset_name] # check resolution - if resolution not in dataset.resolutions: + for res in dataset.resolutions: + if res.code == resolution: + valid_registrations = res.registrations + is_tiled = res.tiled + break + else: raise GMTInvalidInput(f"Invalid resolution '{resolution}'.") # check registration if registration is None: # use gridline registration unless only pixel registration is available - registration = "gridline" - if "gridline" not in dataset.resolutions[resolution].registrations: - registration = "pixel" + registration = "gridline" if "gridline" in valid_registrations else "pixel" elif registration in ("pixel", "gridline"): - if registration not in dataset.resolutions[resolution].registrations: + if registration not in valid_registrations: raise GMTInvalidInput( f"{registration} registration is not available for the " f"{resolution} {dataset.title} dataset. Only " - f"{dataset.resolutions[resolution].registrations[0]}" - " registration is available." + f"{valid_registrations[0]} registration is available." ) else: raise GMTInvalidInput( @@ -305,7 +308,7 @@ def _load_remote_dataset( # Known issue: tiled grids don't support slice operation # See https://github.com/GenericMappingTools/pygmt/issues/524 if region is None: - if dataset.resolutions[resolution].tiled: + if is_tiled: raise GMTInvalidInput( f"'region' is required for {dataset.title} resolution '{resolution}'." ) From dc701277e7feaf0734e73849c81178b8d7d5d721 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 27 Dec 2023 13:03:54 +0800 Subject: [PATCH 02/10] Update all datasets --- pygmt/datasets/load_remote_dataset.py | 307 +++++++++++++------------- 1 file changed, 151 insertions(+), 156 deletions(-) diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index 72730dd55c4..a3df3dfe8e4 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -18,16 +18,17 @@ class Resolution(NamedTuple): Attributes ---------- + code : str + The resolution code. registrations : list A list of the accepted registrations for a given resolution. Can be either "pixel" or "gridline". - tiled : bool States if the given resolution is tiled, which requires an argument for ``region``. """ - code : str + code: str registrations: ClassVar = ["gridline", "pixel"] tiled: bool = False @@ -40,20 +41,14 @@ class GMTRemoteDataset(NamedTuple): ---------- title : str The title of the dataset, used in error messages. - name : str The name assigned as an attribute to the DataArray. - long_name : str The long name assigned as an attribute to the DataArray. - units : str The units of the values in the DataArray. - - resolutions : dict - Dictionary of available resolution as keys and the values are - Resolution objects. - + resolutions : list + List of Resolution objects. extra_attributes : dict A dictionary of extra or unique attributes of the dataset. """ @@ -62,7 +57,7 @@ class GMTRemoteDataset(NamedTuple): name: str long_name: str units: str | None - resolutions: [Resolution] + resolutions: list[Resolution] extra_attributes: dict @@ -85,156 +80,156 @@ class GMTRemoteDataset(NamedTuple): Resolution("03m", tiled=True), Resolution("02m", tiled=True), Resolution("01m", registrations=["gridline"], tiled=True), - ] + ], + ), + "earth_free_air_anomaly": GMTRemoteDataset( + title="free air anomaly", + name="free_air_anomaly", + long_name="IGPP Earth Free-Air Anomaly", + units="mGal", + extra_attributes={"horizontal_datum": "WGS84"}, + resolutions=[ + Resolution("01d"), + Resolution("30m"), + Resolution("20m"), + Resolution("15m"), + Resolution("10m"), + Resolution("06m"), + Resolution("05m", tiled=True), + Resolution("04m", tiled=True), + Resolution("03m", tiled=True), + Resolution("02m", tiled=True), + Resolution("01m", registrations=["pixel"], tiled=True), + ], + ), + "earth_geoid": GMTRemoteDataset( + title="Earth geoid", + name="earth_geoid", + long_name="EGM2008 Earth Geoid", + units="m", + extra_attributes={"horizontal_datum": "WGS84"}, + resolutions=[ + Resolution("01d"), + Resolution("30m"), + Resolution("20m"), + Resolution("15m"), + Resolution("10m"), + Resolution("06m"), + Resolution("05m", tiled=True), + Resolution("04m", tiled=True), + Resolution("03m", tiled=True), + Resolution("02m", tiled=True), + Resolution("01m", registrations=["gridline"], tiled=True), + ], + ), + "earth_magnetic_anomaly": GMTRemoteDataset( + title="Earth magnetic anomaly", + name="magnetic_anomaly", + long_name="Earth magnetic anomaly", + units="nT", + extra_attributes={"horizontal_datum": "WGS84"}, + resolutions=[ + Resolution("01d"), + Resolution("30m"), + Resolution("20m"), + Resolution("15m"), + Resolution("10m"), + Resolution("06m"), + Resolution("05m", tiled=True), + Resolution("04m", tiled=True), + Resolution("03m", tiled=True), + Resolution("02m", registrations=["pixel"], tiled=True), + ], + ), + "earth_mask": GMTRemoteDataset( + title="Earth mask", + name="earth_mask", + long_name="Mask of land and water features", + units=None, + extra_attributes={"horizontal_datum": "WGS84"}, + resolutions=[ + Resolution("01d"), + Resolution("30m"), + Resolution("20m"), + Resolution("15m"), + Resolution("10m"), + Resolution("06m"), + Resolution("05m"), + Resolution("04m"), + Resolution("03m"), + Resolution("02m"), + Resolution("01m"), + Resolution("30s"), + Resolution("15s"), + ], + ), + "earth_relief": GMTRemoteDataset( + title="Earth relief", + name="elevation", + long_name="Earth elevation relative to the geoid", + units="meters", + extra_attributes={"vertical_datum": "EGM96", "horizontal_datum": "WGS84"}, + resolutions=[ + Resolution("01d"), + Resolution("30m"), + Resolution("20m"), + Resolution("15m"), + Resolution("10m"), + Resolution("06m"), + Resolution("05m", tiled=True), + Resolution("04m", tiled=True), + Resolution("03m", tiled=True), + Resolution("02m", tiled=True), + Resolution("01m", tiled=True), + Resolution("30s", tiled=True), + Resolution("15s", registrations=["pixel"], tiled=True), + Resolution("03s", registrations=["gridline"], tiled=True), + Resolution("01s", registrations=["gridline"], tiled=True), + ], + ), + "earth_vgg": GMTRemoteDataset( + title="Earth vertical gravity gradient", + name="earth_vgg", + long_name="IGPP Earth Vertical Gravity Gradient", + units="Eotvos", + extra_attributes={"horizontal_datum": "WGS84"}, + resolutions=[ + Resolution("01d"), + Resolution("30m"), + Resolution("20m"), + Resolution("15m"), + Resolution("10m"), + Resolution("06m"), + Resolution("05m", tiled=True), + Resolution("04m", tiled=True), + Resolution("03m", tiled=True), + Resolution("02m", tiled=True), + Resolution("01m", registrations=["pixel"], tiled=True), + ], + ), + "earth_wdmam": GMTRemoteDataset( + title="WDMAM magnetic anomaly", + name="wdmam", + long_name="World Digital Magnetic Anomaly Map", + units="nT", + extra_attributes={"horizontal_datum": "WGS84"}, + resolutions=[ + Resolution("01d"), + Resolution("30m"), + Resolution("20m"), + Resolution("15m"), + Resolution("10m"), + Resolution("06m"), + Resolution("05m", tiled=True), + Resolution("04m", tiled=True), + Resolution("03m", registrations=["gridline"], tiled=True), + ], ), - # "earth_free_air_anomaly": GMTRemoteDataset( - # title="free air anomaly", - # name="free_air_anomaly", - # long_name="IGPP Earth Free-Air Anomaly", - # units="mGal", - # extra_attributes={"horizontal_datum": "WGS84"}, - # resolutions={ - # "01d": Resolution(["gridline", "pixel"], False), - # "30m": Resolution(["gridline", "pixel"], False), - # "20m": Resolution(["gridline", "pixel"], False), - # "15m": Resolution(["gridline", "pixel"], False), - # "10m": Resolution(["gridline", "pixel"], False), - # "06m": Resolution(["gridline", "pixel"], False), - # "05m": Resolution(["gridline", "pixel"], True), - # "04m": Resolution(["gridline", "pixel"], True), - # "03m": Resolution(["gridline", "pixel"], True), - # "02m": Resolution(["gridline", "pixel"], True), - # "01m": Resolution(["pixel"], True), - # }, - # ), - # "earth_geoid": GMTRemoteDataset( - # title="Earth geoid", - # name="earth_geoid", - # long_name="EGM2008 Earth Geoid", - # units="m", - # extra_attributes={"horizontal_datum": "WGS84"}, - # resolutions={ - # "01d": Resolution(["gridline", "pixel"], False), - # "30m": Resolution(["gridline", "pixel"], False), - # "20m": Resolution(["gridline", "pixel"], False), - # "15m": Resolution(["gridline", "pixel"], False), - # "10m": Resolution(["gridline", "pixel"], False), - # "06m": Resolution(["gridline", "pixel"], False), - # "05m": Resolution(["gridline", "pixel"], True), - # "04m": Resolution(["gridline", "pixel"], True), - # "03m": Resolution(["gridline", "pixel"], True), - # "02m": Resolution(["gridline", "pixel"], True), - # "01m": Resolution(["gridline"], True), - # }, - # ), - # "earth_magnetic_anomaly": GMTRemoteDataset( - # title="Earth magnetic anomaly", - # name="magnetic_anomaly", - # long_name="Earth magnetic anomaly", - # units="nT", - # extra_attributes={"horizontal_datum": "WGS84"}, - # resolutions={ - # "01d": Resolution(["gridline", "pixel"], False), - # "30m": Resolution(["gridline", "pixel"], False), - # "20m": Resolution(["gridline", "pixel"], False), - # "15m": Resolution(["gridline", "pixel"], False), - # "10m": Resolution(["gridline", "pixel"], False), - # "06m": Resolution(["gridline", "pixel"], False), - # "05m": Resolution(["gridline", "pixel"], True), - # "04m": Resolution(["gridline", "pixel"], True), - # "03m": Resolution(["gridline", "pixel"], True), - # "02m": Resolution(["pixel"], True), - # }, - # ), - # "earth_mask": GMTRemoteDataset( - # title="Earth mask", - # name="earth_mask", - # long_name="Mask of land and water features", - # units=None, - # extra_attributes={"horizontal_datum": "WGS84"}, - # resolutions={ - # "01d": Resolution(["gridline", "pixel"], False), - # "30m": Resolution(["gridline", "pixel"], False), - # "20m": Resolution(["gridline", "pixel"], False), - # "15m": Resolution(["gridline", "pixel"], False), - # "10m": Resolution(["gridline", "pixel"], False), - # "06m": Resolution(["gridline", "pixel"], False), - # "05m": Resolution(["gridline", "pixel"], False), - # "04m": Resolution(["gridline", "pixel"], False), - # "03m": Resolution(["gridline", "pixel"], False), - # "02m": Resolution(["gridline", "pixel"], False), - # "01m": Resolution(["gridline", "pixel"], False), - # "30s": Resolution(["gridline", "pixel"], False), - # "15s": Resolution(["gridline", "pixel"], False), - # }, - # ), - # "earth_relief": GMTRemoteDataset( - # title="Earth relief", - # name="elevation", - # long_name="Earth elevation relative to the geoid", - # units="meters", - # extra_attributes={"vertical_datum": "EGM96", "horizontal_datum": "WGS84"}, - # resolutions={ - # "01d": Resolution(["gridline", "pixel"], False), - # "30m": Resolution(["gridline", "pixel"], False), - # "20m": Resolution(["gridline", "pixel"], False), - # "15m": Resolution(["gridline", "pixel"], False), - # "10m": Resolution(["gridline", "pixel"], False), - # "06m": Resolution(["gridline", "pixel"], False), - # "05m": Resolution(["gridline", "pixel"], True), - # "04m": Resolution(["gridline", "pixel"], True), - # "03m": Resolution(["gridline", "pixel"], True), - # "02m": Resolution(["gridline", "pixel"], True), - # "01m": Resolution(["gridline", "pixel"], True), - # "30s": Resolution(["gridline", "pixel"], True), - # "15s": Resolution(["pixel"], True), - # "03s": Resolution(["gridline"], True), - # "01s": Resolution(["gridline"], True), - # }, - # ), - # "earth_vgg": GMTRemoteDataset( - # title="Earth vertical gravity gradient", - # name="earth_vgg", - # long_name="IGPP Earth Vertical Gravity Gradient", - # units="Eotvos", - # extra_attributes={"horizontal_datum": "WGS84"}, - # resolutions={ - # "01d": Resolution(["gridline", "pixel"], False), - # "30m": Resolution(["gridline", "pixel"], False), - # "20m": Resolution(["gridline", "pixel"], False), - # "15m": Resolution(["gridline", "pixel"], False), - # "10m": Resolution(["gridline", "pixel"], False), - # "06m": Resolution(["gridline", "pixel"], False), - # "05m": Resolution(["gridline", "pixel"], True), - # "04m": Resolution(["gridline", "pixel"], True), - # "03m": Resolution(["gridline", "pixel"], True), - # "02m": Resolution(["gridline", "pixel"], True), - # "01m": Resolution(["pixel"], True), - # }, - # ), - # "earth_wdmam": GMTRemoteDataset( - # title="WDMAM magnetic anomaly", - # name="wdmam", - # long_name="World Digital Magnetic Anomaly Map", - # units="nT", - # extra_attributes={"horizontal_datum": "WGS84"}, - # resolutions={ - # "01d": Resolution(["gridline", "pixel"], False), - # "30m": Resolution(["gridline", "pixel"], False), - # "20m": Resolution(["gridline", "pixel"], False), - # "15m": Resolution(["gridline", "pixel"], False), - # "10m": Resolution(["gridline", "pixel"], False), - # "06m": Resolution(["gridline", "pixel"], False), - # "05m": Resolution(["gridline", "pixel"], True), - # "04m": Resolution(["gridline", "pixel"], True), - # "03m": Resolution(["gridline"], True), - # }, - # ), } @kwargs_to_strings(region="sequence") -def _load_remote_dataset( +def _load_remote_dataset( # noqa: PLR0912 dataset_name, dataset_prefix, resolution, region, registration ): r""" From 9b1f6f0e9128e86fd36185770abe56fc3789a97f Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 27 Dec 2023 13:16:25 +0800 Subject: [PATCH 03/10] Add type hints --- pygmt/datasets/load_remote_dataset.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index a3df3dfe8e4..bc5f56b9144 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -3,13 +3,16 @@ """ from __future__ import annotations -from typing import ClassVar, NamedTuple +from typing import TYPE_CHECKING, ClassVar, NamedTuple from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import kwargs_to_strings from pygmt.io import load_dataarray from pygmt.src import grdcut, which +if TYPE_CHECKING: + import xarray as xr + class Resolution(NamedTuple): """ @@ -230,8 +233,12 @@ class GMTRemoteDataset(NamedTuple): @kwargs_to_strings(region="sequence") def _load_remote_dataset( # noqa: PLR0912 - dataset_name, dataset_prefix, resolution, region, registration -): + dataset_name: str, + dataset_prefix: str, + resolution: str, + region: str | list, + registration: str, +) -> xr.DataArray: r""" Load GMT remote datasets. From 165cfbefe4ad1d9e56641572209abc6f8485d919 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 27 Dec 2023 13:24:11 +0800 Subject: [PATCH 04/10] Fix --- pygmt/datasets/load_remote_dataset.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index bc5f56b9144..fb8fca29f69 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -244,22 +244,18 @@ def _load_remote_dataset( # noqa: PLR0912 Parameters ---------- - dataset_name : str + dataset_name The name for the dataset in the 'datasets' dictionary. - - dataset_prefix : str + dataset_prefix The prefix for the dataset that will be passed to the GMT C API. - - resolution : str + resolution The grid resolution. The suffix ``d``, ``m``, and ``s`` stand for arc-degrees, arc-minutes, and arc-seconds, respectively. - - region : str or list + region The subregion of the grid to load, in the form of a list [*xmin*, *xmax*, *ymin*, *ymax*] or a string *xmin/xmax/ymin/ymax*. Required for tiled grids. - - registration : str + registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. Default is ``None``, where a gridline-registered grid is returned unless only the From 567a6d459baaf1591a3cc6625cce9192a25d9a86 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 28 Dec 2023 11:22:54 +0800 Subject: [PATCH 05/10] Fix --- 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 fb8fca29f69..e9169d0dbdf 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -32,7 +32,7 @@ class Resolution(NamedTuple): """ code: str - registrations: ClassVar = ["gridline", "pixel"] + registrations: ClassVar[list] = ["gridline", "pixel"] tiled: bool = False From 704c029d7c1d720338a9de0d78a217ebc4b391b1 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 2 Jan 2024 21:08:42 +0800 Subject: [PATCH 06/10] Rewrap docstrings --- pygmt/datasets/load_remote_dataset.py | 34 ++++++++++++--------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index 08e5efbaa74..00a3162d3c1 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -16,19 +16,17 @@ class Resolution(NamedTuple): """ - The available grid registrations for a given resolution and whether it is a tiled - grid. + Resolution code, the available grid registrations and whether it is tiled. Attributes ---------- code : str The resolution code. registrations : list - A list of the accepted registrations for a given resolution. - Can be either "pixel" or "gridline". + A list of the accepted registrations for a given resolution. Can be either + "pixel" or "gridline". tiled : bool - States if the given resolution is tiled, which requires an - argument for ``region``. + States if the grid is tiled, which requires an argument for ``region``. """ code: str @@ -249,8 +247,8 @@ def _load_remote_dataset( # noqa: PLR0912 dataset_prefix The prefix for the dataset that will be passed to the GMT C API. resolution - The grid resolution. The suffix ``d``, ``m``, and ``s`` stand for - arc-degrees, arc-minutes, and arc-seconds, respectively. + The grid resolution. The suffix ``d``, ``m``, and ``s`` stand for arc-degrees, + arc-minutes, and arc-seconds, respectively. region The subregion of the grid to load, in the form of a list [*xmin*, *xmax*, *ymin*, *ymax*] or a string *xmin/xmax/ymin/ymax*. @@ -258,8 +256,8 @@ def _load_remote_dataset( # noqa: PLR0912 registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. Default is ``None``, where - a gridline-registered grid is returned unless only the - pixel-registered grid is available. + a gridline-registered grid is returned unless only the pixel-registered grid + is available. Returns ------- @@ -268,8 +266,8 @@ def _load_remote_dataset( # noqa: PLR0912 Note ---- - The returned :class:`xarray.DataArray` doesn't support slice operation for - tiled grids. + The returned :class:`xarray.DataArray` doesn't support slice operation for tiled + grids. """ dataset = datasets[dataset_name] @@ -295,10 +293,9 @@ def _load_remote_dataset( # noqa: PLR0912 ) else: raise GMTInvalidInput( - f"Invalid grid registration: '{registration}', should be either " - "'pixel', 'gridline' or None. Default is None, where a " - "gridline-registered grid is returned unless only the " - "pixel-registered grid is available." + f"Invalid grid registration: '{registration}', should be either 'pixel', " + "'gridline' or None. Default is None, where a gridline-registered grid is " + "returned unless only the pixel-registered grid is available." ) reg = f"_{registration[0]}" @@ -322,9 +319,8 @@ def _load_remote_dataset( # noqa: PLR0912 grid.attrs["units"] = dataset.units for key, value in dataset.extra_attributes.items(): grid.attrs[key] = value - # Remove the actual range because it gets outdated when indexing the grid, - # which causes problems when exporting it to netCDF for usage on the - # command-line. + # Remove the actual range because it gets outdated when indexing the grid, which + # causes problems when exporting it to netCDF for usage on the command-line. grid.attrs.pop("actual_range", None) for coord in grid.coords: grid[coord].attrs.pop("actual_range", None) From e5d43c4f1c75ef7f7339635149376f55fec9f48f Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sat, 6 Jan 2024 23:23:03 +0800 Subject: [PATCH 07/10] Temporarily run benchmarks in this PR --- .github/workflows/benchmarks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index 358f0105f63..1d0a0f2a8b1 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -13,7 +13,7 @@ on: - 'pygmt/**/*.py' - '.github/workflows/benchmarks.yml' # Uncomment the 'pull_request' line below to trigger the workflow in PR - # pull_request: + pull_request: # `workflow_dispatch` allows CodSpeed to trigger backtest # performance analysis in order to generate initial data. workflow_dispatch: From eaab9eec03742e3699b2c66706f5d452157c82bd Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sun, 7 Jan 2024 17:20:28 +0800 Subject: [PATCH 08/10] Revert resolutions to a dict of Resolution object --- pygmt/datasets/load_remote_dataset.py | 234 +++++++++++++------------- 1 file changed, 116 insertions(+), 118 deletions(-) diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index 00a3162d3c1..edf47d780b6 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -58,7 +58,7 @@ class GMTRemoteDataset(NamedTuple): name: str long_name: str units: str | None - resolutions: list[Resolution] + resolutions: dict[str, Resolution] extra_attributes: dict @@ -69,19 +69,19 @@ class GMTRemoteDataset(NamedTuple): long_name="age of seafloor crust", units="Myr", extra_attributes={"horizontal_datum": "WGS84"}, - resolutions=[ - Resolution("01d"), - Resolution("30m"), - Resolution("20m"), - Resolution("15m"), - Resolution("10m"), - Resolution("06m"), - Resolution("05m", tiled=True), - Resolution("04m", tiled=True), - Resolution("03m", tiled=True), - Resolution("02m", tiled=True), - Resolution("01m", registrations=["gridline"], tiled=True), - ], + resolutions={ + "01d": Resolution("01d"), + "30m": Resolution("30m"), + "20m": Resolution("20m"), + "15m": Resolution("15m"), + "10m": Resolution("10m"), + "06m": Resolution("06m"), + "05m": Resolution("05m", tiled=True), + "04m": Resolution("04m", tiled=True), + "03m": Resolution("03m", tiled=True), + "02m": Resolution("02m", tiled=True), + "01m": Resolution("01m", registrations=["gridline"], tiled=True), + }, ), "earth_free_air_anomaly": GMTRemoteDataset( title="free air anomaly", @@ -89,19 +89,19 @@ class GMTRemoteDataset(NamedTuple): long_name="IGPP Earth Free-Air Anomaly", units="mGal", extra_attributes={"horizontal_datum": "WGS84"}, - resolutions=[ - Resolution("01d"), - Resolution("30m"), - Resolution("20m"), - Resolution("15m"), - Resolution("10m"), - Resolution("06m"), - Resolution("05m", tiled=True), - Resolution("04m", tiled=True), - Resolution("03m", tiled=True), - Resolution("02m", tiled=True), - Resolution("01m", registrations=["pixel"], tiled=True), - ], + resolutions={ + "01d": Resolution("01d"), + "30m": Resolution("30m"), + "20m": Resolution("20m"), + "15m": Resolution("15m"), + "10m": Resolution("10m"), + "06m": Resolution("06m"), + "05m": Resolution("05m", tiled=True), + "04m": Resolution("04m", tiled=True), + "03m": Resolution("03m", tiled=True), + "02m": Resolution("02m", tiled=True), + "01m": Resolution("01m", registrations=["pixel"], tiled=True), + }, ), "earth_geoid": GMTRemoteDataset( title="Earth geoid", @@ -109,19 +109,19 @@ class GMTRemoteDataset(NamedTuple): long_name="EGM2008 Earth Geoid", units="m", extra_attributes={"horizontal_datum": "WGS84"}, - resolutions=[ - Resolution("01d"), - Resolution("30m"), - Resolution("20m"), - Resolution("15m"), - Resolution("10m"), - Resolution("06m"), - Resolution("05m", tiled=True), - Resolution("04m", tiled=True), - Resolution("03m", tiled=True), - Resolution("02m", tiled=True), - Resolution("01m", registrations=["gridline"], tiled=True), - ], + resolutions={ + "01d": Resolution("01d"), + "30m": Resolution("30m"), + "20m": Resolution("20m"), + "15m": Resolution("15m"), + "10m": Resolution("10m"), + "06m": Resolution("06m"), + "05m": Resolution("05m", tiled=True), + "04m": Resolution("04m", tiled=True), + "03m": Resolution("03m", tiled=True), + "02m": Resolution("02m", tiled=True), + "01m": Resolution("01m", registrations=["gridline"], tiled=True), + }, ), "earth_magnetic_anomaly": GMTRemoteDataset( title="Earth magnetic anomaly", @@ -129,18 +129,18 @@ class GMTRemoteDataset(NamedTuple): long_name="Earth magnetic anomaly", units="nT", extra_attributes={"horizontal_datum": "WGS84"}, - resolutions=[ - Resolution("01d"), - Resolution("30m"), - Resolution("20m"), - Resolution("15m"), - Resolution("10m"), - Resolution("06m"), - Resolution("05m", tiled=True), - Resolution("04m", tiled=True), - Resolution("03m", tiled=True), - Resolution("02m", registrations=["pixel"], tiled=True), - ], + resolutions={ + "01d": Resolution("01d"), + "30m": Resolution("30m"), + "20m": Resolution("20m"), + "15m": Resolution("15m"), + "10m": Resolution("10m"), + "06m": Resolution("06m"), + "05m": Resolution("05m", tiled=True), + "04m": Resolution("04m", tiled=True), + "03m": Resolution("03m", tiled=True), + "02m": Resolution("02m", registrations=["pixel"], tiled=True), + }, ), "earth_mask": GMTRemoteDataset( title="Earth mask", @@ -148,21 +148,21 @@ class GMTRemoteDataset(NamedTuple): long_name="Mask of land and water features", units=None, extra_attributes={"horizontal_datum": "WGS84"}, - resolutions=[ - Resolution("01d"), - Resolution("30m"), - Resolution("20m"), - Resolution("15m"), - Resolution("10m"), - Resolution("06m"), - Resolution("05m"), - Resolution("04m"), - Resolution("03m"), - Resolution("02m"), - Resolution("01m"), - Resolution("30s"), - Resolution("15s"), - ], + resolutions={ + "01d": Resolution("01d"), + "30m": Resolution("30m"), + "20m": Resolution("20m"), + "15m": Resolution("15m"), + "10m": Resolution("10m"), + "06m": Resolution("06m"), + "05m": Resolution("05m"), + "04m": Resolution("04m"), + "03m": Resolution("03m"), + "02m": Resolution("02m"), + "01m": Resolution("01m"), + "30s": Resolution("30s"), + "15s": Resolution("15s"), + }, ), "earth_relief": GMTRemoteDataset( title="Earth relief", @@ -170,23 +170,23 @@ class GMTRemoteDataset(NamedTuple): long_name="Earth elevation relative to the geoid", units="meters", extra_attributes={"vertical_datum": "EGM96", "horizontal_datum": "WGS84"}, - resolutions=[ - Resolution("01d"), - Resolution("30m"), - Resolution("20m"), - Resolution("15m"), - Resolution("10m"), - Resolution("06m"), - Resolution("05m", tiled=True), - Resolution("04m", tiled=True), - Resolution("03m", tiled=True), - Resolution("02m", tiled=True), - Resolution("01m", tiled=True), - Resolution("30s", tiled=True), - Resolution("15s", registrations=["pixel"], tiled=True), - Resolution("03s", registrations=["gridline"], tiled=True), - Resolution("01s", registrations=["gridline"], tiled=True), - ], + resolutions={ + "01d": Resolution("01d"), + "30m": Resolution("30m"), + "20m": Resolution("20m"), + "15m": Resolution("15m"), + "10m": Resolution("10m"), + "06m": Resolution("06m"), + "05m": Resolution("05m", tiled=True), + "04m": Resolution("04m", tiled=True), + "03m": Resolution("03m", tiled=True), + "02m": Resolution("02m", tiled=True), + "01m": Resolution("01m", tiled=True), + "30s": Resolution("30s", tiled=True), + "15s": Resolution("15s", registrations=["pixel"], tiled=True), + "03s": Resolution("03s", registrations=["gridline"], tiled=True), + "01s": Resolution("01s", registrations=["gridline"], tiled=True), + }, ), "earth_vgg": GMTRemoteDataset( title="Earth vertical gravity gradient", @@ -194,19 +194,19 @@ class GMTRemoteDataset(NamedTuple): long_name="IGPP Earth Vertical Gravity Gradient", units="Eotvos", extra_attributes={"horizontal_datum": "WGS84"}, - resolutions=[ - Resolution("01d"), - Resolution("30m"), - Resolution("20m"), - Resolution("15m"), - Resolution("10m"), - Resolution("06m"), - Resolution("05m", tiled=True), - Resolution("04m", tiled=True), - Resolution("03m", tiled=True), - Resolution("02m", tiled=True), - Resolution("01m", registrations=["pixel"], tiled=True), - ], + resolutions={ + "01d": Resolution("01d"), + "30m": Resolution("30m"), + "20m": Resolution("20m"), + "15m": Resolution("15m"), + "10m": Resolution("10m"), + "06m": Resolution("06m"), + "05m": Resolution("05m", tiled=True), + "04m": Resolution("04m", tiled=True), + "03m": Resolution("03m", tiled=True), + "02m": Resolution("02m", tiled=True), + "01m": Resolution("01m", registrations=["pixel"], tiled=True), + }, ), "earth_wdmam": GMTRemoteDataset( title="WDMAM magnetic anomaly", @@ -214,23 +214,23 @@ class GMTRemoteDataset(NamedTuple): long_name="World Digital Magnetic Anomaly Map", units="nT", extra_attributes={"horizontal_datum": "WGS84"}, - resolutions=[ - Resolution("01d"), - Resolution("30m"), - Resolution("20m"), - Resolution("15m"), - Resolution("10m"), - Resolution("06m"), - Resolution("05m", tiled=True), - Resolution("04m", tiled=True), - Resolution("03m", registrations=["gridline"], tiled=True), - ], + resolutions={ + "01d": Resolution("01d"), + "30m": Resolution("30m"), + "20m": Resolution("20m"), + "15m": Resolution("15m"), + "10m": Resolution("10m"), + "06m": Resolution("06m"), + "05m": Resolution("05m", tiled=True), + "04m": Resolution("04m", tiled=True), + "03m": Resolution("03m", registrations=["gridline"], tiled=True), + }, ), } @kwargs_to_strings(region="sequence") -def _load_remote_dataset( # noqa: PLR0912 +def _load_remote_dataset( dataset_name: str, dataset_prefix: str, resolution: str, @@ -271,16 +271,14 @@ def _load_remote_dataset( # noqa: PLR0912 """ dataset = datasets[dataset_name] - # check resolution - for res in dataset.resolutions: - if res.code == resolution: - valid_registrations = res.registrations - is_tiled = res.tiled - break - else: - raise GMTInvalidInput(f"Invalid resolution '{resolution}'.") + if resolution not in dataset.resolutions: + raise GMTInvalidInput( + f"Invalid resolution '{resolution}' for {dataset.title} dataset. " + f"Available resolutions are: {', '.join(dataset.resolutions)}." + ) # check registration + valid_registrations = dataset.resolutions[resolution].registrations if registration is None: # use gridline registration unless only pixel registration is available registration = "gridline" if "gridline" in valid_registrations else "pixel" @@ -303,7 +301,7 @@ def _load_remote_dataset( # noqa: PLR0912 # Known issue: tiled grids don't support slice operation # See https://github.com/GenericMappingTools/pygmt/issues/524 if region is None: - if is_tiled: + if dataset.resolutions[resolution].tiled: raise GMTInvalidInput( f"'region' is required for {dataset.title} resolution '{resolution}'." ) From 2a784f6179422a781658c6c06033f9dc7d2714fe Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sun, 7 Jan 2024 17:22:29 +0800 Subject: [PATCH 09/10] Improve description of resolution code --- 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 edf47d780b6..31aa8275c2e 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -21,7 +21,7 @@ class Resolution(NamedTuple): Attributes ---------- code : str - The resolution code. + The resolution code. E.g., "01d", "30m", "01s". registrations : list A list of the accepted registrations for a given resolution. Can be either "pixel" or "gridline". From f9f09f39c80169f73a1d987815897c7793440319 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sun, 7 Jan 2024 17:24:31 +0800 Subject: [PATCH 10/10] Fix the description of resolutions --- pygmt/datasets/load_remote_dataset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index 31aa8275c2e..67f3f73842d 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -48,8 +48,8 @@ class GMTRemoteDataset(NamedTuple): The long name assigned as an attribute to the DataArray. units : str The units of the values in the DataArray. - resolutions : list - List of Resolution objects. + resolutions : dict + Dictionary of available resolution as keys and Resolution objects as values. extra_attributes : dict A dictionary of extra or unique attributes of the dataset. """