From abe4ff393c518511f67f55e2c44b89cefbd2ce09 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 14 Jun 2010 10:25:59 -0400 Subject: [PATCH] Skip PoorFit curves in flatfilt and convfilt. --- hooke/plugin/convfilt.py | 4 ++++ hooke/plugin/flatfilt.py | 6 +++++- hooke/plugin/vclamp.py | 9 +++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/hooke/plugin/convfilt.py b/hooke/plugin/convfilt.py index 4be6ea8..3d1e883 100644 --- a/hooke/plugin/convfilt.py +++ b/hooke/plugin/convfilt.py @@ -45,6 +45,7 @@ from ..plugin import Plugin, argument_to_setting from ..plugin.curve import CurveArgument from ..plugin.playlist import FilterCommand from ..plugin.vclamp import scale +from ..util.fit import PoorFit from ..util.peak import find_peaks, find_peaks_arguments, Peak, _kwargs @@ -211,6 +212,9 @@ class ConvolutionFilterCommand (FilterCommand): if c.name=='convolution peaks'][0] conv_command.run(hooke, inq, outq, **params) peaks = outq.get() + if isinstance(peaks, UncaughtException) \ + and isinstance(peaks.exception, PoorFit): + return False if not (isinstance(peaks, list) and (len(peaks) == 0 or isinstance(peaks[0], Peak))): raise Failure('Expected a list of Peaks, not %s' % peaks) diff --git a/hooke/plugin/flatfilt.py b/hooke/plugin/flatfilt.py index 1637ce3..716a4be 100644 --- a/hooke/plugin/flatfilt.py +++ b/hooke/plugin/flatfilt.py @@ -38,13 +38,14 @@ from multiprocessing import Queue from numpy import diff from scipy.signal.signaltools import medfilt -from ..command import Command, Argument, Success, Failure +from ..command import Command, Argument, Success, Failure, UncaughtException from ..config import Setting from ..experiment import VelocityClamp from ..plugin import Plugin, argument_to_setting from ..plugin.curve import CurveArgument from ..plugin.playlist import FilterCommand from ..plugin.vclamp import scale +from ..util.fit import PoorFit from ..util.peak import find_peaks, find_peaks_arguments, Peak, _kwargs @@ -204,6 +205,9 @@ class FlatFilterCommand (FilterCommand): if c.name=='flat filter peaks'][0] filt_command.run(hooke, inq, outq, **params) peaks = outq.get() + if isinstance(peaks, UncaughtException) \ + and isinstance(peaks.exception, PoorFit): + return False if not (isinstance(peaks, list) and (len(peaks) == 0 or isinstance(peaks[0], Peak))): raise Failure('Expected a list of Peaks, not %s' % peaks) diff --git a/hooke/plugin/vclamp.py b/hooke/plugin/vclamp.py index 0dfaeab..fca2cd3 100644 --- a/hooke/plugin/vclamp.py +++ b/hooke/plugin/vclamp.py @@ -46,8 +46,13 @@ def scale(hooke, curve): inqueue = None outqueue = NullQueue() for i,block in enumerate(curve.data): + numpy.savetxt(open('curve.dat', 'w'), block, delimiter='\t') params = {'curve':curve, 'block':i} - contact._run(hooke, inqueue, outqueue, params) + try: + contact._run(hooke, inqueue, outqueue, params) + except PoorFit, e: + raise PoorFit('Could not fit %s %s: %s' + % (curve.path, i, str(e))) force._run(hooke, inqueue, outqueue, params) return curve @@ -175,7 +180,7 @@ class SurfacePositionModel (ModelFitter): if abs(params[3]*10) > abs(params[1]) : raise PoorFit('Slope in non-contact region, or no slope in contact') if params[2] < self.info['min position']+0.02*self.info['position range']: - raise poorFit( + raise PoorFit( 'No kink (kink %g less than %g, need more space to left)' % (params[2], self.info['min position']+0.02*self.info['position range'])) -- 2.26.2