convert to H5config and bump to v0.7.
[calibcant.git] / calibcant / config.py
index 8d7d51131a525536e4500d4003db17f62b1dd623..0a20c8f4fd131f43ec95b699bc6bacea4424919b 100644 (file)
 # calibcant - tools for thermally calibrating AFM cantilevers
 #
-# Copyright (C) 2007,2008, William Trevor King
+# Copyright (C) 2008-2011 W. Trevor King <wking@drexel.edu>
 #
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 3 of the
-# License, or (at your option) any later version.
+# This file is part of calibcant.
 #
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the GNU General Public License for more details.
+# calibcant is free software: you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation, either
+# version 3 of the License, or (at your option) any later version.
 #
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
+# calibcant is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
 #
-# The author may be contacted at <wking@drexel.edu> on the Internet, or
-# write to Trevor King, Drexel University, Physics Dept., 3141 Chestnut St.,
-# Philadelphia PA 19104, USA.
+# You should have received a copy of the GNU Lesser General Public
+# License along with calibcant.  If not, see
+# <http://www.gnu.org/licenses/>.
 
 """Define some variables to configure the package for a particular lab
 and workflow."""
 
-import z_piezo
-
-DEFAULT_TEMP = 22  # assume 22 deg C
-LOG_DATA = True  # quietly grab all real-world data and log to LOG_DIR
-LOG_DIR = '$DEFAULT$/calibrate_cantilever'
-GNUFIT_DATA_BASE='./calibrate_cantilever_fitdata'
-TEXT_VERBOSE = True      # for debugging
-GNUPLOT_VERBOSE = True     # turn on fit check plotting
-PYLAB_VERBOSE = True     # turn on plotting
-PYLAB_INTERACTIVE = True # select between draw() and show() for flushing plots
-BASE_FIGNUM = 20 # to avoid writing to already existing figures
-
-
-# HACK
-# make sure you make a system note (add_system_note) if you change
-# these in case you don't have access to a z_piezo for conversion
-# functions
-
-# zpGain      zpiezo applied voltage per output Volt
-zpGain = z_piezo.DEFAULT_GAIN
-# zpSensitivity  nm zpiezo response per applied Volt
-zpSensitivity = z_piezo.DEFAULT_SENSITIVITY
-# Vzp_out2V   function that converts output DAC bits to Volts
-Vzp_out2V = z_piezo.DEFAULT_VZP_OUT_2_VOLTS
-# Vphoto_in2V function that converts input ADC bits to Volts
-Vphoto_in2V = z_piezo.DEFAULT_VPHOTO_IN_2_VOLTS
-# zeroVphoto_bits  ADC bit output for a 0V input
-zeroVphoto_bits = z_piezo.DEFAULT_ZERO_PHOTODIODE_BITS
+import sys as _sys
+
+from FFT_tools import window_hann as _window_hann
+import h5config.config as _config
+import h5config.tools as _h5config_tools
+
+
+class PackageConfig (_h5config_tools.PackageConfig):
+    "Configure `calibcant` module operation"
+    settings = _h5config_tools.PackageConfig.settings + [
+        _config.BooleanSetting(
+            name='matplotlib',
+            help='Plot piezo motion using `matplotlib`.',
+            default=False),
+        _config.FloatSetting(
+            name='temperature',
+            help=('Default temperature for thermal calibration in degrees '
+                  'Celsius.'),
+            default=22),
+        ]
+
+class _TemperatureUnit (object):
+    pass
+class Celsius (_TemperatureUnit):
+    pass
+class Kelvin (_TemperatureUnit):
+    pass
+
+class TemperatureConfig (_config.Config):
+    "Configure `calibcant` temperature operation"
+    settings = [
+        _config.ChoiceSetting(
+            name='units',
+            help='Units of raw temperature measurements.',
+            default=Celsius,
+            choices=[
+                ('Celsius', Celsius),
+                ('Kelvin', Kelvin),
+                ]),
+        _config.BooleanSetting(
+            name='default',
+            help=('The temperature values are defaults (vs. real '
+                  'measurements).'),
+            default=True),
+        ]
+
+class _BumpModel (object):
+    pass
+class Linear (_BumpModel):
+    pass
+class Quadratic (_BumpModel):
+    pass
+
+class BumpConfig (_config.Config):
+    "Configure `calibcant` bump operation"
+    settings = [
+        _config.FloatSetting(
+            name='initial-position',
+            help=('Position relative to surface for start of bump in meters.  '
+                  'Should be less than zero to ensure non-contact region '
+                  'before you hit the surface.'),
+            default=-50e-9),
+        _config.FloatSetting(
+            name='setpoint',
+            help=('Maximum deflection in volts in case of stepper positioning '
+                  'to achieve the initial position.'),
+            default=2.0),
+        _config.IntegerSetting(
+            name='far-steps',
+            help=('Number of stepper steps to move "far" away from the '
+                  'surface.  For possible stepper adjustments while initially '
+                  'locating the surface.'),
+            default=200),
+        _config.FloatSetting(
+            name='push-depth',
+            help='Distance to approach in meters.',
+            default=200e-9),
+        _config.FloatSetting(
+            name='push-speed',
+            help='Approach/retract speed in meters/second.',
+            default=1e-6),
+        _config.FloatSetting(
+            name='samples',
+            help='Number of samples during approach and during retreat.',
+            default=1024),
+        _config.ChoiceSetting(
+            name='model',
+            help='Bump deflection model.',
+            default=Quadratic,
+            choices=[
+                ('linear', Linear),
+                ('quadratic', Quadratic),
+                ]),
+        ]
+
+class _VibrationModel (object):
+    pass
+class Variance (_VibrationModel):
+    pass
+class BreitWigner (_VibrationModel):
+    pass
+class OffsetBreitWigner (_VibrationModel):
+    pass
+
+class VibrationConfig (_config.Config):
+    "Configure `calibcant` vibration operation"
+    settings = [
+        _config.FloatSetting(
+            name='frequency',
+            help='Sampling frequency in Hz.',
+            default=50e3),
+        _config.FloatSetting(
+            name='sample-time',
+            help=('Aquisition time in seconds.  This is rounded up as required '
+                  'so the number of samples will be an integer power of two.'),
+            default=1),
+        _config.ChoiceSetting(
+            name='model',
+            help='Vibration model.',
+            default=BreitWigner,
+            choices=[
+                ('variance', Variance),
+                ('Breit-Wigner', BreitWigner),
+                ('offset Breit-Wigner', OffsetBreitWigner),
+                ]),
+        _config.IntegerSetting(
+            name='chunk-size',
+            help='FFT chunk size (for PSD fits).',
+            default=2048),
+        _config.BooleanSetting(
+            name='overlap',
+            help='Overlap FFT chunks (for PSD fits).'),
+        _config.ChoiceSetting(
+            name='window',
+            help='FFT chunk window (for PSD fits).',
+            default=_window_hann,
+            choices=[
+                ('Hann', _window_hann),
+                ]),
+        _config.FloatSetting(
+            name='minimum-fit-frequency',
+            help='Lower bound of Lorentzian fitting region.',
+            default=500.),
+        _config.FloatSetting(
+            name='maximum-fit-frequency',
+            help='Upper bound of Lorentzian fitting region.',
+            default=25e3),
+        ]
+
+
+class CalibrationConfig (_config.Config):
+    "Configure a full `calibcant` calibration run"
+    settings = [
+        _config.IntegerSetting(
+            name='num-bumps',
+            help='Number of surface bumps.',
+            default=10),
+        _config.IntegerSetting(
+            name='num-temperatures',
+            help='Number of temperature measurements.',
+            default=10),
+        _config.IntegerSetting(
+            name='num-vibrations',
+            help='Number of thermal vibration measurements.',
+            default=20),
+        _config.FloatSetting(
+            name='temperature-sleep',
+            help=('Time between temperature measurements (in seconds) to get '
+                  'independent measurements when reading from slow sensors.'),
+            default=1),
+        _config.FloatSetting(
+            name='vibration-spacing',
+            help=('Approximate distance from the surface in meters for the '
+                  'vibration measurements.  This should be large enough that '
+                  'surface effects are negligable.'),
+            default=50e-6),
+        ]