Skip to content

Commit b8432dc

Browse files
committed
pygmt.grdfilter: Let the parameter nans support descriptive arguments
1 parent 74b3cf7 commit b8432dc

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

pygmt/src/grdfilter.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313

1414

1515
@fmt_docstring
16-
@use_alias(D="distance", F="filter", N="nans", f="coltypes")
16+
@use_alias(D="distance", F="filter", f="coltypes")
1717
def grdfilter(
1818
grid: PathLike | xr.DataArray,
1919
outgrid: PathLike | None = None,
20-
toggle: bool = False,
2120
spacing: Sequence[float | str] | None = None,
21+
nans: Literal["ignore", "replace", "preserve"] | None = None,
22+
toggle: bool = False,
2223
region: Sequence[float | str] | str | None = None,
23-
registration: Literal["gridline", "pixel"] | bool = False,
2424
verbose: Literal["quiet", "error", "warning", "timing", "info", "compat", "debug"]
2525
| bool = False,
26+
registration: Literal["gridline", "pixel"] | bool = False,
2627
cores: int | bool = False,
2728
**kwargs,
2829
) -> xr.DataArray | None:
@@ -43,6 +44,7 @@ def grdfilter(
4344
4445
$aliases
4546
- I = spacing
47+
- N = nans
4648
- R = region
4749
- T = toggle
4850
- V = verbose
@@ -87,21 +89,22 @@ def grdfilter(
8789
calculation.
8890
- ``"5"``: grid (x,y) in Mercator ``projection="m1"`` img units,
8991
*width* in km, Spherical distance calculation.
90-
9192
$spacing
92-
nans : str or float
93-
**i**\|\ **p**\|\ **r**.
94-
Determine how NaN-values in the input grid affect the filtered output.
95-
Use **i** to ignore all NaNs in the calculation of the filtered value
96-
[Default]. **r** is same as **i** except if the input node was NaN then
97-
the output node will be set to NaN (only applies if both grids are
98-
co-registered). **p** will force the filtered value to be NaN if any
99-
grid nodes with NaN-values are found inside the filter circle.
100-
$region
93+
nans
94+
Determine how NaN-values in the input grid affect the filtered output. Choose
95+
one of:
96+
97+
- ``"ignore"``: Ignore all NaNs in the calculation of filtered value [Default].
98+
- ``"replace"``: Similar to ``"ignore"`` except if the input node was NaN then
99+
the output node will be set to NaN (only applies if both grids are
100+
co-registered).
101+
- ``"preserve"``: Force the filtered value to be NaN if any grid nodes with
102+
NaN-values are found inside the filter circle.
101103
toggle
102104
Toggle the node registration for the output grid so as to become the opposite of
103105
the input grid [Default gives the same registration as the input grid].
104106
Alternatively, use ``registration`` to set the registration explicitly.
107+
$region
105108
$verbose
106109
$coltypes
107110
$registration
@@ -120,8 +123,8 @@ def grdfilter(
120123
--------
121124
>>> from pathlib import Path
122125
>>> import pygmt
123-
>>> # Apply a filter of 600 km (full width) to the @earth_relief_30m_g file
124-
>>> # and return a filtered field (saved as netCDF)
126+
>>> # Apply a filter of 600 km (full width) to the @earth_relief_30m_g file and
127+
>>> # return a filtered field (saved as netCDF)
125128
>>> pygmt.grdfilter(
126129
... grid="@earth_relief_30m_g",
127130
... filter="m600",
@@ -131,13 +134,16 @@ def grdfilter(
131134
... outgrid="filtered_pacific.nc",
132135
... )
133136
>>> Path("filtered_pacific.nc").unlink() # Cleanup file
134-
>>> # Apply a Gaussian smoothing filter of 600 km to the input DataArray
135-
>>> # and return a filtered DataArray with the smoothed field
137+
>>> # Apply a Gaussian smoothing filter of 600 km to the input DataArray and return
138+
>>> # a filtered DataArray with the smoothed field
136139
>>> grid = pygmt.datasets.load_earth_relief()
137140
>>> smooth_field = pygmt.grdfilter(grid=grid, filter="g600", distance="4")
138141
"""
139142
aliasdict = AliasSystem(
140143
I=Alias(spacing, name="spacing", sep="/", size=2),
144+
N=Alias(
145+
nans, name="nans", mapping={"ignore": "i", "replace": "r", "preserve": "p"}
146+
),
141147
T=Alias(toggle, name="toggle"),
142148
).add_common(
143149
R=region,

0 commit comments

Comments
 (0)