obspy.signal.detrend.spline

spline(data, order, dspline, plot=False)[source]

Remove a trend by fitting splines.

Parameters:
  • data (numpy.ndarray) The data to detrend. Will be modified in-place.
  • order (int) The order/degree of the smoothing spline to fit. Must be 1 <= order <= 5.
  • dspline (int) The distance in samples between two spline nodes.
  • plot (bool or str) If True, a plot of the operation happening will be shown. If a string is given that plot will be saved to the given file name.

Note

In a real world application please make sure to use the convenience obspy.core.trace.Trace.detrend() method.

Example

>>> import obspy
>>> from obspy.signal.detrend import spline

Prepare some example data.

>>> tr = obspy.read()[0].filter("highpass", freq=2)
>>> tr.data += 6000 + 4 * tr.times() ** 2
>>> tr.data -= 0.1 * tr.times() ** 3 + 0.00001 * tr.times() ** 5
>>> data = tr.data

Remove the trend.

>>> spline(data, order=2, dspline=1000, plot=True)  

(Source code, png, hires.png)

../../_images/obspy-signal-detrend-spline-1.png