From 0f53dffaa0b7c8eb08fb7040b1375423732cb883 Mon Sep 17 00:00:00 2001 From: Felix Kleinert <f.kleinert@fz-juelich.de> Date: Tue, 23 Mar 2021 17:07:17 +0100 Subject: [PATCH] update transform methods to proplery work when external transformation parameetrs are preovided --- mlair/data_handler/data_handler_single_station.py | 12 +++++++++++- mlair/data_handler/default_data_handler.py | 12 ++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/mlair/data_handler/data_handler_single_station.py b/mlair/data_handler/data_handler_single_station.py index 0c83e625..e9db27a9 100644 --- a/mlair/data_handler/data_handler_single_station.py +++ b/mlair/data_handler/data_handler_single_station.py @@ -195,7 +195,17 @@ class DataHandlerSingleStation(AbstractDataHandler): else: raise NotImplementedError - def f_apply(data, method, mean=None, std=None, min=None, max=None): + def f_apply(data, method, **kwargs): + for k, v in kwargs.items(): + if not (isinstance(v, xr.DataArray) or v is None): + _, opts = statistics.min_max(data, dim) + helper = xr.ones_like(opts['min']) + kwargs[k] = helper * v + mean = kwargs.pop('mean', None) + std = kwargs.pop('std', None) + min = kwargs.pop('min', None) + max = kwargs.pop('max', None) + if method == "standardise": return statistics.standardise_apply(data, mean, std), {"mean": mean, "std": std, "method": method} elif method == "centre": diff --git a/mlair/data_handler/default_data_handler.py b/mlair/data_handler/default_data_handler.py index 5eb6fd02..2eceff32 100644 --- a/mlair/data_handler/default_data_handler.py +++ b/mlair/data_handler/default_data_handler.py @@ -241,6 +241,8 @@ class DefaultDataHandler(AbstractDataHandler): * standardise (default, if method is not given) * centre + * min_max + * log ### mean and std estimation @@ -256,14 +258,16 @@ class DefaultDataHandler(AbstractDataHandler): If mean and std are not None, the default data handler expects this parameters to match the data and applies this values to the data. Make sure that all dimensions and/or coordinates are in agreement. + + ### min and max given + If min and max are not None, the default data handler expects this parameters to match the data and applies + this values to the data. Make sure that all dimensions and/or coordinates are in agreement. """ sp_keys = {k: copy.deepcopy(kwargs[k]) for k in cls._requirements if k in kwargs} - transformation_dict = sp_keys.get("transformation", None) - if transformation_dict is None: + if "transformation" not in sp_keys.keys(): return - if isinstance(transformation_dict, dict): # tuple for (input, target) transformation - transformation_dict = copy.deepcopy(transformation_dict), copy.deepcopy(transformation_dict) + transformation_dict = ({}, {}) def _inner(): """Inner method that is performed in both serial and parallel approach.""" -- GitLab