Skip to content

Commit c31a913

Browse files
authored
TYP: Add type hints for the 'registration' parameter in pygmt.datasets.load_* functions (#2867)
1 parent 7d6f615 commit c31a913

7 files changed

+58
-26
lines changed

pygmt/datasets/earth_age.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
55
The grids are available in various resolutions.
66
"""
7+
from typing import Literal
8+
79
from pygmt.datasets.load_remote_dataset import _load_remote_dataset
810
from pygmt.helpers import kwargs_to_strings
911

1012
__doctest_skip__ = ["load_earth_age"]
1113

1214

1315
@kwargs_to_strings(region="sequence")
14-
def load_earth_age(resolution="01d", region=None, registration=None):
16+
def load_earth_age(
17+
resolution="01d",
18+
region=None,
19+
registration: Literal["gridline", "pixel"] = "gridline",
20+
):
1521
r"""
1622
Load the Earth seafloor crustal age dataset in various resolutions.
1723
@@ -56,9 +62,9 @@ def load_earth_age(resolution="01d", region=None, registration=None):
5662
Required for grids with resolutions higher than 5
5763
arc-minutes (i.e., ``"05m"``).
5864
59-
registration : str
65+
registration
6066
Grid registration type. Either ``"pixel"`` for pixel registration or
61-
``"gridline"`` for gridline registration. Default is ``"gridline"``.
67+
``"gridline"`` for gridline registration.
6268
6369
Returns
6470
-------

pygmt/datasets/earth_free_air_anomaly.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
55
The grids are available in various resolutions.
66
"""
7+
from typing import Literal
8+
79
from pygmt.datasets.load_remote_dataset import _load_remote_dataset
810
from pygmt.helpers import kwargs_to_strings
911

1012
__doctest_skip__ = ["load_earth_free_air_anomaly"]
1113

1214

1315
@kwargs_to_strings(region="sequence")
14-
def load_earth_free_air_anomaly(resolution="01d", region=None, registration=None):
16+
def load_earth_free_air_anomaly(
17+
resolution="01d",
18+
region=None,
19+
registration: Literal["gridline", "pixel", None] = None,
20+
):
1521
r"""
1622
Load the IGPP Earth Free-Air Anomaly dataset in various resolutions.
1723
@@ -56,10 +62,11 @@ def load_earth_free_air_anomaly(resolution="01d", region=None, registration=None
5662
Required for grids with resolutions higher than 5
5763
arc-minutes (i.e., ``"05m"``).
5864
59-
registration : str
65+
registration
6066
Grid registration type. Either ``"pixel"`` for pixel registration or
61-
``"gridline"`` for gridline registration. Default is ``"gridline"``
62-
for all resolutions except ``"01m"`` which is ``"pixel"`` only.
67+
``"gridline"`` for gridline registration. Default is ``None``, means
68+
``"gridline"`` for all resolutions except ``"01m"`` which is
69+
``"pixel"`` only.
6370
6471
Returns
6572
-------

pygmt/datasets/earth_geoid.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
55
The grids are available in various resolutions.
66
"""
7+
from typing import Literal
8+
79
from pygmt.datasets.load_remote_dataset import _load_remote_dataset
810
from pygmt.helpers import kwargs_to_strings
911

1012
__doctest_skip__ = ["load_earth_geoid"]
1113

1214

1315
@kwargs_to_strings(region="sequence")
14-
def load_earth_geoid(resolution="01d", region=None, registration=None):
16+
def load_earth_geoid(
17+
resolution="01d",
18+
region=None,
19+
registration: Literal["gridline", "pixel"] = "gridline",
20+
):
1521
r"""
1622
Load the EGM2008 Earth Geoid dataset in various resolutions.
1723
@@ -49,9 +55,9 @@ def load_earth_geoid(resolution="01d", region=None, registration=None):
4955
Required for grids with resolutions higher than 5
5056
arc-minutes (i.e., ``"05m"``).
5157
52-
registration : str
58+
registration
5359
Grid registration type. Either ``"pixel"`` for pixel registration or
54-
``"gridline"`` for gridline registration. Default is ``"gridline"``.
60+
``"gridline"`` for gridline registration.
5561
5662
Returns
5763
-------

pygmt/datasets/earth_magnetic_anomaly.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
def load_earth_magnetic_anomaly(
1818
resolution="01d",
1919
region=None,
20-
registration=None,
20+
registration: Literal["gridline", "pixel", None] = None,
2121
data_source: Literal["emag2", "emag2_4km", "wdmam"] = "emag2",
2222
):
2323
r"""
@@ -76,11 +76,12 @@ def load_earth_magnetic_anomaly(
7676
Required for grids with resolutions higher than 5
7777
arc-minutes (i.e., ``"05m"``).
7878
79-
registration : str
79+
registration
8080
Grid registration type. Either ``"pixel"`` for pixel registration or
81-
``"gridline"`` for gridline registration. Default is ``"gridline"``
82-
for all resolutions except ``"02m"`` for ``data_source="emag2"`` or
83-
``data_source="emag2_4km"``, which are ``"pixel"`` only.
81+
``"gridline"`` for gridline registration. Default is ``None``, means
82+
``"gridline"`` for all resolutions except ``"02m"`` for
83+
``data_source="emag2"`` or ``data_source="emag2_4km"``, which are
84+
``"pixel"`` only.
8485
8586
data_source
8687
Select the source of the magnetic anomaly data. Available options are:

pygmt/datasets/earth_mask.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44
55
The grids are available in various resolutions.
66
"""
7+
from typing import Literal
8+
79
from pygmt.datasets.load_remote_dataset import _load_remote_dataset
810
from pygmt.helpers import kwargs_to_strings
911

1012
__doctest_skip__ = ["load_earth_mask"]
1113

1214

1315
@kwargs_to_strings(region="sequence")
14-
def load_earth_mask(resolution="01d", region=None, registration=None):
16+
def load_earth_mask(
17+
resolution="01d",
18+
region=None,
19+
registration: Literal["gridline", "pixel"] = "gridline",
20+
):
1521
r"""
1622
Load the GSHHG Earth Mask dataset in various resolutions.
1723
@@ -47,9 +53,9 @@ def load_earth_mask(resolution="01d", region=None, registration=None):
4753
The subregion of the grid to load, in the form of a list
4854
[*xmin*, *xmax*, *ymin*, *ymax*] or a string *xmin/xmax/ymin/ymax*.
4955
50-
registration : str
56+
registration
5157
Grid registration type. Either ``"pixel"`` for pixel registration or
52-
``"gridline"`` for gridline registration. Default is ``"gridline"``.
58+
``"gridline"`` for gridline registration.
5359
5460
Returns
5561
-------

pygmt/datasets/earth_relief.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
def load_earth_relief(
1818
resolution="01d",
1919
region=None,
20-
registration=None,
20+
registration: Literal["gridline", "pixel", None] = None,
2121
data_source: Literal["igpp", "gebco", "gebcosi", "synbath"] = "igpp",
2222
use_srtm=False,
2323
):
@@ -71,10 +71,11 @@ def load_earth_relief(
7171
Required for Earth relief grids with resolutions higher than 5
7272
arc-minutes (i.e., ``"05m"``).
7373
74-
registration : str
74+
registration
7575
Grid registration type. Either ``"pixel"`` for pixel registration or
76-
``"gridline"`` for gridline registration. Default is ``"gridline"``
77-
for all resolutions except ``"15s"`` which is ``"pixel"`` only.
76+
``"gridline"`` for gridline registration. Default is ``None``, means
77+
``"gridline"`` for all resolutions except ``"15s"`` which is
78+
``"pixel"`` only.
7879
7980
data_source
8081
Select the source for the Earth relief data. Available options are:

pygmt/datasets/earth_vertical_gravity_gradient.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
The grids are available in various resolutions.
66
"""
7+
from typing import Literal
8+
79
from pygmt.datasets.load_remote_dataset import _load_remote_dataset
810
from pygmt.helpers import kwargs_to_strings
911

@@ -12,7 +14,9 @@
1214

1315
@kwargs_to_strings(region="sequence")
1416
def load_earth_vertical_gravity_gradient(
15-
resolution="01d", region=None, registration=None
17+
resolution="01d",
18+
region=None,
19+
registration: Literal["gridline", "pixel", None] = None,
1620
):
1721
r"""
1822
Load the IGPP Earth Vertical Gravity Gradient dataset in various
@@ -59,10 +63,11 @@ def load_earth_vertical_gravity_gradient(
5963
Required for grids with resolutions higher than 5
6064
arc-minutes (i.e., ``"05m"``).
6165
62-
registration : str
66+
registration
6367
Grid registration type. Either ``"pixel"`` for pixel registration or
64-
``"gridline"`` for gridline registration. Default is ``"gridline"``
65-
for all resolutions except ``"01m"`` which is ``"pixel"`` only.
68+
``"gridline"`` for gridline registration. Default is ``None``, means
69+
``"gridline"`` for all resolutions except ``"01m"`` which is
70+
``"pixel"`` only.
6671
6772
Returns
6873
-------

0 commit comments

Comments
 (0)