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
**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,
......
......@@ -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)
......
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