From 29e9f14a98fad2d5d8771c2e8eb887155b59357c Mon Sep 17 00:00:00 2001 From: Felix Kleinert <f.kleinert@fz-juelich.de> Date: Thu, 1 Apr 2021 15:21:22 +0200 Subject: [PATCH] extarct method from make_history to _make_and_return_history_window --- .../data_handler_single_station.py | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/mlair/data_handler/data_handler_single_station.py b/mlair/data_handler/data_handler_single_station.py index cb0a4803..9fdba43c 100644 --- a/mlair/data_handler/data_handler_single_station.py +++ b/mlair/data_handler/data_handler_single_station.py @@ -521,9 +521,29 @@ class DataHandlerSingleStation(AbstractDataHandler): expression :param dim_name_of_shift: Dimension along shift will be applied """ + history = self._make_and_return_history_window(dim_name_of_shift, window) + self.history = history + # self.history = self.shift(data, dim_name_of_shift, window, offset=self.window_history_offset) + + def _make_and_return_history_window(self, dim_name_of_shift, window, data=None): + """ + Create a xr.DataArray containing history data. + + Shift the data window+1 times and return a xarray which has a new dimension 'window' containing the shifted + data. This is used to represent history in the data. Results are stored in history attribute. + + :param dim_name_of_inputs: Name of dimension which contains the input variables + :param window: number of time steps to look back in history + Note: window will be treated as negative value. This should be in agreement with looking back on + a time line. Nonetheless positive values are allowed but they are converted to its negative + expression + :param dim_name_of_shift: Dimension along shift will be applied + """ + if data is None: + data = self.input_data window = -abs(window) - data = self.input_data - self.history = self.shift(data, dim_name_of_shift, window, offset=self.window_history_offset) + history = self.shift(data, dim_name_of_shift, window, offset=self.window_history_offset) + return history def make_labels(self, dim_name_of_target: str, target_var: str_or_list, dim_name_of_shift: str, window: int) -> None: -- GitLab