Detrend Flux timeline with non-linear trend

I need to filter out stream time series data (light curves), but I ran into a problem when time series data does not have a simple linear trend.

I use scipy.signal.detrend () to divide linear cases, but this is not enough here.

I used numpy.polyfit () to try polynomial derivation, but I'm not sure what to do with the return polynomial coefficients.

Can anyone advise me on the next reasonable step? Or, if someone has a better method for determining non-linear data, I would be happy to hear that as well.

+4
source share
1 answer

, polyfit, polyval "x".

, - :

import numpy as np
import matplotlib.pyplot as plt

num = 1000
x = np.linspace(0, 10, num)
y = np.exp(x)

# Add some non-stationary noise that hard to see without de-trending
noise = 100 * np.exp(0.2 * x) * np.random.normal(0, 1, num)
y += noise

fig, ax = plt.subplots()
ax.plot(x, y, 'ro')
plt.show()

enter image description here

: y. . "" .

2- ( 2 model = np.polyfit(x, y, 2)):

import numpy as np
import matplotlib.pyplot as plt

num = 1000
x = np.linspace(0, 10, num)
y = np.exp(x)

# Add some non-stationary noise that hard to see without de-trending
noise = 100 * np.exp(0.2 * x) * np.random.normal(0, 1, num)
y += noise

# Detrend with a 2d order polynomial
model = np.polyfit(x, y, 2)
predicted = np.polyval(model, x)

fig, axes = plt.subplots(nrows=2, sharex=True)
axes[0].plot(x, y, 'ro')
axes[0].plot(x, predicted, 'k-')
axes[0].set(title='Original Data and 2nd Order Polynomial Trend')

axes[1].plot(x, y - predicted, 'ro')
axes[1].set(title='Detrended Residual')

plt.show()

enter image description here


, . , . , , ( ):

enter image description here

enter image description here

enter image description here

enter image description here

+9

Source: https://habr.com/ru/post/1569736/


All Articles