From 46f97dd9372d29db016726951b276d86938fd2f5 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 19 May 2010 03:57:50 -0400 Subject: [PATCH] Clean up argument handling in hooke.plugin.convfilt/flatfilt. * 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 | 6 +++--- hooke/plugin/flatfilt.py | 26 +++++++++++++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/hooke/plugin/convfilt.py b/hooke/plugin/convfilt.py index b4af4f6..37794ad 100644 --- a/hooke/plugin/convfilt.py +++ b/hooke/plugin/convfilt.py @@ -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']) diff --git a/hooke/plugin/flatfilt.py b/hooke/plugin/flatfilt.py index 1bbdbec..25abf75 100644 --- a/hooke/plugin/flatfilt.py +++ b/hooke/plugin/flatfilt.py @@ -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): -- 2.26.2