Add 'ignore index' argument to SurfaceContactCommand
[hooke.git] / hooke / plugin / vclamp.py
index 78a46147f96277be9fab2a45153ee28512657320..48d55b3e6a6f1cbaa2135a9566884aa118a1d5f3 100644 (file)
@@ -139,7 +139,7 @@ class SurfacePositionModel (ModelFitter):
             self.info = {}
         for key,value in [
             ('force zero non-contact slope', False),
-            ('ignore non-contact before index', 6158),
+            ('ignore non-contact before index', -1),
             ('min position', 0),  # Store postions etc. to avoid recalculating.
             ('max position', len(data)),
             ('max deflection', data.max()),
@@ -179,22 +179,6 @@ class SurfacePositionModel (ModelFitter):
             params = params[:-1]
         return params
 
-    def guess_scale(self, params, outqueue=None):
-        """Guess the parameter scales.
-
-        Notes
-        -----
-        We the scale as one tenth for each parameter.
-        """
-        offset_scale = 0.1
-        left_slope_scale = 0.1
-        kink_scale = 0.1
-        right_slope_scale = 0.1
-        scale = [offset_scale, left_slope_scale, kink_scale, right_slope_scale]
-        if self.info['force zero non-contact slope'] == True:
-            scale = scale[:-1]
-        return scale
-
     def fit(self, *args, **kwargs):
         """Fit the model to the data.
 
@@ -273,6 +257,11 @@ class SurfaceContactCommand (Command):
 Data block for which the force should be calculated.  For an
 approach/retract force curve, `0` selects the approaching curve and `1`
 selects the retracting curve.
+""".strip()),
+                Argument(name='ignore index', type='int', default=None,
+                         help="""
+Ignore the residual from the non-contact region before the indexed
+point (for the `wtk` algorithm).
 """.strip()),
                 Argument(name='input distance column', type='string',
                          default='z piezo (m)',
@@ -333,7 +322,7 @@ Name (without units) for storing fit parameters in the `.info` dictionary.
         def_data = data[:,data.info['columns'].index(
                 params['input deflection column'])]
         i,def_offset,ps = self.find_contact_point(
-            params['curve'], dist_data, def_data, outqueue)
+            params, dist_data, def_data, outqueue)
         dist_offset = dist_data[i]
         new.info[join_data_label(params['distance info name'], dist_units
                                  )] = dist_offset
@@ -344,7 +333,7 @@ Name (without units) for storing fit parameters in the `.info` dictionary.
         new[:,-1] = def_data - def_offset
         params['curve'].data[params['block']] = new
 
-    def find_contact_point(self, curve, z_data, d_data, outqueue=None):
+    def find_contact_point(self, params, z_data, d_data, outqueue=None):
         """Railyard for the `find_contact_point_*` family.
 
         Uses the `surface contact point algorithm` configuration
@@ -352,9 +341,9 @@ Name (without units) for storing fit parameters in the `.info` dictionary.
         """
         fn = getattr(self, 'find_contact_point_%s'
                      % self.plugin.config['surface contact point algorithm'])
-        return fn(curve, z_data, d_data, outqueue)
+        return fn(params, z_data, d_data, outqueue)
 
-    def find_contact_point_fmms(self, curve, z_data, d_data, outqueue=None):
+    def find_contact_point_fmms(self, params, z_data, d_data, outqueue=None):
         """Algorithm by Francesco Musiani and Massimo Sandal.
 
         Notes
@@ -374,7 +363,7 @@ Name (without units) for storing fit parameters in the `.info` dictionary.
         curve, until you find a point with greater than baseline
         deflection.  That point is the contact point.
         """
-        if curve.info['filetype'] == 'picoforce':
+        if params['curve'].info['filetype'] == 'picoforce':
             # Take care of the picoforce trigger bug (TODO: example
             # data file demonstrating the bug).  We exclude portions
             # of the curve that have too much standard deviation.
@@ -415,7 +404,7 @@ Name (without units) for storing fit parameters in the `.info` dictionary.
             i += 1
         return (i, d_baseline, {})
 
-    def find_contact_point_ms(self, curve, z_data, d_data, outqueue=None):
+    def find_contact_point_ms(self, params, z_data, d_data, outqueue=None):
         """Algorithm by Massimo Sandal.
 
         Notes
@@ -460,7 +449,7 @@ Name (without units) for storing fit parameters in the `.info` dictionary.
         else:
             return dummy.index
 
-    def find_contact_point_wtk(self, curve, z_data, d_data, outqueue=None):
+    def find_contact_point_wtk(self, params, z_data, d_data, outqueue=None):
         """Algorithm by W. Trevor King.
 
         Notes
@@ -473,6 +462,8 @@ Name (without units) for storing fit parameters in the `.info` dictionary.
         s = SurfacePositionModel(d_data, info={
                 'force zero non-contact slope':True},
                                  rescale=True)
+        if params['ignore index'] != None:
+            s.info['ignore non-contact before index'] = params['ignore index']
         offset,contact_slope,surface_index,non_contact_slope = s.fit(
             outqueue=outqueue)
         info = {