Skip to content

Conversation

@seisman
Copy link
Member

@seisman seisman commented Feb 9, 2026

This PR is a subset of PR #4378, aiming to implement a Pythonic interface for the -F option of the grdfilter module.

The full syntax of the -F option is (https://docs.generic-mapping-tools.org/dev/grdfilter.html#f):

-Fxwidth[/width2][+c|+h|+l|+qquantile|+u]

GMT supports 12 different types of filters, which can be specified by x. For most filters, the syntax is very simple (e.g., -Fg600). Some filters can accept more modifiers. For example, histogram filter accepts +c/+l/+u; median filter accepts +q; Maximum likelihood probability filter accepts +l/+u; and all filters accept +h (for highpass). For custom and operator filters, width is actually a weight file. As a result, this option is complicated to implement.

PR #4378 tries to alias the -F option to multiple parameters filter_type/filter_width/highpass/hist_bin_width/median_quantile/hist_center_bins/mode_extreme. As you can see, that PR is already very big and there are still many edge cases to be covered. I feel that PR will take a very long time to finish and will definitely delay the submission of the paper. Instead, I'm opening this PR to implement a subset of the -F option, which should cover most (80%, I guess) use cases of the -Foption. A more feature-complete version can be added after the paper submission.

Previously, the -F option is aliased to a single parameter filter. In this PR, three new parameters are added:

  • filter_type: specify the filter type
  • filter_width: specify the filter width
  • highpass: for the +h modifier

Then, in our paper, filter="g600" would be filter_type="gaussian", filter_width=600.

We still need to discuss the parameter names:

  • filter is a built-in function in Python, so the old alias filter is not a good name.
  • filter_type/filter_width are good, but the prefix filter_ is not necessary as the method name is grdfilter (and da.gmt.filter in the GMT accessor). But type is also a built-in function in Python.

I feel we have some choices:

  1. filter_type/filter_width
  2. filter_type/width
  3. filter/width
  4. type/width

I'm a little inclined to filter/width. What do you think @GenericMappingTools/pygmt-maintainers?

Preview: https://pygmt-dev--4401.org.readthedocs.build/en/4401/api/generated/pygmt.grdfilter.html

@seisman seisman added the needs review This PR has higher priority and needs review. label Feb 9, 2026
@seisman seisman changed the title pygmt.grdfilter: Add parameters filter_type/filter_width to set the filter [Part 1] WIP: pygmt.grdfilter: Add parameters filter_type/filter_width to set the filter [Part 1] Feb 9, 2026
@seisman seisman added this to the 0.19.0 milestone Feb 10, 2026
@seisman seisman added the enhancement Improving an existing feature label Feb 10, 2026
Comment on lines +55 to +62
mapping={
"boxcar": "b",
"cosine_arch": "c",
"gaussian": "g",
"minall": "l",
"minpos": "L",
"maxall": "u",
"maxneg": "U",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seisman seisman changed the title WIP: pygmt.grdfilter: Add parameters filter_type/filter_width to set the filter [Part 1] pygmt.grdfilter: Add parameters filter_type/filter_width to set the filter [Part 1] Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improving an existing feature high-priority needs review This PR has higher priority and needs review.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant