Massive rewrite (v 0.6) to base everything on Cython and revamped pypiezo.
[calibcant.git] / bin / analyze.py
1 #!/usr/bin/env python
2 # calibcant - tools for thermally calibrating AFM cantilevers
3 #
4 # Copyright (C) 2008-2011 W. Trevor King <wking@drexel.edu>
5 #
6 # This file is part of calibcant.
7 #
8 # calibcant is free software: you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation, either
11 # version 3 of the License, or (at your option) any later version.
12 #
13 # calibcant is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with calibcant.  If not, see
20 # <http://www.gnu.org/licenses/>.
21
22 """Load a calibration file and (re)analyze from the raw data.
23 """
24
25 from optparse import OptionParser
26
27 from matplotlib.pyplot import show
28 from calibcant.analyze import calib_analyze_all
29
30
31 def main(args):
32     usage = '%prog [options] filename'
33     p = OptionParser(usage)
34
35     p.add_option('-g', '--group', dest='group', default='/',
36                  help='HDF5 group containing calibration data (%default).')
37     p.add_option('-d', '--dry-run', dest='dry_run', action='store_true',
38                  help="Don't change the original file.")
39
40     options,args = p.parse_args(args)
41     filename = args[0]
42
43     k,k_s = calib_analyze_all(
44         filename=filename, group=options.group, dry_run=options.dry_run)
45     print "New spring constant:"
46     print "%g +/- %g N/m" % (k, k_s)
47
48
49 if __name__ == '__main__':
50     import sys
51
52     sys.exit(main(sys.argv[1:]))