2 # Fairly stubby, since a one shot Temp measurement is a common thing.
3 # We just wrap that to provide a consistent interface.
5 from . import LOG as _LOG
6 from . import base_config as _base_config
7 from .T_analyze import T_analyze as _T_analyze
8 from .T_analyze import T_save as _T_save
11 def T_acquire(get_T=None):
12 """Measure the current temperature of the sample,
14 If `get_T` is `None`, fake it by returning
15 `base_config['temperature']`.
18 _LOG.info('measure temperature')
23 _LOG.info('fake temperature %g' % _base_config['temperature'])
24 T = _base_config['temperature']
27 def T(get_T, temperature_config, filename, group='/'):
28 """Wrapper around T_acquire(), T_analyze(), T_save().
32 >>> from pypiezo.config import pprint_HDF5
33 >>> from .config import HDF5_TemperatureConfig
35 >>> fd,filename = tempfile.mkstemp(suffix='.h5', prefix='calibcant-')
38 >>> temperature_config = HDF5_TemperatureConfig(
39 ... filename=filename, group='/T/config/')
43 >>> t = T(get_T=get_T, temperature_config=temperature_config,
44 ... filename=filename, group='/T/')
45 >>> pprint_HDF5(filename) # doctest: +ELLIPSIS, +REPORT_UDIFF
49 <HDF5 dataset "default": shape (), type "|S2">
51 <HDF5 dataset "units": shape (), type "|S7">
53 <HDF5 dataset "processed": shape (), type "<f8">
55 <HDF5 dataset "raw": shape (), type "<f8">
57 >>> t = T(get_T=None, temperature_config=temperature_config,
58 ... filename=filename, group='/T/')
59 >>> pprint_HDF5(filename) # doctest: +ELLIPSIS, +REPORT_UDIFF
63 <HDF5 dataset "default": shape (), type "|S3">
65 <HDF5 dataset "units": shape (), type "|S7">
67 <HDF5 dataset "processed": shape (), type "<f8">
69 <HDF5 dataset "raw": shape (), type "<i4">
72 Cleanup our temporary config file.
74 >>> os.remove(filename)
76 T_raw = T_acquire(get_T)
77 T_ret = _T_analyze(T_raw, temperature_config)
78 temperature_config['default'] = not get_T
79 _T_save(filename, group=group, raw_T=T_raw,
80 temperature_config=temperature_config, processed_T=T_ret)