pygmt.dimfilter
- pygmt.dimfilter(grid, *, distance=None, filter=None, outgrid=None, spacing=None, sectors=None, region=None, verbose=None, **kwargs)[source]
Filter a grid file by dividing the filter circle.
Filter a grid file in the space (or time) domain by dividing the given filter circle into n_sectors, applying one of the selected primary convolution or non-convolution filters to each sector, and choosing the final outcome according to the selected secondary filter. It computes distances using Cartesian or Spherical geometries. The output .nc file can optionally be generated as a subregion of the input and/or with a new -Increment. In this way, one may have “extra space” in the input data so that there will be no edge effects for the output grid. If the filter is low-pass, then the output may be less frequently sampled than the input. The -Q option is for the error analysis mode and expects the input file to contains the filtered depths. Finally, one should know that dimfilter will not produce a smooth output as other spatial filters do because it returns a minimum median out of N medians of N sectors. The output can be rough unless the input data is noise-free. Thus, an additional filtering (e.g., Gaussian via grdfilter) of the DiM-filtered data is generally recommended.
Full option list at https://docs.generic-mapping-tools.org/latest/dimfilter.html
Aliases:
D = distance
F = filter
G = outgrid
I = spacing
N = sectors
R = region
V = verbose
- Parameters
grid (str or xarray.DataArray) – The file name of the input grid or the grid loaded as a DataArray.
outgrid (str or None) – The name of the output netCDF file with extension .nc to store the grid in.
Distance flag tells how grid (x,y) relates to filter width, as follows:
0: grid (x,y) in same units as width, Cartesian distances.
1: grid (x,y) in degrees, width in kilometers, Cartesian distances.
2: grid (x,y) in degrees, width in km, dx scaled by cos(middle y), Cartesian distances.
The above options are fastest because they allow weight matrix to be computed only once. The next two options are slower because they recompute weights for each latitude.
3: grid (x,y) in degrees, width in km, dx scaled by cosine(y), Cartesian distance calculation.
4: grid (x,y) in degrees, width in km, Spherical distance calculation.
filter (str) –
xwidth[+l|u] Sets the primary filter type. Choose among convolution and non-convolution filters. Append the filter code x followed by the full diameter width. Available convolution filters are:
(b) Boxcar: All weights are equal.
(c) Cosine Arch: Weights follow a cosine arch curve.
(g) Gaussian: Weights are given by the Gaussian function.
Non-convolution filters are:
(m) Median: Returns median value.
(p) Maximum likelihood probability (a mode estimator): Return modal value. If more than one mode is found we return their average value. Append +l or +h to the filter width if you want to return the smallest or largest of each sector’s modal values.
sectors (str) –
xsectors[+l|u] Sets the secondary filter type x and the number of bow-tie sectors. sectors must be integer and larger than 0. When sectors is set to 1, the secondary filter is not effective. Available secondary filters x are:
(l) Lower: Return the minimum of all filtered values.
(u) Upper: Return the maximum of all filtered values.
(a) Average: Return the mean of all filtered values.
(m) Median: Return the median of all filtered values.
(p) Mode: Return the mode of all filtered values: If more than one mode is found we return their average value. Append +l or +h to the sectors if you rather want to return the smallest or largest of the modal values.
spacing (str) –
xinc[+e|n][/yinc[+e|n]]. x_inc [and optionally y_inc] is the grid spacing.
Geographical (degrees) coordinates: Optionally, append an increment unit. Choose among m to indicate arc minutes or s to indicate arc seconds. If one of the units e, f, k, M, n or u is appended instead, the increment is assumed to be given in meter, foot, km, mile, nautical mile or US survey foot, respectively, and will be converted to the equivalent degrees longitude at the middle latitude of the region (the conversion depends on PROJ_ELLIPSOID). If y_inc is given but set to 0 it will be reset equal to x_inc; otherwise it will be converted to degrees latitude.
All coordinates: If +e is appended then the corresponding max x (east) or y (north) may be slightly adjusted to fit exactly the given increment [by default the increment may be adjusted slightly to fit the given domain]. Finally, instead of giving an increment you may specify the number of nodes desired by appending +n to the supplied integer argument; the increment is then recalculated from the number of nodes, the registration, and the domain. The resulting increment value depends on whether you have selected a gridline-registered or pixel-registered grid; see GMT File Formats for details.
Note: If
region=grdfile
is used then the grid spacing and the registration have already been initialized; usespacing
andregistration
to override these values.region (str or list) – xmin/xmax/ymin/ymax[+r][+uunit]. Specify the region of interest.
Select verbosity level [Default is w], which modulates the messages written to stderr. Choose among 7 levels of verbosity:
q - Quiet, not even fatal error messages are produced
e - Error messages only
w - Warnings [Default]
t - Timings (report runtimes for time-intensive algorithms);
i - Informational messages (same as
verbose=True
)c - Compatibility warnings
d - Debugging messages
- Returns
ret (xarray.DataArray or None) – Return type depends on whether the
outgrid
parameter is set:xarray.DataArray
ifoutgrid
is not setNone if
outgrid
is set (grid output will be stored in file set byoutgrid
)