Run update-copyright.py.
[calibcant.git] / bin / calibcant-plot.py
1 #!/usr/bin/env python
2 # calibcant - tools for thermally calibrating AFM cantilevers
3 #
4 # Copyright (C) 2011-2012 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 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 plot everything interesting.
21 """
22
23 from optparse import OptionParser
24
25 from matplotlib.pyplot import close, get_fignums, figure, show
26 from calibcant.analyze import calib_load_all, calib_plot_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('-b', '--no-bumps', dest='bumps', default=True,
36                  action='store_false',
37                  help="Don't display bump details.")
38     p.add_option('-v', '--no-vibrations', dest='vibrations', default=True,
39                  action='store_false',
40                  help="Don't display vibration details.")
41     p.add_option('-s', '--save-figures', dest='save', action='store_true',
42                  help="Save plots (instead of displaying them.")
43
44     options,args = p.parse_args(args)
45     filename = args[0]
46
47     stuff = calib_load_all(filename=filename, group=options.group)
48     if not options.bumps:
49         stuff['bump_details'] = []
50     if not options.vibrations:
51         stuff['vibration_details'] = []
52     calib_plot_all(**stuff)
53     if options.save:
54         for i in get_fignums():
55             fig = figure(i)
56             fig.savefig('%i.png' % i, dpi=300)
57             close(i)
58     else:
59         show()
60
61
62 if __name__ == '__main__':
63     import sys
64
65     sys.exit(main(sys.argv[1:]))