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