Ran update-copyright.py
[hooke.git] / hooke / plugin / flatfilt.py
index 429a2dcc362e8b633a7e18cbd5b9ef02c8638e79..87a1f65d0356ae385e54b9177e60e27f0cece0fa 100644 (file)
@@ -1,25 +1,21 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2008-2010 Alberto Gomez-Casado
-#                         Fabrizio Benedetti
-#                         Massimo Sandal <devicerandom@gmail.com>
-#                         W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2010-2012 W. Trevor King <wking@tremily.us>
 #
 # This file is part of Hooke.
 #
-# Hooke is free software: you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
+# Hooke is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
 #
-# Hooke is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
-# Public License for more details.
+# Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
 #
-# You should have received a copy of the GNU Lesser General Public
-# License along with Hooke.  If not, see
-# <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Lesser General Public License
+# along with Hooke.  If not, see <http://www.gnu.org/licenses/>.
 
 """The ``flatfilt`` module provides :class:`FlatFiltPlugin` and
 several associated :class:`~hooke.command.Command`\s for removing flat
@@ -28,8 +24,7 @@ several associated :class:`~hooke.command.Command`\s for removing flat
 
 See Also
 --------
-:mod:`~hooke.plugin.convfilt` for a convolution-based filter for
-:class:`~hooke.experiment.VelocityClamp` experiments.
+:mod:`~hooke.plugin.convfilt` for a convolution-based filter.
 """
 
 import copy
@@ -41,14 +36,13 @@ from scipy.signal.signaltools import medfilt
 from ..command import Argument, Success, Failure, UncaughtException
 from ..config import Setting
 from ..curve import Data
-from ..experiment import VelocityClamp
-from ..plugin import Plugin, argument_to_setting
-from ..plugin.curve import ColumnAddingCommand
-from ..plugin.playlist import FilterCommand
 from ..util.fit import PoorFit
 from ..util.peak import (find_peaks, peaks_to_mask,
                          find_peaks_arguments, Peak, _kwargs)
 from ..util.si import join_data_label, split_data_label
+from . import Plugin, argument_to_setting
+from .curve import ColumnAddingCommand
+from .playlist import FilterCommand
 
 
 class FlatFiltPlugin (Plugin):
@@ -131,20 +125,20 @@ Name of the column to use as the deflection input.
             new_columns=[
                 ('output peak column', 'flat filter peaks', """
 Name of the column (without units) to use as the peak output.
-""".split()),
+""".strip()),
                 ],
             arguments=[
                 Argument(name='peak info name', type='string',
                          default='flat filter peaks',
                          help="""
-Name (without units) for storing the list of peaks in the `.info`
-dictionary.
+Name for storing the list of peaks in the `.info` dictionary.
 """.strip()),
                 ] + plugin_arguments,
             help=self.__doc__, plugin=plugin)
 
     def _run(self, hooke, inqueue, outqueue, params):
-        params = self.__setup_params(hooke=hooke, params=params)
+        self._add_to_command_stack(params)
+        params = self._setup_params(hooke=hooke, params=params)
         block = self._block(hooke=hooke, params=params)
         dist_data = self._get_column(hooke=hooke, params=params,
                                      column_name='distance column')
@@ -165,14 +159,11 @@ dictionary.
                          values=peaks_to_mask(def_data, peaks) * def_data)
         outqueue.put(peaks)
 
-    def __setup_params(self, hooke, params):
+    def _setup_params(self, hooke, params):
         """Setup `params` from config and return the z piezo and
         deflection arrays.
         """
         curve = self._curve(hooke=hooke, params=params)
-        if curve.info['experiment'] != VelocityClamp:
-            raise Failure('%s operates on VelocityClamp experiments, not %s'
-                          % (self.name, curve.info['experiment']))
         for key,value in params.items():
             if value == None and key in self.plugin.config:
                 # Use configured default value.
@@ -181,8 +172,6 @@ dictionary.
         name,def_unit = split_data_label(params['deflection column'])
         params['output peak column'] = join_data_label(
             params['output peak column'], def_unit)
-        params['peak info name'] = join_data_label(
-            params['peak info name'], def_unit)
         return params
 
     def _peak_name(self, params, index):
@@ -215,10 +204,12 @@ class FlatFilterCommand (FilterCommand):
     def __init__(self, plugin):
         flat_peaks = [c for c in plugin._commands
                       if c.name == 'flat filter peaks'][0]
-        flat_peaks_arg_names = [a.name for a in flat_peaks.arguments]
+        flat_peaks_arguments = [a for a in flat_peaks.arguments
+                                if a.name not in ['help', 'stack']]
+        flat_peaks_arg_names = [a.name for a in flat_peaks_arguments]
         plugin_arguments = [a for a in plugin._arguments
                             if a.name not in flat_peaks_arg_names]
-        arguments = flat_peaks.arguments + plugin_arguments
+        arguments = flat_peaks_arguments + plugin_arguments
         super(FlatFilterCommand, self).__init__(
             plugin, name='flat filter playlist')
         self.arguments.extend(arguments)
@@ -227,8 +218,7 @@ class FlatFilterCommand (FilterCommand):
         params['curve'] = curve
         inq = Queue()
         outq = Queue()
-        filt_command = [c for c in hooke.commands
-                        if c.name=='flat filter peaks'][0]
+        filt_command = hooke.command_by_name['flat filter peaks']
         filt_command.run(hooke, inq, outq, **params)
         peaks = outq.get()
         if isinstance(peaks, UncaughtException) \