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