1515
1616
1717@fmt_docstring
18- @use_alias (D = "distance" , F = "filter" , f = "coltypes" )
18+ @use_alias (F = "filter" , f = "coltypes" )
1919def grdfilter (
2020 grid : PathLike | xr .DataArray ,
2121 outgrid : PathLike | None = None ,
22+ distance : Literal [
23+ "pixel" ,
24+ "cartesian" ,
25+ "geo_cartesian" ,
26+ "geo_flatearth1" ,
27+ "geo_flatearth2" ,
28+ "geo_spherical" ,
29+ "geo_mercator" ,
30+ ]
31+ | None = None ,
2232 spacing : Sequence [float | str ] | None = None ,
2333 nans : Literal ["ignore" , "replace" , "preserve" ] | None = None ,
2434 toggle : bool = False ,
@@ -45,6 +55,7 @@ def grdfilter(
4555 Full GMT docs at :gmt-docs:`grdfilter.html`.
4656
4757 $aliases
58+ - D = distance
4859 - G = outgrid
4960 - I = spacing
5061 - N = nans
@@ -71,27 +82,50 @@ def grdfilter(
7182 - **p**: Maximum Likelihood probability
7283 - **h**: Histogram
7384
74- distance : str
75- State how the grid (x,y) relates to the filter *width*:
76-
77- - ``"p"``: grid (px,py) with *width* an odd number of pixels,
78- Cartesian distances.
79- - ``"0"``: grid (x,y) same units as *width*, Cartesian distances.
80- - ``"1"``: grid (x,y) in degrees, *width* in kilometers, Cartesian
81- distances.
82- - ``"2"``: grid (x,y) in degrees, *width* in km, dx scaled by
83- cos(middle y), Cartesian distances.
84-
85- The above options are fastest because they allow weight matrix to be
86- computed only once. The next three options are slower because they
87- recompute weights for each latitude.
88-
89- - ``"3"``: grid (x,y) in degrees, *width* in km, dx scaled by cos(y),
90- Cartesian distance calculation.
91- - ``"4"``: grid (x,y) in degrees, *width* in km, Spherical distance
92- calculation.
93- - ``"5"``: grid (x,y) in Mercator ``projection="m1"`` img units,
94- *width* in km, Spherical distance calculation.
85+ distance
86+ Distance *flag* tells how grid (*x, y*) relates to filter *width* as follows:
87+
88+ .. list-table::
89+ :header-rows: 1
90+ :widths: 16 32 20 32
91+
92+ * - Name
93+ - Grid (x,y)
94+ - Width
95+ - Distance Calculation
96+ * - ``"pixel"``
97+ - Pixels (px, py)
98+ - Odd number of pixels
99+ - Cartesian
100+ * - ``"cartesian"``
101+ - Same units as *width*
102+ - Any
103+ - Cartesian
104+ * - ``"geo_cartesian"``
105+ - Degrees
106+ - km
107+ - Cartesian
108+ * - ``"geo_flatearth1"``
109+ - Degrees
110+ - km
111+ - Cartesian, dx scaled by cos(middle y)
112+ * - ``"geo_flatearth2"``
113+ - Degrees
114+ - km
115+ - Cartesian, dx scaled by cos(y) per row
116+ * - ``"geo_spherical"``
117+ - Degrees
118+ - km
119+ - Spherical (great circle)
120+ * - ``"geo_mercator"``
121+ - Mercator **-Jm1** img units
122+ - km
123+ - Spherical
124+
125+ The first four options are fastest because they allow weight matrix to be
126+ computed only once. The last three options are slower because they recompute
127+ weights for each latitude.
128+
95129 $spacing
96130 nans
97131 Determine how NaN-values in the input grid affect the filtered output grid.
@@ -131,7 +165,7 @@ def grdfilter(
131165 >>> pygmt.grdfilter(
132166 ... grid="@earth_relief_30m_g",
133167 ... filter="m600",
134- ... distance="4 ",
168+ ... distance="geo_spherical ",
135169 ... region=[150, 250, 10, 40],
136170 ... spacing=0.5,
137171 ... outgrid="filtered_pacific.nc",
@@ -140,9 +174,22 @@ def grdfilter(
140174 >>> # Apply a Gaussian smoothing filter of 600 km to the input DataArray and return
141175 >>> # a filtered DataArray with the smoothed grid.
142176 >>> grid = pygmt.datasets.load_earth_relief()
143- >>> smooth_field = pygmt.grdfilter(grid=grid, filter="g600", distance="4 ")
177+ >>> smoothed = pygmt.grdfilter(grid=grid, filter="g600", distance="geo_spherical ")
144178 """
145179 aliasdict = AliasSystem (
180+ D = Alias (
181+ distance ,
182+ name = "distance" ,
183+ mapping = {
184+ "pixel" : "p" ,
185+ "cartesian" : 0 ,
186+ "geo_cartesian" : 1 ,
187+ "geo_flatearth1" : 2 ,
188+ "geo_flatearth2" : 3 ,
189+ "geo_spherical" : 4 ,
190+ "geo_mercator" : 5 ,
191+ },
192+ ),
146193 I = Alias (spacing , name = "spacing" , sep = "/" , size = 2 ),
147194 N = Alias (
148195 nans , name = "nans" , mapping = {"ignore" : "i" , "replace" : "r" , "preserve" : "p" }
0 commit comments