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

pygmt.dataset.load_*: Add type hints for the 'region' parameter #3272

Merged
merged 5 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 6 additions & 10 deletions pygmt/datasets/earth_age.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed because region is passed to _load_remote_dataset and in that function region can be a 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"""
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 6 additions & 10 deletions pygmt/datasets/earth_free_air_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand Down
16 changes: 6 additions & 10 deletions pygmt/datasets/earth_geoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 6 additions & 11 deletions pygmt/datasets/earth_magnetic_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
):
Expand Down Expand Up @@ -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:

Expand Down
13 changes: 5 additions & 8 deletions pygmt/datasets/earth_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"""
Expand Down Expand Up @@ -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.
Expand Down
22 changes: 8 additions & 14 deletions pygmt/datasets/earth_relief.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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.
Expand Down Expand Up @@ -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:

Expand All @@ -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
Expand Down
16 changes: 6 additions & 10 deletions pygmt/datasets/earth_vertical_gravity_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions pygmt/datasets/mars_relief.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"""
Expand Down Expand Up @@ -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
Expand Down
Loading