From e0d7bd853a645f293736abd0b2a1cf6f276b4dc0 Mon Sep 17 00:00:00 2001 From: Niklas Selke <n.selke@fz-juelich.de> Date: Thu, 6 Oct 2022 10:53:07 +0200 Subject: [PATCH] Added the boilerplate code for the deseasonalization of data. --- toarstats/trends/interface.py | 8 +++++--- toarstats/trends/utils.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 toarstats/trends/utils.py diff --git a/toarstats/trends/interface.py b/toarstats/trends/interface.py index b6b928a..f4ce663 100644 --- a/toarstats/trends/interface.py +++ b/toarstats/trends/interface.py @@ -6,6 +6,7 @@ calculate_trend - calculate the trend using the requested method from toarstats.trends.ols import ols from toarstats.trends.quant_reg import quant_reg +from toarstats.trends.utils import deseasonalize def calculate_trend(method, data, formula="value ~ datetime", quantiles=None): @@ -30,14 +31,15 @@ def calculate_trend(method, data, formula="value ~ datetime", quantiles=None): :return: The result of the fit or a list of fit results if ``method="quant"`` and multiple quantiles are given """ + deseasonalized_data = deseasonalize(data) if method == "OLS": - fit = ols(data, formula) + fit = ols(deseasonalized_data, formula) elif method == "quant": try: - fit = [quant_reg(data, formula, quantile) + fit = [quant_reg(deseasonalized_data, formula, quantile) for quantile in quantiles] except TypeError: - fit = quant_reg(data, formula, quantiles) + fit = quant_reg(deseasonalized_data, formula, quantiles) else: raise ValueError(f"{method} is not recognized, must be 'OLS' or" " 'quant'") diff --git a/toarstats/trends/utils.py b/toarstats/trends/utils.py new file mode 100644 index 0000000..2ef7fc1 --- /dev/null +++ b/toarstats/trends/utils.py @@ -0,0 +1,16 @@ +"""This module contains helper functions for the trends subpackage. + +This module contains the following function: +deseasonalize - calculate the trend using the requested method +""" + + +def deseasonalize(data): + """Deseasonalize the data. + + :param data: data containing a list of date time values and + associated parameter values + + :return: The deseasonalized data + """ + return data -- GitLab