Clean up argument handling in hooke.plugin.convfilt/flatfilt.
authorW. Trevor King <wking@drexel.edu>
Wed, 19 May 2010 07:57:50 +0000 (03:57 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 19 May 2010 07:57:50 +0000 (03:57 -0400)
* Take advantage of hooke.util.peak._kwargs to split out appropriate
  kwargs for find_peaks.
* Add missing arguments 'blind window' and 'median window' to
  FlatFiltPlugin.
* Fix leftover convfilt code in FlatFiltPlugin._run peak naming.
* Add type casting HACK to FlatFiltPlugin._setup.

hooke/plugin/convfilt.py
hooke/plugin/flatfilt.py

index b4af4f63003c482708c512872d00804998f7a272..37794ad952e4b10d38b74c2b72a4f5d1c2c7a1a8 100644 (file)
@@ -45,7 +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.peak import find_peaks, find_peaks_arguments, Peak
+from ..util.peak import find_peaks, find_peaks_arguments, Peak, _kwargs
 
 
 class ConvFiltPlugin (Plugin):
@@ -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'])
index 1bbdbecae5fbf8381c775c2050733da47205a842..25abf758d8e4008efd0e009f0d34ea1c61ade410 100644 (file)
@@ -45,7 +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.peak import find_peaks, find_peaks_arguments, Peak
+from ..util.peak import find_peaks, find_peaks_arguments, Peak, _kwargs
 
 
 class FlatFiltPlugin (Plugin):
@@ -108,21 +108,29 @@ class FlatPeaksCommand (Command):
         # function, just detecting peaks.
         super(FlatPeaksCommand, self).__init__(
             name='flat filter peaks',
-            arguments=[CurveArgument] + config_arguments,
+            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)
 
     def _run(self, hooke, inqueue, outqueue, params):
         z_data,d_data,params = self._setup(params)
         start_index = 0
-        while z_data[start_index] < params['bind window']:
+        while z_data[start_index] < params['blind window']:
             start_index += 1
         median = medfilt(d_data[start_index:], params['median window']),
         deriv = diff(median)
-        kwargs = dict([(a.name, params[a.name]) for a in find_peaks_arguments])
-        peaks = find_peaks(deriv, **kwargs)
+        peaks = find_peaks(deriv, **_kwargs(params, find_peaks_arguments,
+                                            argument_input_keys=True))
         for peak in peaks:
-            peak.name = 'flat filter of %s with %s' \
-                % (params['deflection column name'], params['convolution'])
+            peak.name = 'flat filter of %s' % (params['deflection column name'])
             peak.index += start_index
         outqueue.put(peaks)
 
@@ -154,6 +162,10 @@ class FlatPeaksCommand (Command):
         for key,value in params.items():
             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 deviation', 'min points', 'see double', 'stable']:
+            params[key] = float(params[key])
+        # TODO: convert 'see double' from nm to points
         return z_data,d_data,params
 
 class FlatFilterCommand (FilterCommand):