Success import and better peaks validation in flatfilt and convfilt.
[hooke.git] / hooke / plugin / convfilt.py
index b4af4f63003c482708c512872d00804998f7a272..b85348a6feae57a679a2e41de7980a45b6f2e290 100644 (file)
@@ -38,14 +38,14 @@ from multiprocessing import Queue
 
 import numpy
 
-from ..command import Command, Argument, Failure
+from ..command import Command, Argument, Success, Failure
 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.peak import find_peaks, find_peaks_arguments, Peak
+from ..util.peak import find_peaks, find_peaks_arguments, Peak, _kwargs
 
 
 class ConvFiltPlugin (Plugin):
@@ -72,7 +72,7 @@ Minimum number of peaks for curve acceptance.
         for key,value in [('cut side', 'positive'),
                           ('stable', 0.005),
                           ('max cut', 0.2),
-                          ('min deviation', 5.0),
+                          ('min deviations', 5.0),
                           ('min points', 1),
                           ('see double', 10e-9),
                           ]:
@@ -136,8 +136,8 @@ class ConvolutionPeaksCommand (Command):
             start_index += 1
         conv = numpy.convolve(d_data[start_index:], params['convolution'],
                               mode='valid')
-        kwargs = dict([(a.name, params[a.name]) for a in find_peaks_arguments])
-        peaks = find_peaks(conv, **kwargs)
+        peaks = find_peaks(conv, **_kwargs(params, find_peaks_arguments,
+                                            argument_input_keys=True))
         for peak in peaks:
             peak.name = 'convolution of %s with %s' \
                 % (params['deflection column name'], params['convolution'])
@@ -210,7 +210,8 @@ class ConvolutionFilterCommand (FilterCommand):
                         if c.name=='convolution peaks'][0]
         conv_command.run(hooke, inq, outq, **params)
         peaks = outq.get()
-        if not isinstance(peaks[0], Peak):
+        if not (isinstance(peaks, list) and (len(peaks) == 0
+                                             or isinstance(peaks[0], Peak))):
             raise Failure('Expected a list of Peaks, not %s' % peaks)
         ret = outq.get()
         if not isinstance(ret, Success):