Fix problems with the transition to the new nested-Config h5config package.
authorW. Trevor King <wking@drexel.edu>
Fri, 30 Sep 2011 18:36:22 +0000 (14:36 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 30 Sep 2011 18:36:22 +0000 (14:36 -0400)
Also restore BumpConfig's `initial-position` setting, since it's
critical to running a bump.  I removed it when I mistakenly thought it
was storeing the output voltage used as the initial position
(something that you'd measure during a bump).  I guess I should have
read the help string before I deleted it ;).

There are also a number of numpy array -> float conversions when
loading HDF5.  This avoids excessive numpy-fication with h5py v2.0.

calibcant/calibrate.py

index 426abbf5b686f07143a80b54d2a153eea38cba51..2f850e144742bff1e71b7ad0f5f0fb5fced949f5 100644 (file)
@@ -187,7 +187,7 @@ def calib(afm, calibration_config, filename=None, group='/'):
     >>> from pypiezo.base import PiezoAxis, InputChannel
     >>> from pypiezo.config import ChannelConfig, AxisConfig
     >>> from stepper import Stepper
-    >>> from pyafm import AFM
+    >>> from pyafm.afm import AFM
     >>> from .config import (CalibrationConfig, BumpConfig,
     ...     TemperatureConfig, VibrationConfig)
     >>> from .analyze import calib_load_all
@@ -222,19 +222,18 @@ def calib(afm, calibration_config, filename=None, group='/'):
     >>> axis_config.update(
     ...     {'gain':20, 'sensitivity':8e-9, 'minimum':-9})
     >>> axis_channel_config = ChannelConfig()
+    >>> axis_channel_config['name'] = 'z'
+    >>> axis_config['channel'] = axis_channel_config
     >>> input_channel_config = ChannelConfig()
+    >>> input_channel_config['name'] = 'deflection'
 
-    >>> a = PiezoAxis(axis_config=axis_config,
-    ...     axis_channel_config=axis_channel_config,
-    ...     axis_channel=axis_channel, name='z')
+    >>> a = PiezoAxis(config=axis_config, axis_channel=axis_channel)
     >>> a.setup_config()
 
-    >>> c = InputChannel(
-    ...     channel_config=input_channel_config, channel=input_channel,
-    ...     name='deflection')
+    >>> c = InputChannel(config=input_channel_config, channel=input_channel)
     >>> c.setup_config()
 
-    >>> piezo = AFMPiezo(axes=[a], input_channels=[c])
+    >>> piezo = AFMPiezo(axes=[a], inputs=[c])
 
     Setup a `stepper` instance.
 
@@ -256,16 +255,137 @@ def calib(afm, calibration_config, filename=None, group='/'):
     Test calibration:
 
     >>> 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='/')
+    >>> calibration_config['bump'] = BumpConfig()
+    >>> calibration_config['temperature'] = TemperatureConfig()
+    >>> calibration_config['vibration'] = VibrationConfig()
+    >>> calib(afm, calibration_config, filename=filename, group='/')
     TODO: replace skipped example data with real-world values
     >>> pprint_HDF5(filename)  # doctest: +ELLIPSIS, +REPORT_UDIFF
