vibration_analyze.py: Don't use the peak power for D_guess
[calibcant.git] / calibcant / bump_analyze.py
index d5256fc84bd1ea660c05c81b6bfc73d188d35de9..d5e0f9cc8bbe6ca7160d4eddfd7f05f3b75a3438 100644 (file)
@@ -234,6 +234,8 @@ def limited_linear_param_guess(x, y):
     x_high = float(x[i_high])
     if x_high == x_contact:  # things must be pretty flat
         x_contact = (x_contact + x[0]) / 2
+    if x_high == x_contact:
+        x_high = x[1]
     slope = (y_high - y_contact) / (x_high - x_contact)
     return (x_contact, y_contact, slope)
 
@@ -320,7 +322,7 @@ def fit(z, deflection, high_voltage_rail,
     except ValueError:
         zd = _numpy.ndarray(list(z.shape) + [2], dtype=z.dtype)
         zd[:,0] = z
-        zd[:,1] = d
+        zd[:,1] = deflection
         _numpy.savetxt('/tmp/z-deflection.dat', zd, delimiter='\t')
         raise
     _LOG.debug('fitted params: %s' % p)
@@ -387,6 +389,7 @@ def plot(data, yguess=None, yfit=None):
     if yfit != None:
         axes.plot(data['z'], yfit, 'r-', label='fit')
 
+    axes.autoscale(tight=True)
     axes.set_title('bump surface %s' % timestamp)
     #axes.legend(loc='upper left')
     axes.set_xlabel('Z piezo (meters)')
@@ -395,9 +398,11 @@ def plot(data, yguess=None, yfit=None):
         # second subplot for residual
         residual_axes.plot(data['z'], data['deflection'] - yfit,
                            'r-', label='residual')
+        residual_axes.autoscale(tight=True)
         #residual_axes.legend(loc='upper right')
         residual_axes.set_xlabel('Z piezo (meters)')
         residual_axes.set_ylabel('Photodiode (Volts)')
     if hasattr(figure, 'show'):
         figure.show()
+    return figure
 _plot = plot  # alternative name for use inside fit()