From c026c560b332ee4619b131f5a71701fef9e2425c Mon Sep 17 00:00:00 2001
From: Peter Luenenschloss <peter.luenenschloss@ufz.de>
Date: Mon, 5 Oct 2020 17:37:03 +0200
Subject: [PATCH] progress with implementing flagPlateaus

---
 saqc/funcs/proc_functions.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/saqc/funcs/proc_functions.py b/saqc/funcs/proc_functions.py
index 3b0924274..42754e384 100644
--- a/saqc/funcs/proc_functions.py
+++ b/saqc/funcs/proc_functions.py
@@ -5,13 +5,14 @@ import pandas as pd
 import numpy as np
 from saqc.core.register import register
 from saqc.lib.ts_operators import interpolateNANs, aggregate2Freq, shift2Freq, expModelFunc
-from saqc.lib.tools import toSequence, mergeDios, dropper, mutateIndex
+from saqc.lib.tools import toSequence, mergeDios, dropper, mutateIndex, detectDeviants
 import dios
 import functools
 from scipy.optimize import curve_fit
 from sklearn.linear_model import LinearRegression
 from sklearn.utils import resample
 
+
 ORIGINAL_SUFFIX = "_original"
 
 METHOD2ARGS = {
@@ -970,8 +971,13 @@ def proc_seefoExpDriftCorrecture(data, field, flagger, maint_data_field, cal_mea
 
 
 @register(masking='all')
-def proc_flagOffsets(data, field, flagger, stat, regime_cluster):
-    pass
+def proc_flagOffsets(data, field, flagger, cluster_field, norm_spread, metric=lambda x,y: np.abs(np.nanmean(x) - np.nanmean(y)),
+                     norm_frac=0.5):
+    clusterser = data[cluster_field]
+    cluster_num = clusterser.max() + 1
+    cluster_dios = dios.DictOfSeries({i : data[field][clusterser == i] for i in range(cluster_num)})
+    plateaus = detectDeviants(cluster_dios, metric, norm_spread, norm_frac)
+
 
 
 
-- 
GitLab