obspy.signal.detrend.polynomial

polynomial(data, order, plot=False)[source]

Removes a polynomial trend from the data.

Parameters
  • data (numpy.ndarray) – The data to detrend. Will be modified in-place.

  • order (int) – The order of the polynomial to fit.

  • 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 polynomial

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.

>>> polynomial(data, order=3, plot=True)  

(Source code, png)

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