Skip to content
Snippets Groups Projects
Commit d8c9d68a authored by Peter Lünenschloß's avatar Peter Lünenschloß
Browse files

refactoring/renaming in harm_funcs

parent 133abce4
No related branches found
No related tags found
No related merge requests found
...@@ -844,8 +844,9 @@ def interpolate2Grid(data, field, flagger, freq, interpolation_method, interpola ...@@ -844,8 +844,9 @@ def interpolate2Grid(data, field, flagger, freq, interpolation_method, interpola
**kwargs) **kwargs)
def aggregate(data, field, flagger, source_freq, target_freq, agg_func=np.mean, sample_func=np.mean, @register('downsample')
invalid_flags=None, max_invalid=np.inf, **kwargs): 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 # define the "fastest possible" aggregator
if sample_func is None: if sample_func is None:
...@@ -868,7 +869,7 @@ def aggregate(data, field, flagger, source_freq, target_freq, agg_func=np.mean, ...@@ -868,7 +869,7 @@ def aggregate(data, field, flagger, source_freq, target_freq, agg_func=np.mean,
sample_func_name = sample_func.__name__ sample_func_name = sample_func.__name__
if max_invalid < np.inf: if max_invalid < np.inf:
def aggregator(x): 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: if y.isna().sum() < max_invalid:
return agg_func(y) return agg_func(y)
else: else:
...@@ -876,25 +877,25 @@ def aggregate(data, field, flagger, source_freq, target_freq, agg_func=np.mean, ...@@ -876,25 +877,25 @@ def aggregate(data, field, flagger, source_freq, target_freq, agg_func=np.mean,
else: else:
def aggregator(x): 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: else:
if max_invalid < np.inf: if max_invalid < np.inf:
def aggregator(x): 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: if y.isna().sum() < max_invalid:
return agg_func(y) return agg_func(y)
else: else:
return np.nan return np.nan
else: else:
def aggregator(x): 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( return harmonize(
data, data,
field, field,
flagger, flagger,
target_freq, agg_freq,
inter_method='bagg', inter_method='bagg',
reshape_method='bagg', reshape_method='bagg',
inter_agg=aggregator, inter_agg=aggregator,
......
...@@ -19,7 +19,7 @@ from saqc.funcs.harm_functions import ( ...@@ -19,7 +19,7 @@ from saqc.funcs.harm_functions import (
interpolate2Grid, interpolate2Grid,
shift2Grid, shift2Grid,
aggregate2Grid, aggregate2Grid,
aggregate downsample
) )
...@@ -335,7 +335,7 @@ def test_wrapper(data, flagger): ...@@ -335,7 +335,7 @@ def test_wrapper(data, flagger):
field = data.columns[0] field = data.columns[0]
freq = '15min' freq = '15min'
flagger = flagger.initFlags(data) 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, linear2Grid(data, field, flagger, freq, flag_assignment_method='nearest_agg', flag_agg_func=max,
drop_flags=None) drop_flags=None)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment