From d691b7eb9caa9b0f2bdc4bf46372075dcb438dbc Mon Sep 17 00:00:00 2001 From: Mauro Rovezzi Date: Sat, 14 Apr 2018 02:04:11 +0200 Subject: [PATCH] wip --- sloth/math/deglitch.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sloth/math/deglitch.py b/sloth/math/deglitch.py index b50d217..3966f5b 100644 --- a/sloth/math/deglitch.py +++ b/sloth/math/deglitch.py @@ -1,10 +1,18 @@ -"""Deglitch utility""" +"""Deglitch utilities""" import numpy as np -import pandas as pd -def remove_spikes(x_data, y_spiky_data, threshold=3): - # convert data to pandas DataFrame +HAS_PANDAS = False +try: + import pandas as pd + HAS_PANDAS = True +except: + pass + +def remove_spikes(x_data, y_spiky_data, threshold=0): + """remove spikes using pandas""" + if (not HAS_PANDAS): + return np.zeros_like(y_spiky_data) df = pd.DataFrame(y_spiky_data); df['filtered'] = pd.rolling_median(df, window=3, center=True).fillna(method='bfill').fillna(method='ffill') diff = df['filtered'].as_matrix()-y_spiky_data