Convert calibcant to the new, nestable h5config.
[calibcant.git] / calibcant / config.py
1 # calibcant - tools for thermally calibrating AFM cantilevers
2 #
3 # Copyright (C) 2008-2011 W. Trevor King <wking@drexel.edu>
4 #
5 # This file is part of calibcant.
6 #
7 # calibcant is free software: you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation, either
10 # version 3 of the License, or (at your option) any later version.
11 #
12 # calibcant is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with calibcant.  If not, see
19 # <http://www.gnu.org/licenses/>.
20
21 """Define some variables to configure the package for a particular lab
22 and workflow."""
23
24 import sys as _sys
25
26 from FFT_tools import window_hann as _window_hann
27 import h5config.config as _config
28 import h5config.tools as _h5config_tools
29
30
31 class PackageConfig (_h5config_tools.PackageConfig):
32     "Configure `calibcant` module operation"
33     settings = _h5config_tools.PackageConfig.settings + [
34         _config.BooleanSetting(
35             name='matplotlib',
36             help='Plot piezo motion using `matplotlib`.',
37             default=False),
38         _config.FloatSetting(
39             name='temperature',
40             help=('Default temperature for thermal calibration in degrees '
41                   'Celsius.'),
42             default=22),
43         ]
44
45 class _TemperatureUnit (object):
46     pass
47 class Celsius (_TemperatureUnit):
48     pass
49 class Kelvin (_TemperatureUnit):
50     pass
51
52 class TemperatureConfig (_config.Config):
53     "Configure `calibcant` temperature operation"
54     settings = [
55         _config.ChoiceSetting(
56             name='units',
57             help='Units of raw temperature measurements.',
58             default=Celsius,
59             choices=[
60                 ('Celsius', Celsius),
61                 ('Kelvin', Kelvin),
62                 ]),
63         _config.BooleanSetting(
64             name='default',
65             help=('The temperature values are defaults (vs. real '
66                   'measurements).'),
67             default=True),
68         ]
69
70 class _BumpModel (object):
71     pass
72 class Linear (_BumpModel):
73     pass
74 class Quadratic (_BumpModel):
75     pass
76
77 class BumpConfig (_config.Config):
78     "Configure `calibcant` bump operation"
79     settings = [
80         _config.FloatSetting(
81             name='setpoint',
82             help=('Maximum deflection in volts in case of stepper positioning '
83                   'to achieve the initial position.'),
84             default=2.0),
85         _config.IntegerSetting(
86             name='far-steps',
87             help=('Number of stepper steps to move "far" away from the '
88                   'surface.  For possible stepper adjustments while initially '
89                   'locating the surface.'),
90             default=200),
91         _config.FloatSetting(
92             name='push-depth',
93             help='Distance to approach in meters.',
94             default=200e-9),
95         _config.FloatSetting(
96             name='push-speed',
97             help='Approach/retract speed in meters/second.',
98             default=1e-6),
99         _config.FloatSetting(
100             name='samples',
101             help='Number of samples during approach and during retreat.',
102             default=1024),
103         _config.ChoiceSetting(
104             name='model',
105             help='Bump deflection model.',
106             default=Quadratic,
107             choices=[
108                 ('linear', Linear),
109                 ('quadratic', Quadratic),
110                 ]),
111         ]
112
113 class BumpResult (_config.Config):
114     "The result of a `calibcant` bump operation"
115     
116
117 class _VibrationModel (object):
118     pass
119 class Variance (_VibrationModel):
120     pass
121 class BreitWigner (_VibrationModel):
122     pass
123 class OffsetBreitWigner (_VibrationModel):
124     pass
125
126 class VibrationConfig (_config.Config):
127     "Configure `calibcant` vibration operation"
128     settings = [
129         _config.FloatSetting(
130             name='frequency',
131             help='Sampling frequency in Hz.',
132             default=50e3),
133         _config.FloatSetting(
134             name='sample-time',
135             help=('Aquisition time in seconds.  This is rounded up as required '
136                   'so the number of samples will be an integer power of two.'),
137             default=1),
138         _config.ChoiceSetting(
139             name='model',
140             help='Vibration model.',
141             default=BreitWigner,
142             choices=[
143                 ('variance', Variance),
144                 ('Breit-Wigner', BreitWigner),
145                 ('offset Breit-Wigner', OffsetBreitWigner),
146                 ]),
147         _config.IntegerSetting(
148             name='chunk-size',
149             help='FFT chunk size (for PSD fits).',
150             default=2048),
151         _config.BooleanSetting(
152             name='overlap',
153             help='Overlap FFT chunks (for PSD fits).'),
154         _config.ChoiceSetting(
155             name='window',
156             help='FFT chunk window (for PSD fits).',
157             default=_window_hann,
158             choices=[
159                 ('Hann', _window_hann),
160                 ]),
161         _config.FloatSetting(
162             name='minimum-fit-frequency',
163             help='Lower bound of Lorentzian fitting region.',
164             default=500.),
165         _config.FloatSetting(
166             name='maximum-fit-frequency',
167             help='Upper bound of Lorentzian fitting region.',
168             default=25e3),
169         ]
170
171
172 class CalibrationConfig (_config.Config):
173     "Configure a full `calibcant` calibration run"
174     settings = [
175         _config.ConfigSetting(
176             name='bump',
177             help='Configure the surface bumps',
178             config_class=BumpConfig),
179         _config.IntegerSetting(
180             name='num-bumps',
181             help='Number of surface bumps.',
182             default=10),
183         _config.ConfigSetting(
184             name='temperature',
185             help='Configure the temperature measurements',
186             config_class=TemperatureConfig),
187         _config.IntegerSetting(
188             name='num-temperatures',
189             help='Number of temperature measurements.',
190             default=10),
191         _config.ConfigSetting(
192             name='vibration',
193             help='Configure the temperature measurements',
194             config_class=VibrationConfig),
195         _config.IntegerSetting(
196             name='num-vibrations',
197             help='Number of thermal vibration measurements.',
198             default=20),
199         _config.FloatSetting(
200             name='temperature-sleep',
201             help=('Time between temperature measurements (in seconds) to get '
202                   'independent measurements when reading from slow sensors.'),
203             default=1),
204         _config.FloatSetting(
205             name='vibration-spacing',
206             help=('Approximate distance from the surface in meters for the '
207                   'vibration measurements.  This should be large enough that '
208                   'surface effects are negligable.'),
209             default=50e-6),
210         ]