diff --git a/mlair/data_handler/data_handler_single_station.py b/mlair/data_handler/data_handler_single_station.py index cb0a4803b7dd5825c7c3a63622766a02ce40811b..9fdba43cc2b6b3f9ed7a6d97dbd43ec86f03a1f7 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: