Assymetric gaussian funciton fitting in Python for time series

24 Views Asked by At

I have a NDVI (indice from -1 to 1 indicating growth of plants) time series, for example

ts=np.array([0.8821, 0.7118, 0.6271, 0.2289, 0.2003, 0.1658, 0.3492, 0.3385, 0.7882, 0.8434,
 0.8691, 0.8546, 0.8451, 0.8419,0.8524, 0.8249, 0.8573, 0.8339, 0.8026, 0.7707,
 0.7758, 0.7362, 0.6913, 0.6461, 0.4875, 0.3913, 0.2732, 0.2132, 0.2077, 0.1861])
doy_vector = range(0,len(ts[0:30]))

I would like to fit an asymetric gaussiang function to this data according to this: Asymmetric gaussian fitting method, which tells that it is a good method for smoothing NDVI series.

I am relatively new to Python and estimating methods specially, but I am aware of curve_fit function of scipy.optimize. Is it possible to fit this Asymetric gaussian method to the data using curve_fit?

I have tried so far:

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

def g(t, a1, a2, a3, a4, a5):
    return np.where(t > a1, np.exp(-((t - a1) / a2)**a3), np.exp(-((a1 - t) / a4)**a5))
def f(t, c1, c2, a1, a2, a3, a4, a5):
    return c1 + c2 * g(t, a1, a2, a3, a4, a5)
I = ts
sigma = np.ones_like(I) #what can I put here for weights?
n1 = 0
n2 = len(doy_vector) - 1
def chi2(t, c1, c2, a1, a2, a3, a4, a5, I, sigma):
   return (f(t, c1, c2, a1, a2, a3, a4, a5) - I) / sigma
initial_guess = [1, 1, 50, 10, 2, 10, 2]  # Valores iniciais dos parĂ¢metros
params, covariance = curve_fit(chi2, ....)

But now I am struggling to use the function. Is this approach correct? If so, how can I can adequately complete curve_fit(chi2, ....)?

Thank you.

0

There are 0 best solutions below