diff --git a/toarstats/trends/interface.py b/toarstats/trends/interface.py index b6b928a261447d260777986996feb09efbb76f9a..f4ce6637549e9d0c46357000a36fd6a3cafc19a8 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 0000000000000000000000000000000000000000..2ef7fc185c7aa1767b735362279a3418e7242ece --- /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