Convert to h5config's new get_attribute option for select_config.
authorW. Trevor King <wking@drexel.edu>
Sun, 25 Sep 2011 23:20:56 +0000 (19:20 -0400)
committerW. Trevor King <wking@drexel.edu>
Sun, 25 Sep 2011 23:20:56 +0000 (19:20 -0400)
pypiezo/afm.py
pypiezo/base.py
pypiezo/test.py

index 049d4a882c3e4e4f11a9a84c476f805556a1229c..da05b68535f5b954983416f71b6311cfc5dc66be 100644 (file)
@@ -97,7 +97,7 @@ class AFMPiezo (_base.Piezo):
     smoothly.
 
     >>> pos = _base.convert_volts_to_bits(p.config.select_config(
-    ...     'axes', 'z')['channel'], 0)
+    ...     'axes', 'z', get_attribute=_base.get_axis_name)['channel'], 0)
     >>> p.jump('z', pos)
 
     Usually `.move_to_pos_or_def` is used to approach the surface, but
@@ -105,7 +105,8 @@ class AFMPiezo (_base.Piezo):
     into the deflection input channel.
 
     >>> target_pos = _base.convert_volts_to_bits(
-    ...     p.config.select_config('axes', 'channel'), 2)
+    ...     p.config.select_config('axes', 'channel',
+            get_attribute=_base.get_axis_name), 2)
     >>> step = int((target_pos - pos)/5)
     >>> target_def = _base.convert_volts_to_bits(
     ...     p.config.select_config('inputs', 'deflection'), 3)
index 7ab0295a786de2d8adf2337e8c07b6f970dfc1d1..8cea54bb38ca6df1890a6d22cd0b34c16e07e380 100644 (file)
@@ -162,6 +162,15 @@ def convert_meters_to_bits(axis_config, data):
     data = convert_meters_to_volts(axis_config, data)
     return convert_volts_to_bits(axis_config['channel'], data)
 
+def get_axis_name(axis_config):
+    """Return the name of an axis from the `AxisConfig`
+
+    This is useful, for example, with
+    `Config.select_config(get_attribute=get_axis_name)`.
+    """
+    channel_config = axis_config['channel']
+    return channel_config['name']
+
 def _setup_channel_config(config, channel):
     """Initialize the `ChannelConfig` `config` using the
     `AnalogChannel` `channel`.
index bdc90a2e4a632ff63ed654ae44bd6f8e7264b186..e2efd7d90729441797dfc669bbffebe211bf6d5b 100644 (file)
@@ -21,6 +21,7 @@ These methods make it easier to write tests in packages that depend on
 pypiezo.
 """
 
+from .base import get_axis_name as _get_axis_name
 from .config import AxisConfig as _AxisConfig
 from .config import InputChannelConfig as _InputChannelConfig
 from .config import OutputChannelConfig as _OutputChannelConfig
@@ -91,8 +92,10 @@ def get_piezo_config(storage=None):
         conversion-origin: 0
         inverse-conversion-coefficients: 0, 1
         inverse-conversion-origin: 0
-    >>> d = p.select_config('inputs', 'deflection')
-    >>> d['name']
+    >>> get_axis_name
+    >>> d = p.select_config('inputs', 'deflection',
+    ...     get_attribute=_get_axis_name)
+    >>> d['channel']['name']
     'deflection'
     """
     piezo_config = _PiezoConfig(storage=storage)