Get calibcant working with the new load_from_config-based pyafm.
[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 """h5config support, so we can easily save what we did and load it later.
20 """
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 from pyafm.config import AFMConfig as _AFMConfig
28
29
30 class PackageConfig (_h5config_tools.PackageConfig):
31     "Configure `calibcant` module operation"
32     settings = _h5config_tools.PackageConfig.settings + [
33         _config.BooleanSetting(
34             name='matplotlib',
35             help='Plot piezo motion using `matplotlib`.',
36             default=False),
37         ]
38
39
40 class _BumpModel (object):
41     pass
42 class Linear (_BumpModel):
43     pass
44 class Quadratic (_BumpModel):
45     pass
46
47 class BumpConfig (_config.Config):
48     "Configure `calibcant` bump operation"
49     settings = [
50         _config.FloatSetting(
51             name='initial-position',
52             help=('Position relative to surface for start of bump in meters.  '
53                   'Should be less than zero to ensure non-contact region '
54                   'before you hit the surface.'),
55             default=-50e-9),
56         _config.FloatSetting(
57             name='setpoint',
58             help=('Maximum deflection in volts in case of stepper positioning '
59                   'to achieve the initial position.'),
60             default=2.0),
61         _config.FloatSetting(
62             name='min-slope-ratio',
63             help=('Set the minimum ratio between the deflection/displacement '
64                   'of the contact and the non-contact regions for bumps '
65                   'seeking the surface.  Bumps without sufficient difference '
66                   'assume they need to move closer to find the surface.'),
67             default=10.0),
68         _config.IntegerSetting(
69             name='far-steps',
70             help=('Number of stepper steps to move "far" away from the '
71                   'surface.  For possible stepper adjustments while initially '
72                   'locating the surface.'),
73             default=200),
74         _config.FloatSetting(
75             name='push-depth',
76             help='Distance to approach in meters.',
77             default=200e-9),
78         _config.FloatSetting(
79             name='push-speed',
80             help='Approach/retract speed in meters/second.',
81             default=1e-6),
82         _config.FloatSetting(
83             name='samples',
84             help='Number of samples during approach and during retreat.',
85             default=1024),
86         _config.ChoiceSetting(
87             name='model',
88             help='Bump deflection model.',
89             default=Quadratic,
90             choices=[
91                 ('linear', Linear),
92                 ('quadratic', Quadratic),
93                 ]),
94         ]
95
96
97 class TemperatureConfig (_config.Config):
98     "Configure `calibcant` temperature operation"
99     settings = [
100         _config.FloatSetting(
101             name='sleep',
102             help=('Time between temperature measurements (in seconds) to get '
103                   'independent measurements when reading from slow sensors.'),
104             default=1),
105         ]
106
107
108 class _VibrationModel (object):
109     pass
110 class Variance (_VibrationModel):
111     pass
112 class BreitWigner (_VibrationModel):
113     pass
114 class OffsetBreitWigner (_VibrationModel):
115     pass
116
117 class VibrationConfig (_config.Config):
118     "Configure `calibcant` vibration operation"
119     settings = [
120         _config.FloatSetting(
121             name='frequency',
122             help='Sampling frequency in Hz.',
123             default=50e3),
124         _config.FloatSetting(
125             name='sample-time',
126             help=('Aquisition time in seconds.  This is rounded up as required '
127                   'so the number of samples will be an integer power of two.'),
128             default=1),
129         _config.ChoiceSetting(
130             name='model',
131             help='Vibration model.',
132             default=BreitWigner,
133             choices=[
134                 ('variance', Variance),
135                 ('Breit-Wigner', BreitWigner),
136                 ('offset Breit-Wigner', OffsetBreitWigner),
137                 ]),
138         _config.IntegerSetting(
139             name='chunk-size',
140             help='FFT chunk size (for PSD fits).',
141             default=2048),
142         _config.BooleanSetting(
143             name='overlap',
144             help='Overlap FFT chunks (for PSD fits).'),
145         _config.ChoiceSetting(
146             name='window',
147             help='FFT chunk window (for PSD fits).',
148             default=_window_hann,
149             choices=[
150                 ('Hann', _window_hann),
151                 ]),
152         _config.FloatSetting(
153             name='minimum-fit-frequency',
154             help='Lower bound of Lorentzian fitting region.',
155             default=500.),
156         _config.FloatSetting(
157             name='maximum-fit-frequency',
158             help='Upper bound of Lorentzian fitting region.',
159             default=25e3),
160         ]
161
162
163 class CalibrateConfig (_config.Config):
164     "Configure a full `calibcant` calibration run"
165     settings = [
166         _config.ConfigSetting(
167             name='afm',
168             help='Configure the AFM used to carry out the calibration',
169             config_class=_AFMConfig),
170         _config.ConfigSetting(
171             name='bump',
172             help='Configure the surface bumps',
173             config_class=BumpConfig),
174         _config.IntegerSetting(
175             name='num-bumps',
176             help='Number of surface bumps.',
177             default=10),
178         _config.ConfigSetting(
179             name='temperature',
180             help='Configure the temperature measurements',
181             config_class=TemperatureConfig),
182         _config.IntegerSetting(
183             name='num-temperatures',
184             help='Number of temperature measurements.',
185             default=10),
186         _config.ConfigSetting(
187             name='vibration',
188             help='Configure the temperature measurements',
189             config_class=VibrationConfig),
190         _config.IntegerSetting(
191             name='num-vibrations',
192             help='Number of thermal vibration measurements.',
193             default=20),
194         _config.FloatSetting(
195             name='vibration-spacing',
196             help=('Approximate distance from the surface in meters for the '
197                   'vibration measurements.  This should be large enough that '
198                   'surface effects are negligable.'),
199             default=50e-6),
200         ]