diff --git a/saqc/funcs/harm_functions.py b/saqc/funcs/harm_functions.py index 311369fa14ee011c5145b2f917cbc1d5e134e626..9e42db1b518e1055380e07a7fcf4195f314119b4 100644 --- a/saqc/funcs/harm_functions.py +++ b/saqc/funcs/harm_functions.py @@ -844,8 +844,9 @@ def interpolate2Grid(data, field, flagger, freq, interpolation_method, interpola **kwargs) -def aggregate(data, field, flagger, source_freq, target_freq, agg_func=np.mean, sample_func=np.mean, - invalid_flags=None, max_invalid=np.inf, **kwargs): +@register('downsample') +def downsample(data, field, flagger, sample_freq, agg_freq, sample_func=np.mean, agg_func=np.mean, + invalid_flags=None, max_invalid=np.inf, **kwargs): # define the "fastest possible" aggregator if sample_func is None: @@ -868,7 +869,7 @@ def aggregate(data, field, flagger, source_freq, target_freq, agg_func=np.mean, sample_func_name = sample_func.__name__ if max_invalid < np.inf: def aggregator(x): - y = getattr(x.resample(source_freq), sample_func_name)() + y = getattr(x.resample(sample_freq), sample_func_name)() if y.isna().sum() < max_invalid: return agg_func(y) else: @@ -876,25 +877,25 @@ def aggregate(data, field, flagger, source_freq, target_freq, agg_func=np.mean, else: def aggregator(x): - return agg_func(getattr(x.resample(source_freq), sample_func_name)()) + return agg_func(getattr(x.resample(sample_freq), sample_func_name)()) else: if max_invalid < np.inf: def aggregator(x): - y = x.resample(source_freq).apply(sample_func) + y = x.resample(sample_freq).apply(sample_func) if y.isna().sum() < max_invalid: return agg_func(y) else: return np.nan else: def aggregator(x): - return agg_func(x.resample(source_freq).apply(sample_func)) + return agg_func(x.resample(sample_freq).apply(sample_func)) return harmonize( data, field, flagger, - target_freq, + agg_freq, inter_method='bagg', reshape_method='bagg', inter_agg=aggregator, diff --git a/test/funcs/test_harm_funcs.py b/test/funcs/test_harm_funcs.py index 825f442651cade79ecdf64184e317bbe34458ef3..1170981b10589db94c89ef4937c019fccea22bc1 100644 --- a/test/funcs/test_harm_funcs.py +++ b/test/funcs/test_harm_funcs.py @@ -19,7 +19,7 @@ from saqc.funcs.harm_functions import ( interpolate2Grid, shift2Grid, aggregate2Grid, - aggregate + downsample ) @@ -335,7 +335,7 @@ def test_wrapper(data, flagger): field = data.columns[0] freq = '15min' flagger = flagger.initFlags(data) - aggregate(data, field, flagger, '15min', '30min', agg_func=np.sum, sample_func=np.mean) + downsample(data, field, flagger, '15min', '30min', agg_func=np.sum, sample_func=np.mean) linear2Grid(data, field, flagger, freq, flag_assignment_method='nearest_agg', flag_agg_func=max, drop_flags=None)