Convert calibcant to the new, nestable h5config.
authorW. Trevor King <wking@drexel.edu>
Thu, 15 Sep 2011 12:17:14 +0000 (08:17 -0400)
committerW. Trevor King <wking@drexel.edu>
Thu, 15 Sep 2011 12:17:14 +0000 (08:17 -0400)
calibcant/calibrate.py

index a3f70580b22f11c2144e0ad02a017756eb8e35c0..426abbf5b686f07143a80b54d2a153eea38cba51 100644 (file)
@@ -116,16 +116,12 @@ def move_far_from_surface(stepper, distance):
     _LOG.info('step back %d steps (~%g m)' % (steps, distance))
     stepper.step_relative(-steps)
 
-def calib_acquire(afm, calibration_config, bump_config, temperature_config,
-                  vibration_config, filename=None, group='/'):
+def calib_acquire(afm, calibration_config, filename=None, group='/'):
     """Acquire data for calibrating a cantilever in one function.
 
     Inputs:
       afm                 a pyafm.AFM instance
       calibration_config  a .config._CalibrationConfig instance
-      bump_config         a .config._BumpConfig instance
-      temperature_config            a .config._TConfig instance
-      vibration_config    a .config._VibrationConfig instance
 
     Outputs (all are arrays of recorded data):
       bumps measured (V_photodiode / nm_tip) proportionality constant
@@ -141,7 +137,7 @@ def calib_acquire(afm, calibration_config, bump_config, temperature_config,
     bumps = _zeros((calibration_config['num-bumps'],), dtype=_float)
     for i in range(calibration_config['num-bumps']):
         _LOG.info('acquire bump %d of %d' % (i, calibration_config['num-bumps']))
-        bumps[i] = _bump(afm=afm, bump_config=bump_config,
+        bumps[i] = _bump(afm=afm, bump_config=calibration_config['bump'],
                          filename=filename, group='%sbump/%d/' % (group, i))
     _LOG.debug('bumps: %s' % bumps)
 
@@ -153,7 +149,8 @@ def calib_acquire(afm, calibration_config, bump_config, temperature_config,
         _LOG.info('acquire T %d of %d'
                  % (i, calibration_config['num-temperatures']))
         Ts[i] = _T(
-            get_T=afm.get_temperature, temperature_config=temperature_config,
+            get_T=afm.get_temperature,
+            temperature_config=calibration_config['temperature'],
             filename=filename, group='%stemperature/%d/' % (group, i))
         _sleep(calibration_config['temperature-sleep'])
     _LOG.debug('temperatures: %s' % Ts)
@@ -162,14 +159,13 @@ def calib_acquire(afm, calibration_config, bump_config, temperature_config,
     vibs = _zeros((calibration_config['num-vibrations'],), dtype=_float)
     for i in range(calibration_config['num-vibrations']):
         vibs[i] = _vib(
-            piezo=afm.piezo, vibration_config=vibration_config,
+            piezo=afm.piezo, vibration_config=calibration_config['vibration'],
             filename=filename, group='%svibration/%d/' % (group, i))
     _LOG.debug('vibrations: %s' % vibs)
 
     return (bumps, Ts, vibs)
 
-def calib(afm, calibration_config, bump_config, temperature_config,
-          vibration_config, filename=None, group='/'):
+def calib(afm, calibration_config, filename=None, group='/'):
     """Calibrate a cantilever in one function.
 
     Inputs:
@@ -182,18 +178,18 @@ def calib(afm, calibration_config, bump_config, temperature_config,
     >>> import os
     >>> from pprint import pprint
     >>> import tempfile
+    >>> from h5config.storage.hdf5 import pprint_HDF5
     >>> from pycomedi.device import Device
     >>> from pycomedi.subdevice import StreamingSubdevice
     >>> from pycomedi.channel import AnalogChannel, DigitalChannel
     >>> from pycomedi.constant import AREF, IO_DIRECTION, SUBDEVICE_TYPE, UNIT
     >>> from pypiezo.afm import AFMPiezo
     >>> from pypiezo.base import PiezoAxis, InputChannel
-    >>> from pypiezo.config import (HDF5_ChannelConfig, HDF5_AxisConfig,
-    ...     pprint_HDF5)
+    >>> from pypiezo.config import ChannelConfig, AxisConfig
     >>> from stepper import Stepper
     >>> from pyafm import AFM
-    >>> from .config import (HDF5_CalibrationConfig, HDF5_BumpConfig,
-    ...     HDF5_TemperatureConfig, HDF5_VibrationConfig)
+    >>> from .config import (CalibrationConfig, BumpConfig,
+    ...     TemperatureConfig, VibrationConfig)
     >>> from .analyze import calib_load_all
 
     >>> fd,filename = tempfile.mkstemp(suffix='.h5', prefix='calibcant-')
@@ -222,13 +218,11 @@ def calib(afm, calibration_config, bump_config, temperature_config,
     first few surface approaching steps, which could lead to an
     `EdgeKink` error instead of a `FlatFit` error.
 
-    >>> axis_config = HDF5_AxisConfig(filename, '/bump/config/z/axis')
+    >>> axis_config = AxisConfig()
     >>> axis_config.update(
     ...     {'gain':20, 'sensitivity':8e-9, 'minimum':-9})
-    >>> axis_channel_config = HDF5_ChannelConfig(
-    ...     filename, '/bump/config/z/channel')
-    >>> input_channel_config = HDF5_ChannelConfig(
-    ...     filename, '/bump/config/deflection/channel')
+    >>> axis_channel_config = ChannelConfig()
+    >>> input_channel_config = ChannelConfig()
 
     >>> a = PiezoAxis(axis_config=axis_config,
     ...     axis_channel_config=axis_channel_config,
@@ -261,14 +255,10 @@ def calib(afm, calibration_config, bump_config, temperature_config,
 
     Test calibration:
 
-    >>> calibration_config = HDF5_CalibrationConfig(
-    ...     filename=filename, group='/bump/config/calibration/')
-    >>> bump_config = HDF5_BumpConfig(
-    ...     filename=filename, group='/bump/config/bump/')
-    >>> temperature_config = HDF5_TemperatureConfig(
-    ...     filename=filename, group='/bump/config/temperature/')
-    >>> vibration_config = HDF5_VibrationConfig(
-    ...     filename=filename, group='/bump/config/vibration')
+    >>> calibration_config = CalibrationConfig()
+    >>> bump_config = BumpConfig()
+    >>> temperature_config = TemperatureConfig()
+    >>> vibration_config = VibrationConfig()
     >>> calib(afm, calibration_config, bump_config, temperature_config,
     ...     vibration_config, filename=filename, group='/')
     TODO: replace skipped example data with real-world values