c80e791c1cfe3307a66b67a703bbf39ffc9e518e
[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='initial-position',
82             help=('Position relative to surface for start of bump in meters.  '
83                   'Should be less than zero to ensure non-contact region '
84                   'before you hit the surface.'),
85             default=-50e-9),
86         _config.FloatSetting(
87             name='setpoint',
88             help=('Maximum deflection in volts in case of stepper positioning '
89                   'to achieve the initial position.'),
90             default=2.0),
91         _config.IntegerSetting(
92             name='far-steps',
93             help=('Number of stepper steps to move "far" away from the '
94                   'surface.  For possible stepper adjustments while initially '
95                   'locating the surface.'),
96             default=200),
97         _config.FloatSetting(
98             name='push-depth',
99             help='Distance to approach in meters.',
100             default=200e-9),
101         _config.FloatSetting(
102             name='push-speed',
103             help='Approach/retract speed in meters/second.',
104             default=1e-6),
105         _config.FloatSetting(
106             name='samples',
107             help='Number of samples during approach and during retreat.',
108             default=1024),
109         _config.ChoiceSetting(
110             name='model',
111             help='Bump deflection model.',
112             default=Quadratic,
113             choices=[
114                 ('linear', Linear),
115                 ('quadratic', Quadratic),
116                 ]),
117         ]
118
119
120 class _VibrationModel (object):
121     pass
122 class Variance (_VibrationModel):
123     pass
124 class BreitWigner (_VibrationModel):
125     pass
126 class OffsetBreitWigner (_VibrationModel):
127     pass
128
129 class VibrationConfig (_config.Config):
130     "Configure `calibcant` vibration operation"
131     settings = [
132         _config.FloatSetting(
133             name='frequency',
134             help='Sampling frequency in Hz.',
135             default=50e3),
136         _config.FloatSetting(
137             name='sample-time',
138             help=('Aquisition time in seconds.  This is rounded up as required '
139                   'so the number of samples will be an integer power of two.'),
140             default=1),
141         _config.ChoiceSetting(
142             name='model',
143             help='Vibration model.',
144             default=BreitWigner,
145             choices=[
146                 ('variance', Variance),
147                 ('Breit-Wigner', BreitWigner),
148                 ('offset Breit-Wigner', OffsetBreitWigner),
149                 ]),
150         _config.IntegerSetting(
151             name='chunk-size',
152             help='FFT chunk size (for PSD fits).',
153             default=2048),
154         _config.BooleanSetting(
155             name='overlap',
156             help='Overlap FFT chunks (for PSD fits).'),
157         _config.ChoiceSetting(
158             name='window',
159             help='FFT chunk window (for PSD fits).',
160             default=_window_hann,
161             choices=[
162                 ('Hann', _window_hann),
163                 ]),
164         _config.FloatSetting(
165             name='minimum-fit-frequency',
166             help='Lower bound of Lorentzian fitting region.',
167             default=500.),
168         _config.FloatSetting(
169             name='maximum-fit-frequency',
170             help='Upper bound of Lorentzian fitting region.',
171             default=25e3),
172         ]
173
174
175 class CalibrationConfig (_config.Config):
176     "Configure a full `calibcant` calibration run"
177     settings = [
178         _config.ConfigSetting(
179             name='bump',
180             help='Configure the surface bumps',
181             config_class=BumpConfig),
182         _config.IntegerSetting(
183             name='num-bumps',
184             help='Number of surface bumps.',
185             default=10),
186         _config.ConfigSetting(
187             name='temperature',
188             help='Configure the temperature measurements',
189             config_class=TemperatureConfig),
190         _config.IntegerSetting(
191             name='num-temperatures',
192             help='Number of temperature measurements.',
193             default=10),
194         _config.ConfigSetting(
195             name='vibration',
196             help='Configure the temperature measurements',
197             config_class=VibrationConfig),
198         _config.IntegerSetting(
199             name='num-vibrations',
200             help='Number of thermal vibration measurements.',
201             default=20),
202         _config.FloatSetting(
203             name='temperature-sleep',
204             help=('Time between temperature measurements (in seconds) to get '
205                   'independent measurements when reading from slow sensors.'),
206             default=1),
207         _config.FloatSetting(
208             name='vibration-spacing',
209             help=('Approximate distance from the surface in meters for the '
210                   'vibration measurements.  This should be large enough that '
211                   'surface effects are negligable.'),
212             default=50e-6),
213         ]