From 25e803883f70bda97cc7e7f5b5319690bca1074a Mon Sep 17 00:00:00 2001 From: Niklas Selke <n.selke@fz-juelich.de> Date: Wed, 9 Nov 2022 16:22:29 +0100 Subject: [PATCH] Added the mean seasonal cycle calculation for deseasonalizing the data before the trend analysis. --- toarstats/trends/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/toarstats/trends/utils.py b/toarstats/trends/utils.py index 2ef7fc1..5f18082 100644 --- a/toarstats/trends/utils.py +++ b/toarstats/trends/utils.py @@ -4,6 +4,8 @@ This module contains the following function: deseasonalize - calculate the trend using the requested method """ +import statsmodels.formula.api as smf + def deseasonalize(data): """Deseasonalize the data. @@ -13,4 +15,9 @@ def deseasonalize(data): :return: The deseasonalized data """ + seasonal_cycle = smf.ols( + "value~np.cos(month*2*np.pi/12)+np.sin(month*2*np.pi/12)" + "+np.cos(month*4*np.pi/12)+np.sin(month*4*np.pi/12)", + pd.DataFrame({"value": data["value"], "month": data.index.month}) + ).fit(method="qr").predict(pd.DataFrame({"month": range(1, 13)})) return data -- GitLab