Fix problems with the transition to the new nested-Config h5config package.
[calibcant.git] / calibcant / bump.py
index 1e2a5b0f97009d3e001b72d2ccacffff1aa27961..90a4b9250459aba8f53d3a89c6c80a3a2ad2bb20 100644 (file)
@@ -87,6 +87,7 @@ def bump_acquire(afm, bump_config):
     """
     afm.move_just_onto_surface(
         depth=bump_config['initial-position'], far=bump_config['far-steps'])
+    #afm.piezo.jump('z', 32000)
 
     _LOG.info('bump the surface to a depth of %g m'
               % bump_config['push-depth'])
@@ -94,11 +95,9 @@ def bump_acquire(afm, bump_config):
     axis = afm.piezo.axis_by_name(afm.axis_name)
 
     start_pos = afm.piezo.last_output[afm.axis_name]
-    start_pos_m = _convert_bits_to_meters(
-        axis.axis_channel_config, axis.axis_config, start_pos)
+    start_pos_m = _convert_bits_to_meters(axis.config, start_pos)
     close_pos_m = start_pos_m + bump_config['push-depth']
-    close_pos = _convert_meters_to_bits(
-        axis.axis_channel_config, axis.axis_config, close_pos_m)
+    close_pos = _convert_meters_to_bits(axis.config, close_pos_m)
 
     dtype = afm.piezo.channel_dtype(afm.axis_name, direction='output')
     appr = _numpy.linspace(
@@ -123,7 +122,7 @@ def bump(afm, bump_config, filename, group='/'):
 
     >>> import os
     >>> import tempfile
-    >>> from h5config.storage.hdf5 import HDF5_Storage, pprint_HDF5
+    >>> from h5config.storage.hdf5 import pprint_HDF5
     >>> from pycomedi.device import Device
     >>> from pycomedi.subdevice import StreamingSubdevice
     >>> from pycomedi.channel import AnalogChannel, DigitalChannel
@@ -132,7 +131,7 @@ def bump(afm, bump_config, filename, 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 BumpConfig
 
     >>> fd,filename = tempfile.mkstemp(suffix='.h5', prefix='calibcant-')
@@ -161,26 +160,22 @@ def bump(afm, bump_config, filename, group='/'):
     first few surface approaching steps, which could lead to an
     `EdgeKink` error instead of a `FlatFit` error.
 
-    >>> axis_config = AxisConfig(storage=HDF5_Storage(
-    ...         filename=filename, group='/bump/config/z/axis'))
+    >>> axis_config = AxisConfig()
     >>> axis_config.update(
     ...     {'gain':20, 'sensitivity':8e-9, 'minimum':-9})
-    >>> axis_channel_config = ChannelConfig(storage=HDF5_Storage(
-    ...         filename=filename, group='/bump/config/z/channel'))
-    >>> input_channel_config = ChannelConfig(storage=HDF5_Storage(
-    ...         filename=filename, group='/bump/config/deflection/channel'))
-
-    >>> a = PiezoAxis(axis_config=axis_config,
-    ...     axis_channel_config=axis_channel_config,
-    ...     axis_channel=axis_channel, name='z')
+    >>> 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(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.
 
@@ -201,11 +196,90 @@ def bump(afm, bump_config, filename, group='/'):
 
     Test a bump:
 
-    >>> bump_config = BumpConfig(storage=HDF5_Storage(
-    ...         filename=filename, group='/bump/config/bump'))
+    >>> bump_config = BumpConfig()
     >>> bump(afm, bump_config, filename, group='/bump')
     TODO: replace skipped example data with real-world values
     >>> pprint_HDF5(filename)  # doctest: +ELLIPSIS, +REPORT_UDIFF
+    /
+      /bump
+        /bump/config
+          /bump/config/bump
+            <HDF5 dataset "far-steps": shape (), type "<i4">
+              200
+            <HDF5 dataset "initial-position": shape (), type "<f8">
+              -5e-08
+            <HDF5 dataset "model": shape (), type "|S9">
+              quadratic
+            <HDF5 dataset "push-depth": shape (), type "<f8">
+              2e-07
+            <HDF5 dataset "push-speed": shape (), type "<f8">
+              1e-06
+            <HDF5 dataset "samples": shape (), type "<i4">
+              1024
+            <HDF5 dataset "setpoint": shape (), type "<f8">
+              2.0
+          /bump/config/deflection
+            /bump/config/deflection/channel
+              <HDF5 dataset "channel": shape (), type "<i4">
+                0
+              <HDF5 dataset "conversion-coefficients": shape (2,), type "<f8">
+                [ -1.00000000e+01   3.05180438e-04]
+              <HDF5 dataset "conversion-origin": shape (), type "<f8">
+                0.0
+              <HDF5 dataset "device": shape (), type "|S12">
+                /dev/comedi0
+              <HDF5 dataset "inverse-conversion-coefficients": shape (2,), type "<f8">
+                [    0.    3276.75]
+              <HDF5 dataset "inverse-conversion-origin": shape (), type "<f8">
+                -10.0
+              <HDF5 dataset "maxdata": shape (), type "<i8">
+                65535
+              <HDF5 dataset "name": shape (), type "|S10">
+                deflection
+              <HDF5 dataset "range": shape (), type "<i4">
+                0
+              <HDF5 dataset "subdevice": shape (), type "<i4">
+                0
+          /bump/config/z
+            /bump/config/z/axis
+              /bump/config/z/axis/channel
+                <HDF5 dataset "channel": shape (), type "<i4">
+                  0
+                <HDF5 dataset "conversion-coefficients": shape (2,), type "<f8">
+                  [ -1.00000000e+01   3.05180438e-04]
+                <HDF5 dataset "conversion-origin": shape (), type "<f8">
+                  0.0
+                <HDF5 dataset "device": shape (), type "|S12">
+                  /dev/comedi0
+                <HDF5 dataset "inverse-conversion-coefficients": shape (2,), type "<f8">
+                  [    0.    3276.75]
+                <HDF5 dataset "inverse-conversion-origin": shape (), type "<f8">
+                  -10.0
+                <HDF5 dataset "maxdata": shape (), type "<i8">
+                  65535
+                <HDF5 dataset "name": shape (), type "|S1">
+                  z
+                <HDF5 dataset "range": shape (), type "<i4">
+                  0
+                <HDF5 dataset "subdevice": shape (), type "<i4">
+                  1
+              <HDF5 dataset "gain": shape (), type "<i4">
+                20
+              <HDF5 dataset "maximum": shape (), type "<f8">
+                10.0
+              <HDF5 dataset "minimum": shape (), type "<i4">
+                -9
+              <HDF5 dataset "monitor": shape (), type "|S1">
+    <BLANKLINE>
+              <HDF5 dataset "sensitivity": shape (), type "<f8">
+                8e-09
+        <HDF5 dataset "processed": shape (), type "<f8">
+          ...
+        /bump/raw
+          <HDF5 dataset "deflection": shape (2048,), type "<u2">
+            [...]
+          <HDF5 dataset "z": shape (2048,), type "<u2">
+            [...]
 
     Close the Comedi device.
 
@@ -220,13 +294,11 @@ def bump(afm, bump_config, filename, group='/'):
 
     data = bump_acquire(afm, bump_config)
     photo_sensitivity = _bump_analyze(
-        data, bump_config, z_channel_config=axis.axis_channel_config,
-        z_axis_config=axis.axis_config,
-        deflection_channel_config=deflection_channel.channel_config)
+        data, bump_config, z_axis_config=axis.config,
+        deflection_channel_config=deflection_channel.config)
     _bump_save(
         filename, group, data, bump_config,
-        z_channel_config=axis.axis_channel_config,
-        z_axis_config=axis.axis_config,
-        deflection_channel_config=deflection_channel.channel_config,
+        z_axis_config=axis.config,
+        deflection_channel_config=deflection_channel.config,
         processed_bump=photo_sensitivity)
     return photo_sensitivity