+    /
+      /bump
+        /bump/0
+          /bump/0/config
+            /bump/0/config/bump
+              <HDF5 dataset "far-steps": shape (), type "<i4">
+                200
+              ...
+            /bump/0/config/deflection
+              /bump/0/config/deflection/channel
+                <HDF5 dataset "channel": shape (), type "<i4">
+                  0
+                ...
+            /bump/0/config/z
+              /bump/0/config/z/axis
+                /bump/0/config/z/axis/channel
+                  <HDF5 dataset "channel": shape (), type "<i4">
+                    0
+                  ...
+                <HDF5 dataset "gain": shape (), type "<i4">
+                  20
+                ...
+          <HDF5 dataset "processed": shape (), type "<f8">
+            ...
+          /bump/0/raw
+            <HDF5 dataset "deflection": shape (2048,), type "<u2">
+              [...]
+            <HDF5 dataset "z": shape (2048,), type "<u2">
+              [...]
+        /bump/1
+        ...
+      /calibration
+        /calibration/config
+          /calibration/config/bump
+            <HDF5 dataset "far-steps": shape (), type "<i4">
+              200
+            ...
+          <HDF5 dataset "num-bumps": shape (), type "<i4">
+            10
+          ...
+        /calibration/processed
+          /calibration/processed/spring-constant
+            <HDF5 dataset "data": shape (), type "<f8">
+              ...
+            <HDF5 dataset "standard-deviation": shape (), type "<f8">
+              ...
+            <HDF5 dataset "units": shape (), type "|S3">
+              N/m
+        /calibration/raw
+          /calibration/raw/photodiode-sensitivity
+            <HDF5 dataset "data": shape (10,), type "<f8">
+              [...]
+            <HDF5 dataset "units": shape (), type "|S3">
+              V/m
+          /calibration/raw/temperature
+            <HDF5 dataset "data": shape (10,), type "<f8">
+              [...]
+            <HDF5 dataset "units": shape (), type "|S1">
+              K
+          /calibration/raw/thermal-vibration-variance
+            <HDF5 dataset "data": shape (20,), type "<f8">
+              [...]
+            <HDF5 dataset "units": shape (), type "|S3">
+              V^2
+      /temperature
+        /temperature/0
+          /temperature/0/config
+            <HDF5 dataset "default": shape (), type "|b1">
+              False
+            <HDF5 dataset "units": shape (), type "|S7">
+              Celsius
+          <HDF5 dataset "processed": shape (), type "<f8">
+            295.15
+          <HDF5 dataset "raw": shape (), type "<i4">
+            22
+        /temperature/1
+        ...
+      /vibration
+        /vibration/0
+          /vibration/0/config
+            /vibration/0/config/deflection
+              <HDF5 dataset "channel": shape (), type "<i4">
+                0
+              ...
+            /vibration/0/config/vibration
+              <HDF5 dataset "chunk-size": shape (), type "<i4">
+                2048
+              ...
+          <HDF5 dataset "processed": shape (), type "<f8">
+            ...
+          /vibration/0/raw
+            <HDF5 dataset "deflection": shape (65536,), type "<u2">
+              [...]
+        /vibration/1
+        ...
+        /vibration/19
+          ...
+          /vibration/19/raw
+            <HDF5 dataset "deflection": shape (65536,), type "<u2">
+              [...]
     >>> everything = calib_load_all(filename, '/')
-    >>> pprint(everything)
-
+    >>> pprint(everything)  # doctest: +ELLIPSIS, +REPORT_UDIFF
+    {'bump_details': [{'bump_config': <BumpConfig ...>,
+                       'deflection_channel_config': <ChannelConfig ...>,
+                       'processed_bump': ...,
+                       'raw_bump': {'deflection': array([...], dtype=uint16),
+                                    'z': array([...], dtype=uint16)},
+                       'z_axis_config': <AxisConfig ...>},
+                      ...],
+     'bumps': array([...]),
+     'calibration_config': <CalibrationConfig ...>,
+     'k': ...,
+     'k_s': ...,
+     'temperature_details': [{'processed_temperature': ...,
+                              'raw_temperature': array(22),
+                              'temperature_config': <TemperatureConfig ...>},
+                             ...],
+     'temperatures': array([...]),
+     'vibration_details': [{'deflection_channel_config': <ChannelConfig ...>,
+                            'processed_vibration': ...,
+                            'raw_vibration': array([...], dtype=uint16),
+                            'vibration_config': <VibrationConfig ...>},
+                           ...],
+     'vibrations': array([...])}
+     
     Close the Comedi device.
 
     >>> d.close()
@@ -275,8 +395,7 @@ def calib(afm, calibration_config, filename=None, group='/'):
     os.remove(filename)
     """
     bumps, Ts, vibs = calib_acquire(
-        afm, calibration_config, bump_config, temperature_config,
-        vibration_config, filename=filename, group=group)
+        afm, calibration_config, filename=filename, group=group)
     # TODO: convert vib units?
     k,k_s = _calib_analyze(bumps, Ts, vibs)
     _calib_save(filename, group=group+'calibration/', bumps=bumps,