Apply 'name' argument in plugin.playlist.FilterCommand
[hooke.git] / hooke / plugin / flatfilt.py
index a1d5e8361257d25e5fb2500d165d6e8dfa1fd3ff..6637eb81f7ec37d8e3a81cf0b0e8786d97d6fc40 100644 (file)
@@ -38,7 +38,7 @@ from multiprocessing import Queue
 from numpy import diff
 from scipy.signal.signaltools import medfilt
 
-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
@@ -54,8 +54,15 @@ class FlatFiltPlugin (Plugin):
     def __init__(self):
         super(FlatFiltPlugin, self).__init__(name='flatfilt')
         self._arguments = [ # For Command initialization
-            Argument('median filter', type='int', default=7, help="""
+            Argument('median window', type='int', default=7, help="""
 Median window filter size (in points).
+""".strip()),
+            Argument('blind window', type='float', default=20e-9, help="""
+Meters after the contact point where we do not count peaks to avoid
+non-specific surface interaction.
+""".strip()),
+            Argument('min peaks', type='int', default=4, help="""
+Minimum number of peaks for curve acceptance.
 """.strip()),
             ] + copy.deepcopy(find_peaks_arguments)
         # Set flat-filter-specific defaults for the fit_peak_arguments.
@@ -110,13 +117,6 @@ class FlatPeaksCommand (Command):
             name='flat filter peaks',
             arguments=[
                 CurveArgument,
-            Argument('blind window', type='float', default=20e-9, help="""
-Meters after the contact point where we do not count peaks to avoid
-non-specific surface interaction.
-""".strip()),
-            Argument('median window', type='float', default=7, help="""
-Number of points to use in the initial rolling median filter.
-""".strip()),
                 ] + config_arguments,
             help=self.__doc__, plugin=plugin)
 
@@ -125,7 +125,7 @@ Number of points to use in the initial rolling median filter.
         start_index = 0
         while z_data[start_index] < params['blind window']:
             start_index += 1
-        median = medfilt(d_data[start_index:], params['median window']),
+        median = medfilt(d_data[start_index:], params['median window'])
         deriv = diff(median)
         peaks = find_peaks(deriv, **_kwargs(params, find_peaks_arguments,
                                             argument_input_keys=True))
@@ -163,7 +163,7 @@ Number of points to use in the initial rolling median filter.
             if value == None: # Use configured default value.
                 params[key] = self.plugin.config[key]
         # TODO: better option parser to do this automatically by Argument.type
-        for key in ['max cut', 'min deviations', 'min points', 'see double', 'stable']:
+        for key in ['blind window', 'median window', 'max cut', 'min deviations', 'min points', 'see double', 'stable']:
             params[key] = float(params[key])
         # TODO: convert 'see double' from nm to points
         return z_data,d_data,params
@@ -198,13 +198,16 @@ class FlatFilterCommand (FilterCommand):
     def filter(self, curve, hooke, inqueue, outqueue, params):
         inq = Queue()
         outq = Queue()
-        conv_command = [c for c in hooke.commands
+        filt_command = [c for c in hooke.commands
                         if c.name=='flat filter peaks'][0]
-        conv_command.run(hooke, inq, outq, **params)
+        filt_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):
             raise ret
-        return len(peaks) >= params['min peaks']
+        if params['min peaks'] == None: # Use configured default value.
+            params['min peaks'] = self.plugin.config['min peaks']
+        return len(peaks) >= int(params['min peaks'])