Broke bump unit conversion out into its own functions.
authorW. Trevor King <wking@drexel.edu>
Mon, 23 Feb 2009 16:28:42 +0000 (11:28 -0500)
committerW. Trevor King <wking@drexel.edu>
Fri, 27 Mar 2009 13:17:26 +0000 (09:17 -0400)
To provide conversion functions for other scripts, e.g. scale_unfold.py.

calibcant/bump_analyze.py

index 748287967cf8d38d29801e353dd217f162bef608..21e13cb308c6281f626fc2009d00baf9dbe036d1 100755 (executable)
@@ -54,15 +54,37 @@ from splittable_kwargs import splittableKwargsFunction, \
     make_splittable_kwargs_function
 
 
+@splittableKwargsFunction()
+def Vzp_bits2nm(data_bits, zpGain=config.zpGain,
+                zpSensitivity=config.zpSensitivity,
+                Vzp_out2V=config.Vzp_out2V):
+    scale_Vzp_bits2V = Vzp_out2V(1) - Vzp_out2V(0)
+    data_V = data_bits / scale_Vzp_bits2V
+    #             bits / (bits/V) = V
+    data_nm = data_V * zpGain * zpSensitivity
+    return data_nm
+
+@splittableKwargsFunction()
+def Vphoto_bits2V(data_bits, Vphoto_in2V=config.Vphoto_in2V):
+    scale_Vphoto_bits2V = Vphoto_in2V(1) - Vphoto_in2V(0)
+    Vphoto_V = data_bits / scale_Vphoto_bits2V
+    #               bits / (bits/V) = V
+    return Vphoto_V
+
+@splittableKwargsFunction((Vzp_bits2nm, 'data_bits'),
+                          (Vphoto_bits2V, 'data_bits'))
+def slope_bitspbit2Vpnm(slope_bitspbit, **kwargs):
+    zp_kwargs,photo_kwargs = slope_bitspbit2Vpnm._splitargs(slope_bitspbit2Vpnm, kwargs)
+    Vzp_bits = 1.0
+    Vphoto_bits = slope_bitspbit * Vzp_bits
+    return Vphoto_bits2V(Vphoto_bits, **photo_kwargs)/Vzp_bits2nm(Vzp_bits, **zp_kwargs)
+    
 #@splittableKwargsFunction((bump_fit, 'zpiezo_output_bits',
-#                           'deflection_input_bits'))
+#                           'deflection_input_bits'),
+#                          (slope_bitspbit2Vpnm, 'slope_bitspbit'))
 # Some of the child functions aren't yet defined, so postpone
 # make-splittable until later in the module.
-def bump_analyze(data, zpGain=config.zpGain,
-                 zpSensitivity=config.zpSensitivity,
-                 Vzp_out2V=config.Vzp_out2V,
-                 Vphoto_in2V=config.Vphoto_in2V,
-                 **kwargs) :
+def bump_analyze(data, **kwargs) :
     """
     Return the slope of the bump ;).
     Inputs:
@@ -79,16 +101,12 @@ def bump_analyze(data, zpGain=config.zpGain,
     and THEN converted, so we're assuming that both conversions are LINEAR.
     if they aren't, rewrite to convert before the regression.
     """
-    bump_fit_kwargs, = bump_analyze._splitargs(bump_analyze, kwargs)
+    bump_fit_kwargs,slope_bitspbit2Vpnm_kwargs = \
+        bump_analyze._splitargs(bump_analyze, kwargs)
     Vphoto2Vzp_out_bit = bump_fit(data['Z piezo output'],
                                   data['Deflection input'],
                                   **bump_fit_kwargs)
-    scale_Vzp_bits2V = Vzp_out2V(1) - Vzp_out2V(0)
-    scale_Vphoto_bits2V = Vphoto_in2V(1) - Vphoto_in2V(0)
-    Vphoto2Vzp_out = Vphoto2Vzp_out_bit *scale_Vphoto_bits2V / scale_Vzp_bits2V
-    #               1 / (Vzp/Vzp_out  *     Zp/Vzp       * Zcant/Zp )
-    Vzp_out2Zcant = 1.0/ (zpGain      * zpSensitivity) # * 1
-    return Vphoto2Vzp_out * Vzp_out2Zcant
+    return slope_bitspbit2Vpnm(Vphoto2Vzp_out_bit, **slope_bitspbit2Vpnm_kwargs)
 
 def limited_quadratic(x, params):
     """
@@ -223,7 +241,8 @@ def bump_plot(data, yguess=None, yfit=None, plotVerbose=False) :
 
 make_splittable_kwargs_function(bump_analyze,
                                 (bump_fit, 'zpiezo_output_bits',
-                                 'deflection_input_bits'))
+                                 'deflection_input_bits'),
+                                (slope_bitspbit2Vpnm, 'slope_bitspbit'))
 
 @splittableKwargsFunction((bump_analyze, 'data'))
 def bump_load_analyze_tweaked(tweak_file, **kwargs):