Skip to content

pygmt.dimfilter: Directional filtering of grids in the space domain #4550

Closed

Description

@seisman

This issue serves as the central place for discussing and tracking the implementation of the pygmt.dimfilter method in PyGMT. The issue will be closed when the initial implementation is complete. Progress is tracked at PyGMT: Wrapping GMT modules.

Documentation

GMT Option Flags and Modifiers

☑️: Implemented; ⬜: To be implemented/discussed; Strikethrough: Won't implement.

  • -B: Not applicable (no map output).
  • ☑️ -D: distance – Distance flag specifying how grid (x,y) relates to filter width (Cartesian or Spherical).
  • ☑️ -F: filter – Primary filter type (boxcar, cosine arch, gaussian, median, p mode), followed by diameter width and optional +l/+u modifiers.
  • ☑️ -G: outgrid – Output grid file name.
  • ☑️ -I: spacing – Output grid increment (x_inc[/y_inc]).
  • -J: Not applicable (no map projection output).
  • ☑️ -N: sectors – Secondary filter type (lower, upper, average, median, pmode) and number of bow-tie sectors, with optional +l/+u modifiers.
  • ⬜ -Q: Quick mode – Applies sector averaging without spatial filtering (i.e., skip the primary filter step). Currently passable via **kwargs but not formally aliased.
  • ☑️ -R: region – Output region [xmin, xmax, ymin, ymax].
  • ⬜ -T: Toggle node registration – If the output should have the opposite registration to the input grid.
  • ☑️ -V: verbose – Verbosity level.
  • -X/-Y: Use Figure.shift_origin instead.
  • --PAR=value: Use pygmt.config instead.

Related GMT configurations

No specific GMT defaults are known to affect dimfilter output. Users working with geographic grids and large filter widths may want to verify PROJ_ELLIPSOID is set appropriately when using spherical distance calculations (distance=4).

Notes on Input Formats

  • grid: Accepts a file path (string or pathlib.Path) or an xarray.DataArray representing a 2-D raster grid.
  • filter (-F): A string of the form <code><width>[+l|+u], e.g. "m600" for a 600 km wide median filter. The width unit is kilometres when distance is ≥ 1, or the same units as the grid when distance=0.
  • sectors (-N): A string of the form <code><sectors>[+l|+u], e.g. "l6" for six sectors using the lower (minimum) secondary filter.
  • distance (-D): An integer 0–4 controlling how horizontal distances are computed; higher values use more accurate (but slower) spherical geometry.
  • At least one of distance, filter, and sectors must be provided unless -Q (quick mode) is used.

Linked Pull Requests

  • Initial feature implementation – #1492
  • Add inline doctest example – #1956
  • Formally alias -Q (quick mode) and -T (toggle registration)
  • Add a tutorial or gallery example demonstrating directional filtering and comparison with pygmt.grdfilter

Related Issues and Discussions

  • The dimfilter function is also exposed via the xarray accessor (DataArray.gmt.dimfilter).
  • For follow-up smoothing of DiM-filtered output (which can be rough), see pygmt.grdfilter (Gaussian or other isotropic filters).
  • Upstream GMT reference: Wessel, P., and Bercovici, D. (1998), "Interpolation with splines in tension: A Green's function approach", Mathematical Geology, 30, 77–93.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions