except KeyError:
pass
cwg['raw'] = raw_T
- if temperature_config:
+ if temperature_config is not None:
config_cwg = _h5_create_group(cwg, 'config')
- temperature_config.save(group=config_cwg)
+ storage = _HDF5_Storage()
+ storage.save(config=temperature_config, group=config_cwg)
if processed_T is not None:
try:
del cwg['processed']
cwg = _h5_create_group(f, group)
if calibration_config is not None:
config_cwg = _h5_create_group(cwg, 'config')
- calibration_config.save(group=config_cwg)
+ storage = _HDF5_Storage()
+ storage.save(config=calibration_config, group=config_cwg)
if bumps is not None:
try:
del cwg['raw/photodiode-sensitivity/data']
except KeyError:
pass
try:
- k = f[group+'processed/spring-constant/data'][...]
+ k = float(f[group+'processed/spring-constant/data'][...])
except KeyError:
pass
try:
- k_s = f[group+'processed/spring-constant/standard-deviation'][...]
+ k_s = float(
+ f[group+'processed/spring-constant/standard-deviation'][...])
except KeyError:
pass
calibration_config = _CalibrationConfig(storage=_HDF5_Storage(
filename, group+'calibration/')
bump_details = []
for i in range(calibration_config['num-bumps']):
- (raw_bump,bump_config,z_channel_config,z_axis_config,
- deflection_channel_config,processed_bump) = _bump_load(
+ (raw_bump,bump_config,z_axis_config,deflection_channel_config,
+ processed_bump) = _bump_load(
filename=filename, group='%sbump/%d/' % (group, i))
bump_details.append({
'raw_bump': raw_bump,
'bump_config': bump_config,
- 'z_channel_config': z_channel_config,
'z_axis_config': z_axis_config,
'deflection_channel_config': deflection_channel_config,
'processed_bump': processed_bump,
"""
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'])
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(
>>> 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
>>> 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-')
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.
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.
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
/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">
i_high = i
x_contact = float(x[i_low])
x_high = float(x[i_high])
+ if x_high == x_contact:
+ x.tofile('x-bad.dat', sep='\n')
+ y.tofile('y-bad.dat', sep='\n')
slope = (y_high - y_contact) / (x_high - x_contact)
return (x_contact, y_contact, slope)
_LOG.debug('solution converged')
else:
_LOG.debug('solution did not converge')
- if plot or _package_config['matplotlib'] or True:
+ if plot or _package_config['matplotlib']:
yguess = model(z, param_guess, high_voltage_rail=high_voltage_rail)
yfit = model(z, p, high_voltage_rail=high_voltage_rail)
bump_plot({'z': z, 'deflection': deflection}, yguess=yguess, yfit=yfit)
filename=filename, group=group+key))
configs.append(config)
try:
- processed_bump = f[group+'processed'][...]
+ processed_bump = float(f[group+'processed'][...])
except KeyError:
pass
ret = [raw_bump]
>>> 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
>>> 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.
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()
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,
class BumpConfig (_config.Config):
"Configure `calibcant` bump operation"
settings = [
+ _config.FloatSetting(
+ name='initial-position',
+ help=('Position relative to surface for start of bump in meters. '
+ 'Should be less than zero to ensure non-contact region '
+ 'before you hit the surface.'),
+ default=-50e-9),
_config.FloatSetting(
name='setpoint',
help=('Maximum deflection in volts in case of stepper positioning '
]),
]
-class BumpResult (_config.Config):
- "The result of a `calibcant` bump operation"
-
class _VibrationModel (object):
pass
>>> channel.range = channel.find_range(
... unit=UNIT.volt, min=-10, max=10)
>>> channel_config = ChannelConfig()
+ >>> channel_config['name'] = 'deflection'
- >>> c = InputChannel(
- ... channel_config=channel_config, channel=channel,
- ... name='deflection')
+ >>> c = InputChannel(config=channel_config, channel=channel)
>>> c.setup_config()
- >>> piezo = AFMPiezo(axes=[], input_channels=[c])
+ >>> piezo = AFMPiezo(axes=[], inputs=[c])
Test a vibration:
/vibration
/vibration/config
/vibration/config/deflection
- /vibration/config/deflection/channel
- <HDF5 dataset "channel": shape (), type "|S1">
- 0
- <HDF5 dataset "conversion-coefficients": shape (), type "|S24">
- -10.0, 0.000305180437934
- <HDF5 dataset "conversion-origin": shape (), type "|S3">
- 0.0
- <HDF5 dataset "device": shape (), type "|S12">
- /dev/comedi0
- <HDF5 dataset "inverse-conversion-coefficients": shape (), type "|S12">
- 0.0, 3276.75
- <HDF5 dataset "inverse-conversion-origin": shape (), type "|S5">
- -10.0
- <HDF5 dataset "maxdata": shape (), type "|S5">
- 65535
- <HDF5 dataset "range": shape (), type "|S1">
- 0
- <HDF5 dataset "subdevice": shape (), type "|S1">
- 0
+ <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
/vibration/config/vibration
- <HDF5 dataset "chunk-size": shape (), type "|S4">
+ <HDF5 dataset "chunk-size": shape (), type "<i4">
2048
- <HDF5 dataset "frequency": shape (), type "|S7">
+ <HDF5 dataset "frequency": shape (), type "<f8">
50000.0
- <HDF5 dataset "maximum-fit-frequency": shape (), type "|S7">
+ <HDF5 dataset "maximum-fit-frequency": shape (), type "<f8">
25000.0
- <HDF5 dataset "minimum-fit-frequency": shape (), type "|S5">
+ <HDF5 dataset "minimum-fit-frequency": shape (), type "<f8">
500.0
<HDF5 dataset "model": shape (), type "|S12">
Breit-Wigner
- <HDF5 dataset "overlap": shape (), type "|S2">
- no
- <HDF5 dataset "sample-time": shape (), type "|S1">
+ <HDF5 dataset "overlap": shape (), type "|b1">
+ False
+ <HDF5 dataset "sample-time": shape (), type "<i4">
1
<HDF5 dataset "window": shape (), type "|S4">
Hann
"""
deflection_input_channel = piezo.input_channel_by_name('deflection')
- deflection_channel_config = deflection_input_channel.channel_config
+ deflection_channel_config = deflection_input_channel.config
deflection = vib_acquire(piezo, vibration_config)
variance = _vib_analyze(
filename=filename, group=group+key))
configs.append(config)
try:
- processed_vibration = f[group+'processed'][...]
+ processed_vibration = float(f[group+'processed'][...])
except KeyError:
pass
ret = [raw_vibration]