From 14082d8a8ffbcf1f793279969d8f0449ad41aeea Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 28 May 2024 07:50:06 +0800 Subject: [PATCH] pygmt.dataset.load_*: Add type hints for the 'region' parameter (#3272) --- pygmt/datasets/earth_age.py | 16 +++++--------- pygmt/datasets/earth_free_air_anomaly.py | 16 +++++--------- pygmt/datasets/earth_geoid.py | 16 +++++--------- pygmt/datasets/earth_magnetic_anomaly.py | 17 +++++--------- pygmt/datasets/earth_mask.py | 13 +++++------ pygmt/datasets/earth_relief.py | 22 +++++++------------ .../earth_vertical_gravity_gradient.py | 16 +++++--------- pygmt/datasets/mars_relief.py | 13 +++++------ pygmt/datasets/mercury_relief.py | 13 +++++------ pygmt/datasets/moon_relief.py | 13 +++++------ pygmt/datasets/pluto_relief.py | 13 +++++------ pygmt/datasets/venus_relief.py | 13 +++++------ 12 files changed, 73 insertions(+), 108 deletions(-) diff --git a/pygmt/datasets/earth_age.py b/pygmt/datasets/earth_age.py index ef45eac1bec..1ee66513622 100644 --- a/pygmt/datasets/earth_age.py +++ b/pygmt/datasets/earth_age.py @@ -5,20 +5,19 @@ The grids are available in various resolutions. """ +from collections.abc import Sequence from typing import Literal from pygmt.datasets.load_remote_dataset import _load_remote_dataset -from pygmt.helpers import kwargs_to_strings __doctest_skip__ = ["load_earth_age"] -@kwargs_to_strings(region="sequence") def load_earth_age( resolution: Literal[ "01d", "30m", "20m", "15m", "10m", "06m", "05m", "04m", "03m", "02m", "01m" ] = "01d", - region=None, + region: Sequence[float] | str | None = None, registration: Literal["gridline", "pixel"] = "gridline", ): r""" @@ -56,13 +55,10 @@ def load_earth_age( resolution The grid resolution. The suffix ``d`` and ``m`` stand for arc-degrees and arc-minutes. - - region : str or list - 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 grids with resolutions higher than 5 - arc-minutes (i.e., ``"05m"``). - + region + The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, + *ymin*, *ymax*] or an ISO country code. Required for grids with resolutions + higher than 5 arc-minutes (i.e., ``"05m"``). registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. diff --git a/pygmt/datasets/earth_free_air_anomaly.py b/pygmt/datasets/earth_free_air_anomaly.py index 56ac3fbe324..0630c7f8a38 100644 --- a/pygmt/datasets/earth_free_air_anomaly.py +++ b/pygmt/datasets/earth_free_air_anomaly.py @@ -5,20 +5,19 @@ The grids are available in various resolutions. """ +from collections.abc import Sequence from typing import Literal from pygmt.datasets.load_remote_dataset import _load_remote_dataset -from pygmt.helpers import kwargs_to_strings __doctest_skip__ = ["load_earth_free_air_anomaly"] -@kwargs_to_strings(region="sequence") def load_earth_free_air_anomaly( resolution: Literal[ "01d", "30m", "20m", "15m", "10m", "06m", "05m", "04m", "03m", "02m", "01m" ] = "01d", - region=None, + region: Sequence[float] | str | None = None, registration: Literal["gridline", "pixel", None] = None, ): r""" @@ -56,13 +55,10 @@ def load_earth_free_air_anomaly( resolution The grid resolution. The suffix ``d`` and ``m`` stand for arc-degrees and arc-minutes. - - region : str or list - 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 grids with resolutions higher than 5 - arc-minutes (i.e., ``"05m"``). - + region + The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, + *ymin*, *ymax*] or an ISO country code. Required for grids with resolutions + higher than 5 arc-minutes (i.e., ``"05m"``). registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. Default is ``None``, means diff --git a/pygmt/datasets/earth_geoid.py b/pygmt/datasets/earth_geoid.py index acae0c527b3..f2a747b8602 100644 --- a/pygmt/datasets/earth_geoid.py +++ b/pygmt/datasets/earth_geoid.py @@ -5,20 +5,19 @@ The grids are available in various resolutions. """ +from collections.abc import Sequence from typing import Literal from pygmt.datasets.load_remote_dataset import _load_remote_dataset -from pygmt.helpers import kwargs_to_strings __doctest_skip__ = ["load_earth_geoid"] -@kwargs_to_strings(region="sequence") def load_earth_geoid( resolution: Literal[ "01d", "30m", "20m", "15m", "10m", "06m", "05m", "04m", "03m", "02m", "01m" ] = "01d", - region=None, + region: Sequence[float] | str | None = None, registration: Literal["gridline", "pixel"] = "gridline", ): r""" @@ -49,13 +48,10 @@ def load_earth_geoid( resolution The grid resolution. The suffix ``d`` and ``m`` stand for arc-degrees and arc-minutes. - - region : str or list - 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 grids with resolutions higher than 5 - arc-minutes (i.e., ``"05m"``). - + region + The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, + *ymin*, *ymax*] or an ISO country code. Required for grids with resolutions + higher than 5 arc-minutes (i.e., ``"05m"``). registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. diff --git a/pygmt/datasets/earth_magnetic_anomaly.py b/pygmt/datasets/earth_magnetic_anomaly.py index 869d272736a..b49bb29e2c8 100644 --- a/pygmt/datasets/earth_magnetic_anomaly.py +++ b/pygmt/datasets/earth_magnetic_anomaly.py @@ -5,21 +5,20 @@ The grids are available in various resolutions. """ +from collections.abc import Sequence from typing import Literal from pygmt.datasets.load_remote_dataset import _load_remote_dataset from pygmt.exceptions import GMTInvalidInput -from pygmt.helpers import kwargs_to_strings __doctest_skip__ = ["load_earth_magnetic_anomaly"] -@kwargs_to_strings(region="sequence") def load_earth_magnetic_anomaly( resolution: Literal[ "01d", "30m", "20m", "15m", "10m", "06m", "05m", "04m", "03m", "02m" ] = "01d", - region=None, + region: Sequence[float] | str | None = None, registration: Literal["gridline", "pixel", None] = None, data_source: Literal["emag2", "emag2_4km", "wdmam"] = "emag2", ): @@ -70,20 +69,16 @@ def load_earth_magnetic_anomaly( The grid resolution. The suffix ``d`` and ``m`` stand for arc-degrees and arc-minutes. The resolution ``"02m"`` is not available for ``data_source="wdmam"``. - - region : str or list - 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 grids with resolutions higher than 5 - arc-minutes (i.e., ``"05m"``). - + region + The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, + *ymin*, *ymax*] or an ISO country code. Required for grids with resolutions + higher than 5 arc-minutes (i.e., ``"05m"``). registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. Default is ``None``, means ``"gridline"`` for all resolutions except ``"02m"`` for ``data_source="emag2"`` or ``data_source="emag2_4km"``, which are ``"pixel"`` only. - data_source Select the source of the magnetic anomaly data. Available options are: diff --git a/pygmt/datasets/earth_mask.py b/pygmt/datasets/earth_mask.py index b2c9ef40b5c..22400a7369b 100644 --- a/pygmt/datasets/earth_mask.py +++ b/pygmt/datasets/earth_mask.py @@ -5,15 +5,14 @@ The grids are available in various resolutions. """ +from collections.abc import Sequence from typing import Literal from pygmt.datasets.load_remote_dataset import _load_remote_dataset -from pygmt.helpers import kwargs_to_strings __doctest_skip__ = ["load_earth_mask"] -@kwargs_to_strings(region="sequence") def load_earth_mask( resolution: Literal[ "01d", @@ -30,7 +29,7 @@ def load_earth_mask( "30s", "15s", ] = "01d", - region=None, + region: Sequence[float] | str | None = None, registration: Literal["gridline", "pixel"] = "gridline", ): r""" @@ -61,11 +60,9 @@ def load_earth_mask( resolution The grid resolution. The suffix ``d``, ``m``, and ``s`` stand for arc-degrees, arc-minutes, and arc-seconds. - - region : str or list - The subregion of the grid to load, in the form of a list - [*xmin*, *xmax*, *ymin*, *ymax*] or a string *xmin/xmax/ymin/ymax*. - + region + The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, + *ymin*, *ymax*] or an ISO country code. registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. diff --git a/pygmt/datasets/earth_relief.py b/pygmt/datasets/earth_relief.py index 969e3d89b60..823aa9ce43a 100644 --- a/pygmt/datasets/earth_relief.py +++ b/pygmt/datasets/earth_relief.py @@ -5,16 +5,15 @@ The grids are available in various resolutions. """ +from collections.abc import Sequence from typing import Literal from pygmt.datasets.load_remote_dataset import _load_remote_dataset from pygmt.exceptions import GMTInvalidInput -from pygmt.helpers import kwargs_to_strings __doctest_skip__ = ["load_earth_relief"] -@kwargs_to_strings(region="sequence") def load_earth_relief( resolution: Literal[ "01d", @@ -33,10 +32,10 @@ def load_earth_relief( "03s", "01s", ] = "01d", - region=None, + region: Sequence[float] | str | None = None, registration: Literal["gridline", "pixel", None] = None, data_source: Literal["igpp", "gebco", "gebcosi", "synbath"] = "igpp", - use_srtm=False, + use_srtm: bool = False, ): r""" Load the Earth relief datasets (topography and bathymetry) in various resolutions. @@ -77,19 +76,15 @@ def load_earth_relief( resolution The grid resolution. The suffix ``d``, ``m`` and ``s`` stand for arc-degrees, arc-minutes, and arc-seconds. - - region : str or list - 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 Earth relief grids with resolutions higher than 5 - arc-minutes (i.e., ``"05m"``). - + region + The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, + *ymin*, *ymax*] or an ISO country code. Required for grids with resolutions + higher than 5 arc-minutes (i.e., ``"05m"``). registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. Default is ``None``, means ``"gridline"`` for all resolutions except ``"15s"`` which is ``"pixel"`` only. - data_source Select the source for the Earth relief data. Available options are: @@ -102,8 +97,7 @@ def load_earth_relief( inferred relief via altimetric gravity. See :gmt-datasets:`earth-gebco.html`. - ``"gebcosi"``: GEBCO Earth Relief that gives sub-ice (si) elevations. - - use_srtm : bool + use_srtm By default, the land-only SRTM tiles from NASA are used to generate the ``"03s"`` and ``"01s"`` grids, and the missing ocean values are filled by up-sampling the SRTM15 tiles which have a resolution of 15 diff --git a/pygmt/datasets/earth_vertical_gravity_gradient.py b/pygmt/datasets/earth_vertical_gravity_gradient.py index 86ef5be5550..71a6a649340 100644 --- a/pygmt/datasets/earth_vertical_gravity_gradient.py +++ b/pygmt/datasets/earth_vertical_gravity_gradient.py @@ -5,20 +5,19 @@ The grids are available in various resolutions. """ +from collections.abc import Sequence from typing import Literal from pygmt.datasets.load_remote_dataset import _load_remote_dataset -from pygmt.helpers import kwargs_to_strings __doctest_skip__ = ["load_earth_vertical_gravity_gradient"] -@kwargs_to_strings(region="sequence") def load_earth_vertical_gravity_gradient( resolution: Literal[ "01d", "30m", "20m", "15m", "10m", "06m", "05m", "04m", "03m", "02m", "01m" ] = "01d", - region=None, + region: Sequence[float] | str | None = None, registration: Literal["gridline", "pixel", None] = None, ): r""" @@ -56,13 +55,10 @@ def load_earth_vertical_gravity_gradient( resolution The grid resolution. The suffix ``d`` and ``m`` stand for arc-degrees and arc-minutes. - - region : str or list - 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 grids with resolutions higher than 5 - arc-minutes (i.e., ``"05m"``). - + region + The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, + *ymin*, *ymax*] or an ISO country code. Required for grids with resolutions + higher than 5 arc-minutes (i.e., ``"05m"``). registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. Default is ``None``, means diff --git a/pygmt/datasets/mars_relief.py b/pygmt/datasets/mars_relief.py index b7ffb8971cb..49b317db308 100644 --- a/pygmt/datasets/mars_relief.py +++ b/pygmt/datasets/mars_relief.py @@ -5,15 +5,14 @@ The grids are available in various resolutions. """ +from collections.abc import Sequence from typing import Literal from pygmt.datasets.load_remote_dataset import _load_remote_dataset -from pygmt.helpers import kwargs_to_strings __doctest_skip__ = ["load_mars_relief"] -@kwargs_to_strings(region="sequence") def load_mars_relief( resolution: Literal[ "01d", @@ -31,7 +30,7 @@ def load_mars_relief( "15s", "12s", ] = "01d", - region=None, + region: Sequence[float] | str | None = None, registration: Literal["gridline", "pixel", None] = None, ): r""" @@ -68,10 +67,10 @@ def load_mars_relief( resolution The grid resolution. The suffix ``d``, ``m`` and ``s`` stand for arc-degrees, arc-minutes and arc-seconds. - region : str or list - 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 - grids with resolutions higher than 5 arc-minutes (i.e., ``"05m"``). + region + The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, + *ymin*, *ymax*] or an ISO country code. Required for grids with resolutions + higher than 5 arc-minutes (i.e., ``"05m"``). registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. Default is ``None``, means diff --git a/pygmt/datasets/mercury_relief.py b/pygmt/datasets/mercury_relief.py index 4764408c7ef..05b6024cb47 100644 --- a/pygmt/datasets/mercury_relief.py +++ b/pygmt/datasets/mercury_relief.py @@ -5,15 +5,14 @@ The grids are available in various resolutions. """ +from collections.abc import Sequence from typing import Literal from pygmt.datasets.load_remote_dataset import _load_remote_dataset -from pygmt.helpers import kwargs_to_strings __doctest_skip__ = ["load_mercury_relief"] -@kwargs_to_strings(region="sequence") def load_mercury_relief( resolution: Literal[ "01d", @@ -29,7 +28,7 @@ def load_mercury_relief( "01m", "56s", ] = "01d", - region=None, + region: Sequence[float] | str | None = None, registration: Literal["gridline", "pixel", None] = None, ): r""" @@ -66,10 +65,10 @@ def load_mercury_relief( resolution The grid resolution. The suffix ``d``, ``m`` and ``s`` stand for arc-degrees, arc-minutes and arc-seconds. - region : str or list - 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 - grids with resolutions higher than 5 arc-minutes (i.e., ``"05m"``). + region + The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, + *ymin*, *ymax*] or an ISO country code. Required for grids with resolutions + higher than 5 arc-minutes (i.e., ``"05m"``). registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. Default is ``None``, means diff --git a/pygmt/datasets/moon_relief.py b/pygmt/datasets/moon_relief.py index 22809f6a281..6c8a68e599e 100644 --- a/pygmt/datasets/moon_relief.py +++ b/pygmt/datasets/moon_relief.py @@ -5,15 +5,14 @@ The grids are available in various resolutions. """ +from collections.abc import Sequence from typing import Literal from pygmt.datasets.load_remote_dataset import _load_remote_dataset -from pygmt.helpers import kwargs_to_strings __doctest_skip__ = ["load_moon_relief"] -@kwargs_to_strings(region="sequence") def load_moon_relief( resolution: Literal[ "01d", @@ -31,7 +30,7 @@ def load_moon_relief( "15s", "14s", ] = "01d", - region=None, + region: Sequence[float] | str | None = None, registration: Literal["gridline", "pixel", None] = None, ): r""" @@ -68,10 +67,10 @@ def load_moon_relief( resolution The grid resolution. The suffix ``d``, ``m`` and ``s`` stand for arc-degrees, arc-minutes and arc-seconds. - region : str or list - 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 - grids with resolutions higher than 5 arc-minutes (i.e., ``"05m"``). + region + The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, + *ymin*, *ymax*] or an ISO country code. Required for grids with resolutions + higher than 5 arc-minutes (i.e., ``"05m"``). registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. Default is ``None``, means diff --git a/pygmt/datasets/pluto_relief.py b/pygmt/datasets/pluto_relief.py index 1b25ac910ea..feb04ee83d3 100644 --- a/pygmt/datasets/pluto_relief.py +++ b/pygmt/datasets/pluto_relief.py @@ -5,15 +5,14 @@ The grids are available in various resolutions. """ +from collections.abc import Sequence from typing import Literal from pygmt.datasets.load_remote_dataset import _load_remote_dataset -from pygmt.helpers import kwargs_to_strings __doctest_skip__ = ["load_pluto_relief"] -@kwargs_to_strings(region="sequence") def load_pluto_relief( resolution: Literal[ "01d", @@ -29,7 +28,7 @@ def load_pluto_relief( "01m", "52s", ] = "01d", - region=None, + region: Sequence[float] | str | None = None, registration: Literal["gridline", "pixel", None] = None, ): r""" @@ -66,10 +65,10 @@ def load_pluto_relief( resolution The grid resolution. The suffix ``d``, ``m`` and ``s`` stand for arc-degrees, arc-minutes and arc-seconds. - region : str or list - 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 - grids with resolutions higher than 5 arc-minutes (i.e., ``"05m"``). + region + The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, + *ymin*, *ymax*] or an ISO country code. Required for grids with resolutions + higher than 5 arc-minutes (i.e., ``"05m"``). registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. Default is ``None``, means diff --git a/pygmt/datasets/venus_relief.py b/pygmt/datasets/venus_relief.py index e86eed40d95..c83c49843ba 100644 --- a/pygmt/datasets/venus_relief.py +++ b/pygmt/datasets/venus_relief.py @@ -5,20 +5,19 @@ The grids are available in various resolutions. """ +from collections.abc import Sequence from typing import Literal from pygmt.datasets.load_remote_dataset import _load_remote_dataset -from pygmt.helpers import kwargs_to_strings __doctest_skip__ = ["load_venus_relief"] -@kwargs_to_strings(region="sequence") def load_venus_relief( resolution: Literal[ "01d", "30m", "20m", "15m", "10m", "06m", "05m", "04m", "03m", "02m", "01m" ] = "01d", - region=None, + region: Sequence[float] | str | None = None, registration: Literal["gridline", "pixel"] = "gridline", ): r""" @@ -55,10 +54,10 @@ def load_venus_relief( resolution The grid resolution. The suffix ``d`` and ``m`` stand for arc-degrees and arc-minutes. - region : str or list - 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 grids with resolutions higher than 5 arc-minutes (i.e., ``"05m"``). + region + The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, + *ymin*, *ymax*] or an ISO country code. Required for grids with resolutions + higher than 5 arc-minutes (i.e., ``"05m"``). registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration.