Skip to content

Commit 819bac1

Browse files
authored
TYP: Add typing hints to the return values for modules that output a grid (#3385)
1 parent cf59045 commit 819bac1

18 files changed

+63
-38
lines changed

pygmt/src/binstats.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
binstats - Bin spatial data and determine statistics per bin
33
"""
44

5+
import xarray as xr
56
from pygmt.clib import Session
67
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
78

@@ -23,7 +24,7 @@
2324
r="registration",
2425
)
2526
@kwargs_to_strings(I="sequence", R="sequence", i="sequence_comma")
26-
def binstats(data, outgrid: str | None = None, **kwargs):
27+
def binstats(data, outgrid: str | None = None, **kwargs) -> xr.DataArray | None:
2728
r"""
2829
Bin spatial data and determine statistics per bin.
2930
@@ -95,7 +96,7 @@ def binstats(data, outgrid: str | None = None, **kwargs):
9596
9697
Returns
9798
-------
98-
ret: xarray.DataArray or None
99+
ret
99100
Return type depends on whether the ``outgrid`` parameter is set:
100101
101102
- :class:`xarray.DataArray` if ``outgrid`` is not set

pygmt/src/dimfilter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
dimfilter - Directional filtering of grids in the space domain.
33
"""
44

5+
import xarray as xr
56
from pygmt.clib import Session
67
from pygmt.exceptions import GMTInvalidInput
78
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
@@ -19,7 +20,7 @@
1920
V="verbose",
2021
)
2122
@kwargs_to_strings(I="sequence", R="sequence")
22-
def dimfilter(grid, outgrid: str | None = None, **kwargs):
23+
def dimfilter(grid, outgrid: str | None = None, **kwargs) -> xr.DataArray | None:
2324
r"""
2425
Filter a grid by dividing the filter circle.
2526
@@ -109,7 +110,7 @@ def dimfilter(grid, outgrid: str | None = None, **kwargs):
109110
110111
Returns
111112
-------
112-
ret: xarray.DataArray or None
113+
ret
113114
Return type depends on whether the ``outgrid`` parameter is set:
114115
115116
- :class:`xarray.DataArray` if ``outgrid`` is not set

pygmt/src/grdclip.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
grdclip - Change the range and extremes of grid values.
33
"""
44

5+
import xarray as xr
56
from pygmt.clib import Session
67
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
78

@@ -24,7 +25,7 @@
2425
Si="sequence",
2526
Sr="sequence",
2627
)
27-
def grdclip(grid, outgrid: str | None = None, **kwargs):
28+
def grdclip(grid, outgrid: str | None = None, **kwargs) -> xr.DataArray | None:
2829
r"""
2930
Set values in a grid that meet certain criteria to a new value.
3031
@@ -62,7 +63,7 @@ def grdclip(grid, outgrid: str | None = None, **kwargs):
6263
6364
Returns
6465
-------
65-
ret: xarray.DataArray or None
66+
ret
6667
Return type depends on whether the ``outgrid`` parameter is set:
6768
6869
- :class:`xarray.DataArray` if ``outgrid`` is not set

pygmt/src/grdcut.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
grdcut - Extract subregion from a grid.
33
"""
44

5+
import xarray as xr
56
from pygmt.clib import Session
67
from pygmt.helpers import (
78
GMTTempFile,
@@ -27,7 +28,7 @@
2728
f="coltypes",
2829
)
2930
@kwargs_to_strings(R="sequence")
30-
def grdcut(grid, **kwargs):
31+
def grdcut(grid, **kwargs) -> xr.DataArray | None:
3132
r"""
3233
Extract subregion from a grid.
3334
@@ -80,7 +81,7 @@ def grdcut(grid, **kwargs):
8081
8182
Returns
8283
-------
83-
ret: xarray.DataArray or None
84+
ret
8485
Return type depends on whether the ``outgrid`` parameter is set:
8586
8687
- :class:`xarray.DataArray` if ``outgrid`` is not set

pygmt/src/grdfill.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
grdfill - Fill blank areas from a grid.
33
"""
44

5+
import xarray as xr
56
from pygmt.clib import Session
67
from pygmt.exceptions import GMTInvalidInput
78
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
@@ -17,7 +18,7 @@
1718
V="verbose",
1819
)
1920
@kwargs_to_strings(R="sequence")
20-
def grdfill(grid, outgrid: str | None = None, **kwargs):
21+
def grdfill(grid, outgrid: str | None = None, **kwargs) -> xr.DataArray | None:
2122
r"""
2223
Fill blank areas from a grid file.
2324
@@ -51,7 +52,7 @@ def grdfill(grid, outgrid: str | None = None, **kwargs):
5152
5253
Returns
5354
-------
54-
ret: xarray.DataArray or None
55+
ret
5556
Return type depends on whether the ``outgrid`` parameter is set:
5657
5758
- :class:`xarray.DataArray` if ``outgrid`` is not set

pygmt/src/grdfilter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
grdfilter - Filter a grid in the space (or time) domain.
33
"""
44

5+
import xarray as xr
56
from pygmt.clib import Session
67
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
78

@@ -20,7 +21,7 @@
2021
x="cores",
2122
)
2223
@kwargs_to_strings(I="sequence", R="sequence")
23-
def grdfilter(grid, outgrid: str | None = None, **kwargs):
24+
def grdfilter(grid, outgrid: str | None = None, **kwargs) -> xr.DataArray | None:
2425
r"""
2526
Filter a grid in the space (or time) domain.
2627
@@ -97,7 +98,7 @@ def grdfilter(grid, outgrid: str | None = None, **kwargs):
9798
9899
Returns
99100
-------
100-
ret: xarray.DataArray or None
101+
ret
101102
Return type depends on whether the ``outgrid`` parameter is set:
102103
103104
- :class:`xarray.DataArray` if ``outgrid`` is not set

pygmt/src/grdgradient.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
grdgradient - Compute directional gradients from a grid.
33
"""
44

5+
import xarray as xr
56
from pygmt.clib import Session
67
from pygmt.exceptions import GMTInvalidInput
78
from pygmt.helpers import (
@@ -29,7 +30,7 @@
2930
n="interpolation",
3031
)
3132
@kwargs_to_strings(A="sequence", E="sequence", R="sequence")
32-
def grdgradient(grid, outgrid: str | None = None, **kwargs):
33+
def grdgradient(grid, outgrid: str | None = None, **kwargs) -> xr.DataArray | None:
3334
r"""
3435
Compute the directional derivative of the vector gradient of the data.
3536
@@ -138,7 +139,7 @@ def grdgradient(grid, outgrid: str | None = None, **kwargs):
138139
139140
Returns
140141
-------
141-
ret: xarray.DataArray or None
142+
ret
142143
Return type depends on whether the ``outgrid`` parameter is set:
143144
144145
- :class:`xarray.DataArray` if ``outgrid`` is not set

pygmt/src/grdhisteq.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import numpy as np
88
import pandas as pd
9+
import xarray as xr
910
from pygmt.clib import Session
1011
from pygmt.exceptions import GMTInvalidInput
1112
from pygmt.helpers import (
@@ -61,7 +62,9 @@ class grdhisteq: # noqa: N801
6162
h="header",
6263
)
6364
@kwargs_to_strings(R="sequence")
64-
def equalize_grid(grid, outgrid: str | None = None, **kwargs):
65+
def equalize_grid(
66+
grid, outgrid: str | None = None, **kwargs
67+
) -> xr.DataArray | None:
6568
r"""
6669
Perform histogram equalization for a grid.
6770
@@ -93,7 +96,7 @@ def equalize_grid(grid, outgrid: str | None = None, **kwargs):
9396
9497
Returns
9598
-------
96-
ret: xarray.DataArray or None
99+
ret
97100
Return type depends on the ``outgrid`` parameter:
98101
99102
- xarray.DataArray if ``outgrid`` is None

pygmt/src/grdlandmask.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
grdlandmask - Create a "wet-dry" mask grid from shoreline data base
33
"""
44

5+
import xarray as xr
56
from pygmt.clib import Session
67
from pygmt.exceptions import GMTInvalidInput
78
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
@@ -22,7 +23,7 @@
2223
x="cores",
2324
)
2425
@kwargs_to_strings(I="sequence", R="sequence", N="sequence", E="sequence")
25-
def grdlandmask(outgrid: str | None = None, **kwargs):
26+
def grdlandmask(outgrid: str | None = None, **kwargs) -> xr.DataArray | None:
2627
r"""
2728
Create a grid file with set values for land and water.
2829
@@ -80,7 +81,7 @@ def grdlandmask(outgrid: str | None = None, **kwargs):
8081
8182
Returns
8283
-------
83-
ret: xarray.DataArray or None
84+
ret
8485
Return type depends on whether the ``outgrid`` parameter is set:
8586
8687
- :class:`xarray.DataArray` if ``outgrid`` is not set

pygmt/src/grdproject.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
grdproject - Forward and inverse map transformation of grids.
33
"""
44

5+
import xarray as xr
56
from pygmt.clib import Session
67
from pygmt.exceptions import GMTInvalidInput
78
from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias
@@ -24,7 +25,7 @@
2425
r="registration",
2526
)
2627
@kwargs_to_strings(C="sequence", D="sequence", R="sequence")
27-
def grdproject(grid, outgrid: str | None = None, **kwargs):
28+
def grdproject(grid, outgrid: str | None = None, **kwargs) -> xr.DataArray | None:
2829
r"""
2930
Change projection of gridded data between geographical and rectangular.
3031
@@ -84,7 +85,7 @@ def grdproject(grid, outgrid: str | None = None, **kwargs):
8485
8586
Returns
8687
-------
87-
ret: xarray.DataArray or None
88+
ret
8889
Return type depends on whether the ``outgrid`` parameter is set:
8990
9091
- :class:`xarray.DataArray` if ``outgrid`` is not set

0 commit comments

Comments
 (0)