Actually, avoid dollars in code (entities escaped when writing the HTML).
[blog.git] / posts / calibcant.mdwn_itex
1 [[!meta  title="calibcant"]]
2 [[!template id=gitrepo repo=calibcant]]
3
4 Here is my Python module for AFM cantilever calibration via the
5 thermal tune method.
6
7 The `README` is posted on the [PyPI page][pypi], and you might also be
8 interested in the [[package dependency graph|calibcant.svg]] generated
9 with Yu-Jie Lin's [PDepGraph.py][]:
10
11     # python PDepGraph.py -o calibcant.dot \
12         -D matplotlib,scipy,numpy,pyyaml,h5py,python,eselect-python \
13         calibcant
14     # dot -T svg -o calibcant.svg calibcant.dot
15
16 Thermal calibration requires three separate measurements: photodiode
17 sensitivity (via surface bumps), fluid temperature (estimated, or via
18 thermocouple), and thermal vibration (watching the cantilever vibrate
19 in far from the surface).  The calibcant package takes repeated
20 measurements ([[!ltio statistics.png]]) of each of these parameters to
21 allow estimation of statistical uncertainty:
22
23     # calibcant-analyze.py calibcant/examples/calibration.h5
24     ...
25     ... variable (units)         : mean +/- std. dev. (relative error)
26     ... cantilever k (N/m)       : 0.0629167 +/- 0.00439057 (0.0697838)
27     ... photo sensitivity (V/m)  : 2.4535e+07 +/- 616119 (0.0251118)
28     ... T (K)                    : 295.15 +/- 0 (0)
29     ... vibration variance (V^2) : 3.89882e-05 +/- 1.88897e-06 (0.0484497)
30     ...
31
32 While this cannot account for systematic errors, calibration numbers
33 are fairly meaninless without at least statistical error estimates.
34
35 Extracting the photodiode sensitivity and thermal deflection variance
36 from the raw data can vary a suprising amount depending on your
37 cantilever/photodiode linearity and drift and signal/noise ratio in
38 the vibration data.  To help deal with this, calibcant provides a
39 choice of models for fitting each measurement type.
40
41 The contact region of surface bumps can be fit with either linear or
42 quadratic models.  Here is an example of a single surface bump fit
43 with a quadratic model.  The green line is the initial guess (before
44 fitting), the red line is the final model (after fitting), and the
45 blue dots are measured data points.
46
47 [[!img bump.png alt="Surface bump for photodiode sensitivity"
48   title="Surface bump for photodiode sensitivity" ]]
49
50 Extracting the thermal vibration variance is also trickier than it
51 might seem.  Fitting the data in frequency-space to a Lorentzian
52 ([Breit-Wigner][]?)  model helps filter out low frequency drift, as
53 well as white noise from the measurement equipment.
54
55 \[
56   \text{PSD}(x, \omega) =
57     \frac{2 k_{B} T \beta}
58          { \pi m \left[{(\omega_0^2-\omega^2)^2 + \beta^2\omega^2}\right] }
59     + W \;.
60 \]
61
62 where $\beta$ and $\omega_0$ come from the damped-forced harmonic
63 oscillator equation of motion
64
65 \[
66   \ddot{x} + \beta \dot{x} + \omega_0^2 x = \frac{F(t)}{m} \;,
67 \]
68
69 the cantilever's effective mass is $m$, and $W$ is an optional
70 white-noise offset.
71
72 Here is an example of a one-second thermal vibration fit with the
73 offset Breit-Wigner model.  The top panel is the time-series
74 deflection voltage (bits vs sample index).  The center pannel is a
75 histogram of the deflection voltage, showing an approximately Gaussian
76 distribution.  The bottom panel shows the power spectral density fit
77 (red dots) fit with an offset Breit-Wigner model (blue curve).  The
78 horizontal blue line marks the white-noise offset, and the vertical
79 blue line marks the resonant frequency.  Points outside the light blue
80 region were not considered during the fitting.  This allows us to
81 isolate the cantilever's thermal vibration from other noise sources,
82 which leads to more accurate and reproducible spring constant
83 estimates.
84
85 [[!img vibration.png alt="Thermal vibration measurement"
86   title="Thermal vibration measurement" ]]
87
88 Finally, all data and analysis results are stored in the standard,
89 portable [[HDF5]] file format, so it's easy to reanalyze earlier
90 calibration data with different models if you decide to do so at a
91 later date, or just look back and see exactly what calculations went
92 into your spring constant calibration in the first place.
93
94 [pypi]: http://pypi.python.org/pypi/calibcant/
95 [PDepgraph.py]:
96   http://code.google.com/p/yjl/source/browse/Miscellaneous/PDepGraph.py
97 [Breit-Wigner]:
98   http://en.wikipedia.org/wiki/Relativistic_Breit%E2%80%93Wigner_distribution
99
100 [[!tag tags/code]]
101 [[!tag tags/linux]]
102 [[!tag tags/programming]]
103 [[!tag tags/pypi]]
104 [[!tag tags/python]]