Skip to content

pygmt.filter1d: Time domain filtering of 1-D data tables #4551

Closed

Description

@seisman

This issue serves as the central place for discussing and tracking the implementation of the pygmt.filter1d 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/figure output).
  • ⬜ -D: increment – Sets the resolution (sampling interval) of the time axis for irregularly spaced data. Without it, data are assumed to be evenly spaced.
  • ☑️ -E: end – Include the ends of the time series in output (default loses half the filter-width at each end).
  • ☑️ -F: filter_type – Primary filter type and width (convolution: b, c, g, f; non-convolution: m, p, l, L, u, U; uppercase variants for robust versions) with optional +h (high-pass) and +l/+u modifiers.
  • ⬜ -I: spacing – Sets the output sampling interval (if different from the input spacing).
  • -J: Not applicable (no map projection).
  • ⬜ -L: gap_width – Largest gap in data (in time units) that the filter will tolerate. Segments with larger gaps will be skipped.
  • ☑️ -N: time_col – Column index of the independent variable (time). Default is column 0 (leftmost).
  • ⬜ -Q: quality_factor – Quality threshold: the fraction of the filter window that must contain valid data for output to be produced at that point (0–1).
  • -R: Not applicable for 1-D table filtering.
  • ⬜ -S: symmetry_factor – Symmetry requirement: the minimum fraction of the total filter weight that must be present on each side of a data point for it to be used (0–0.5).
  • ⬜ -T: time_axis – Construct the output time axis from tmin/tmax/tinc (or from a file of times), overriding the data-derived time axis.
  • ☑️ -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 filter1d output directly. The TIME_UNIT parameter may be relevant when working with time-series data where column units differ from the expected time axis units.

Notes on Input Formats

  • data: Accepts a file path (string or pathlib.Path), a 2-D numpy.ndarray, a pandas.DataFrame, or any table-like object. Each row is a data record; columns represent different variables.
  • filter_type (-F): A string of the form <code><width>[+h][+l|+u], e.g. "g5" for a Gaussian filter with a width of 5 time units. Uppercase codes (B, C, G, M, P, F) use robust versions that replace outliers with the median before filtering.
  • time_col (-N): Zero-indexed integer specifying which column holds the independent variable. All other columns are treated as data to be filtered.
  • output_type: Controls the return type — "pandas" (default), "numpy", or "file" (requires outfile).
  • For multi-segment data (multiple time series in one file), a filter-width file passed via filter_type="f<filename>" must either have the same number of segments or a single segment applied to all.

Linked Pull Requests

  • Initial feature implementation – #1512
  • Fix bug where first line was read as header – #2780
  • Improve performance by storing output in virtual files – #3085
  • Formally alias unimplemented options: -D (increment), -I (spacing), -L (gap_width), -Q (quality_factor), -S (symmetry_factor), -T (time_axis)
  • Add a tutorial or gallery example demonstrating 1-D time series filtering (e.g., smoothing the Mauna Loa CO₂ dataset with different filter types)

Related Issues and Discussions

  • The Mauna Loa CO₂ dataset (pygmt.datasets.load_sample_data(name="maunaloa_co2")) is already used in the test suite and would be a natural choice for a gallery or tutorial example.
  • filter1d operates on tabular data (not grids); for filtering 2-D grids, see pygmt.grdfilter (isotropic) or pygmt.dimfilter (directional).
  • No xarray accessor is needed since filter1d operates on 1-D columnar data rather than gridded arrays.
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