From cd823d4df7408c674b4ed704d1c1f52b3c455d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20L=C3=BCnenschlo=C3=9F?= <peter.luenenschloss@ufz.de> Date: Fri, 2 Oct 2020 11:24:30 +0200 Subject: [PATCH] Flag basic fix --- saqc/funcs/spikes_detection.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/saqc/funcs/spikes_detection.py b/saqc/funcs/spikes_detection.py index 93a23c6d0..ad55bebfa 100644 --- a/saqc/funcs/spikes_detection.py +++ b/saqc/funcs/spikes_detection.py @@ -959,6 +959,17 @@ def spikes_flagBasic(data, field, flagger, thresh, tolerance, window, numba_kick engine = 'numba' result = customRolling(to_roll, window, spikeTester, roll_mask, closed='both', engine=engine) + # correct the result: only those values define plateaus, that do not have + # values at theire left starting point, that belong to other plateaus themselfs: + def correctResult(result): + for k in range(len(result)): + if result[k] > 0: + check_val = result[int(k-result[k])] + if check_val > 0: + result[k] = np.nan + return result + + result = correctResult(result) group_col = np.nancumsum(result) group_frame = pd.DataFrame({'group_col': group_col[:-1], 'diff_col': np.diff(group_col).astype(int)}, @@ -967,7 +978,9 @@ def spikes_flagBasic(data, field, flagger, thresh, tolerance, window, numba_kick def gFunc(x): r = np.zeros(shape=x.shape[0], dtype=np.bool) - r[-x[-1]:] = True + i_val = -x[-1] + if i_val < 0: + r[i_val:] = True return r to_flag = groups['diff_col'].transform(gFunc) -- GitLab