From 3a26ea6a04a07635f26d446f5e822e413546c09f Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 25 Sep 2011 19:20:56 -0400 Subject: [PATCH] Convert to h5config's new get_attribute option for select_config. --- pypiezo/afm.py | 5 +++-- pypiezo/base.py | 9 +++++++++ pypiezo/test.py | 7 +++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pypiezo/afm.py b/pypiezo/afm.py index 049d4a8..da05b68 100644 --- a/pypiezo/afm.py +++ b/pypiezo/afm.py @@ -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) diff --git a/pypiezo/base.py b/pypiezo/base.py index 7ab0295..8cea54b 100644 --- a/pypiezo/base.py +++ b/pypiezo/base.py @@ -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`. diff --git a/pypiezo/test.py b/pypiezo/test.py index bdc90a2..e2efd7d 100644 --- a/pypiezo/test.py +++ b/pypiezo/test.py @@ -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) -- 2.26.2