Mercurial > ~darius > hgwebdir.cgi > pyinst
comparison find.py @ 38:7d76b1d70096
Add file to generate stats on data files.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Wed, 28 Sep 2011 12:30:20 +0930 |
parents | |
children | df1b4d7e988f |
comparison
equal
deleted
inserted
replaced
37:3d2306e39700 | 38:7d76b1d70096 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import datafile | |
4 import getopt | |
5 import numpy | |
6 import sys | |
7 | |
8 if __name__ == "__main__": | |
9 opts, args = getopt.getopt(sys.argv[1:], "e:hm:s") | |
10 | |
11 minlev = None | |
12 exptag = None | |
13 dostats = False | |
14 for o, a in opts: | |
15 if o == "-h": | |
16 print """Find data files with certain characteristics | |
17 | |
18 %s [-h] [-e exp] [-m min] [-s] file [file ..] | |
19 exp Limit to experiment tag exp | |
20 min Find files with power greater than min | |
21 -s Print stats about files | |
22 """ | |
23 elif o == "-e": | |
24 exptag = a | |
25 elif o == "-m": | |
26 minlev = float(a) | |
27 elif o == "-s": | |
28 dostats = True | |
29 else: | |
30 print "Unknown option " + o | |
31 sys.exit(1) | |
32 | |
33 if len(args) == 0: | |
34 print "Need at least one file to analyse" | |
35 sys.exit(1) | |
36 | |
37 minfiles = [] | |
38 if dostats: | |
39 print "%-50s %7s %7s %7s (dBm)" % ("Name", "Min", "Mean", "Max") | |
40 for fn in args: | |
41 dfile = datafile.DataFile(fn) | |
42 | |
43 if exptag != None and dfile['TAG'] != exptag: | |
44 continue | |
45 | |
46 if minlev != None: | |
47 if reduce(lambda x, y: x or y, dfile.powers > minlev): | |
48 minfiles.append(fn) | |
49 | |
50 if dostats: | |
51 print "%-50s %7.2f %7.2f %7.2f" % (fn, dfile.powers.min(), dfile.powers.mean(), dfile.powers.max()) | |
52 | |
53 if minlev != None: | |
54 if dostats: | |
55 print "" | |
56 print "Files with any element exceeding %.2f dBm:" % (minlev) | |
57 for fn in minfiles: | |
58 print fn | |
59 |