From 16a8170e49c4a7664727be8c1640e89d33dcee25 Mon Sep 17 00:00:00 2001 From: Darius Arnold Date: Mon, 13 Nov 2017 09:32:39 +0100 Subject: [PATCH] [add] an exception if unable to find minimum in AIC cf --- pylot/core/pick/picker.py | 9 ++++++++- pylot/core/pick/utils.py | 9 ++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pylot/core/pick/picker.py b/pylot/core/pick/picker.py index 31ea86f8..a64c9dbc 100644 --- a/pylot/core/pick/picker.py +++ b/pylot/core/pick/picker.py @@ -201,6 +201,9 @@ class AICPicker(AutoPicker): if diffcf[i - 1] >= diffcf[i]: self.Pick = self.Tcf[i] break + if self.Pick is None: + raise ValueError + def calcPick(self): """ @@ -221,8 +224,12 @@ class AICPicker(AutoPicker): self.prepareCF() except ValueError: return + try: + self.findMinimum() + except ValueError: + print('Could not determine pick on AIC CF') + return - self.findMinimum() # quality assessment using SNR and slope from CF if self.Pick is not None: diff --git a/pylot/core/pick/utils.py b/pylot/core/pick/utils.py index c8c68ff7..88dbb667 100644 --- a/pylot/core/pick/utils.py +++ b/pylot/core/pick/utils.py @@ -1281,13 +1281,12 @@ def smooth_cf(cf, t_smooth, delta): if len(cf) < ismooth: raise ValueError - - for i, val in enumerate(cf): - if i <= ismooth: - cf_smooth[i] = np.mean(cf[0:i+1]) - elif i > ismooth: + for i in range(1, len(cf)): + if i > ismooth: ii1 = i - ismooth cf_smooth[i] = cf_smooth[i - 1] + (cf[i] - cf[ii1]) / ismooth + else: + cf_smooth[i] = np.mean(cf[1: i]) offset = abs(min(cf) - min(cf_smooth)) cf_smooth -= offset # remove offset from smoothed function return cf_smooth