Upgraded hooke.plugin.polymer_fit commands to ColumnAddingArgument subclasses.
[hooke.git] / hooke / plugin / flatfilt.py
index 7c0b5346f9b659d7ec145df7b86b95b716b5539a..952e6fc2e790011c0fb237fdb4c79787d5fbc990 100644 (file)
@@ -21,7 +21,7 @@
 # License along with Hooke.  If not, see
 # <http://www.gnu.org/licenses/>.
 
-"""The ``flatfilt`` module provides :class:`~FlatFiltPlugin` and
+"""The ``flatfilt`` module provides :class:`FlatFiltPlugin` and
 several associated :class:`~hooke.command.Command`\s for removing flat
 (featureless) :mod:`~hooke.curve.Curve`\s from
 :class:`~hooke.playlist.Playlist`\s.
@@ -42,13 +42,13 @@ 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):
@@ -84,7 +84,10 @@ Minimum number of peaks for curve acceptance.
             self._settings.append(argument_to_setting(
                     self.setting_section, argument))
             argument.default = None # if argument isn't given, use the config.
-        self._commands = [FlatPeaksCommand(self), FlatFilterCommand(self)]
+        self._commands = [FlatPeaksCommand(self)]
+        # append FlatFilterCommand so it can steal arguments from
+        # FlatPeaksCommand.
+        self._commands.append(FlatFilterCommand(self))
 
     def dependencies(self):
         return ['vclamp']
@@ -128,19 +131,19 @@ 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):
+        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,
@@ -171,14 +174,13 @@ dictionary.
             raise Failure('%s operates on VelocityClamp experiments, not %s'
                           % (self.name, curve.info['experiment']))
         for key,value in params.items():
-            if value == None: # Use configured default value.
+            if value == None and key in self.plugin.config:
+                # Use configured default value.
                 params[key] = self.plugin.config[key]
         # TODO: convert 'see double' from nm to points
         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):
@@ -209,9 +211,15 @@ class FlatFilterCommand (FilterCommand):
     FlatPeaksCommand : Underlying flat-based peak detection.
     """
     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]
+        plugin_arguments = [a for a in plugin._arguments
+                            if a.name not in flat_peaks_arg_names]
+        arguments = flat_peaks.arguments + plugin_arguments
         super(FlatFilterCommand, self).__init__(
             plugin, name='flat filter playlist')
-        self.arguments.extend(plugin._arguments)  # TODO: curve & block arguments
+        self.arguments.extend(arguments)
 
     def filter(self, curve, hooke, inqueue, outqueue, params):
         params['curve'] = curve
@@ -226,7 +234,8 @@ class FlatFilterCommand (FilterCommand):
             return False
         if not (isinstance(peaks, list) and (len(peaks) == 0
                                              or isinstance(peaks[0], Peak))):
-            raise Failure('Expected a list of Peaks, not %s' % peaks)
+            raise Failure('Expected a list of Peaks, not %s: %s'
+                          % (type(peaks), peaks))
         ret = outq.get()
         if not isinstance(ret, Success):
             raise ret