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

minor bugfix/ handy harm wrappers introduced + tested

parent 50e2ca0a
No related branches found
No related tags found
No related merge requests found
......@@ -608,7 +608,6 @@ def _reshapeFlags(
# NOTE: breaks for non categorical flaggers
.apply(lambda x: agg_method(x) if not x.empty else missing_flag)
.astype(flagger.dtype)
.to_frame(name=field)
)
if method == "nearest_agg":
......@@ -776,3 +775,60 @@ def _toMerged(
return flagMissing(
data, fieldname, flagger.initFlags(flags=flags), nodata=np.nan
)
@register('harmonize_shift2Grid')
def shift2Grid(data, field, flagger, freq, shift_method='nearest_shift', drop_flags=None, **kwargs):
return harmonize(
data,
field,
flagger,
freq,
inter_method=shift_method,
reshape_method=shift_method,
drop_flags=drop_flags,
**kwargs)
@register('harmonize_aggregate2Grid')
def aggregate2Grid(data, field, flagger, freq, agg_func, agg_method='nearest_agg', flag_agg_func=max, drop_flags=None, **kwargs):
return harmonize(
data,
field,
flagger,
freq,
inter_method=agg_method,
reshape_method=agg_method,
inter_agg=agg_func,
reshape_agg=flag_agg_func,
drop_flags=drop_flags,
**kwargs)
@register('harmonize_linear2Grid')
def linear2Grid(data, field, flagger, freq, flag_assignment_method='nearest_agg', flag_agg_func=max, drop_flags=None, **kwargs):
return harmonize(
data,
field,
flagger,
freq,
inter_method='time',
reshape_method=flag_assignment_method,
reshape_agg=flag_agg_func,
drop_flags=drop_flags,
**kwargs)
@register('harmonize_interpolate2Grid')
def interpolate2Grid(data, field, flagger, freq, interpolation_method, interpolation_order=1, flag_assignment_method='nearest_agg', flag_agg_func=max, drop_flags=None, **kwargs):
return harmonize(
data,
field,
flagger,
freq,
inter_method=interpolation_method,
inter_order=interpolation_order,
reshape_method=flag_assignment_method,
reshape_agg=flag_agg_func,
drop_flags=drop_flags,
**kwargs)
\ No newline at end of file
......@@ -15,6 +15,10 @@ from saqc.funcs.harm_functions import (
_interpolateGrid,
_insertGrid,
_outsortCrap,
linear2Grid,
interpolate2Grid,
shift2Grid,
aggregate2Grid
)
......@@ -287,7 +291,7 @@ def test_multivariatHarmonization(multi_data, flagger, shift_comment):
def test_gridInterpolation(data, method):
freq = "15min"
data = (data * np.sin(data)).append(data.shift(1, "2h")).shift(1, "3s")
# we are just testing if the interolation gets passed to the series without causing an error:
# we are just testing if the interpolation gets passed to the series without causing an error:
_interpolateGrid(
data, freq, method, order=1, agg_method=sum, downcast_interpolation=True
)
......@@ -322,3 +326,16 @@ def test_outsortCrap(data, flagger):
data, field, flagger, drop_flags=[flagger.BAD, flagger.GOOD], return_drops=True,
)
assert f_drop.index.sort_values().equals(drop_index.sort_values())
@pytest.mark.parametrize("flagger", TESTFLAGGER)
def test_wrapper(data, flagger):
# we are only testing, whether the wrappers do pass processing:
field = data.columns[0]
freq = '15min'
flagger = flagger.initFlags(data)
linear2Grid(data, field, flagger, freq, flag_assignment_method='nearest_agg', flag_agg_func=max,
drop_flags=None)
aggregate2Grid(data, field, flagger, freq, agg_func=sum, agg_method='nearest_agg',
flag_agg_func=max, drop_flags=None)
shift2Grid(data, field, flagger, freq, shift_method='nearest_shift', 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