Oops, use numpy arrays instead of lists for the last commit.
[calibcant.git] / calibcant / analyze.py
index dcfc7471304426f2b58df0b23e182f9860859e9f..1033dcc3b692865f9b87f56d7018fad882dc7ad5 100644 (file)
@@ -1,22 +1,20 @@
 # calibcant - tools for thermally calibrating AFM cantilevers
 #
-# Copyright (C) 2008-2011 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2008-2012 W. Trevor King <wking@drexel.edu>
 #
 # This file is part of calibcant.
 #
-# calibcant 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.
+# calibcant is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
 #
-# calibcant 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.
+# calibcant 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 General Public License for more details.
 #
-# You should have received a copy of the GNU Lesser General Public
-# License along with calibcant.  If not, see
-# <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU General Public License along with
+# calibcant.  If not, see <http://www.gnu.org/licenses/>.
 
 """Calculate `k` from arrays of bumps, temperatures, and vibrations.
 
@@ -337,7 +335,8 @@ def calib_plot(bumps, temperatures, vibrations):
     vib_axes.plot(vibrations, 'b.-')
     vib_axes.set_ylabel('thermal deflection variance (V^2)')
 
-    figure.show()
+    if hasattr(figure, 'show'):
+        figure.show()
 
 
 def calib_load_all(filename, group='/'):
@@ -396,15 +395,23 @@ def calib_analyze_all(filename, group='/', maximum_relative_error=1e-5,
     assert group.endswith('/'), group
     bumps,temperatures,vibrations,calibration_config,k,k_s = calib_load(
         filename, group+'calibration/')
+    if bumps is None:
+        bumps = _numpy.zeros(
+            (calibration_config['num-bumps'],), dtype=float)
+    if temperatures is None:
+        temperatures = _numpy.zeros(
+            (calibration_config['num-temperatures'],), dtype=float)
+    if vibrations is None:
+        vibrations = _numpy.zeros(
+            (calibration_config['num-vibrations'],), dtype=float)
     changed_bump = changed_temperature = changed_vibration = False
     for i in range(calibration_config['num-bumps']):
         bump_group = '%sbump/%d/' % (group, i)
-        (raw_bump,bump_config,z_channel_config,z_axis_config,
+        (raw_bump,bump_config,z_axis_config,
          deflection_channel_config,processed_bump) = _bump_load(
             filename=filename, group=bump_group)
         sensitivity = _bump_analyze(
             data=raw_bump, bump_config=bump_config,
-            z_channel_config=z_channel_config,
             z_axis_config=z_axis_config,
             deflection_channel_config=deflection_channel_config)
         bumps[i] = sensitivity
@@ -491,7 +498,6 @@ def calib_plot_all(bumps, bump_details, temperatures, temperature_details,
     for i,bump in enumerate(bump_details):
         sensitivity = _bump_analyze(
             data=bump['raw_bump'], bump_config=bump['bump_config'],
-            z_channel_config=bump['z_channel_config'],
             z_axis_config=bump['z_axis_config'],
             deflection_channel_config=bump['deflection_channel_config'],
             plot=True)