vista.algorithms.tracks.savitzky_golay.SavitzkyGolayFilter

class vista.algorithms.tracks.savitzky_golay.SavitzkyGolayFilter(track, radius=2, polyorder=2)[source]

Applies Savitzky-Golay filter to smooth track trajectories.

The Savitzky-Golay filter smooths data by fitting successive sub-sets of adjacent data points with a low-degree polynomial using least-squares. This preserves features of the distribution such as relative maxima, minima and width better than adjacent averaging.

Parameters:
  • track (Track) – Input track to smooth

  • radius (int, optional) – Radius of the smoothing window. The window length will be 2*radius + 1. Must be large enough to satisfy window_length > polyorder. By default 2

  • polyorder (int, optional) – Order of the polynomial used to fit the samples. Must be less than window_length (2*radius + 1). By default 2

__call__()[source]

Execute the filtering and return results

Examples

>>> filter = SavitzkyGolayFilter(track, radius=3, polyorder=2)
>>> results = filter()
>>> smoothed_track = results['smoothed_track']

Notes

  • The Savitzky-Golay filter requires at least window_length = 2*radius + 1 points

  • The polynomial order must be less than the window length

  • Edge effects: The filter uses ‘interp’ mode which interpolates at the boundaries

__init__(track, radius=2, polyorder=2)[source]

Initialize the Savitzky-Golay filter.

Parameters:
  • track (Track) – Input track to smooth

  • radius (int, optional) – Radius of the smoothing window, by default 2

  • polyorder (int, optional) – Order of the polynomial, by default 2

Methods

__init__(track[, radius, polyorder])

Initialize the Savitzky-Golay filter.

__init__(track, radius=2, polyorder=2)[source]

Initialize the Savitzky-Golay filter.

Parameters:
  • track (Track) – Input track to smooth

  • radius (int, optional) – Radius of the smoothing window, by default 2

  • polyorder (int, optional) – Order of the polynomial, by default 2

__call__()[source]

Execute Savitzky-Golay filtering on the track.

Returns:

Dictionary containing: - ‘smoothed_track’: Track object with smoothed positions - ‘original_rows’: Original row positions before smoothing - ‘original_columns’: Original column positions before smoothing - ‘smoothed_rows’: Smoothed row positions - ‘smoothed_columns’: Smoothed column positions

Return type:

dict

Raises:

ValueError – If window length is greater than number of track points, or if polyorder >= window_length, or if track has fewer than 3 points