comparison find.py @ 56:91b476ebc0f2

Run through 2to3
author Daniel O'Connor <doconnor@gsoft.com.au>
date Tue, 08 Dec 2020 14:00:45 +1030
parents df1b4d7e988f
children
comparison
equal deleted inserted replaced
55:ad5942d22f78 56:91b476ebc0f2
2 2
3 import datafile 3 import datafile
4 import getopt 4 import getopt
5 import numpy 5 import numpy
6 import sys 6 import sys
7 from functools import reduce
7 8
8 if __name__ == "__main__": 9 if __name__ == "__main__":
9 opts, args = getopt.getopt(sys.argv[1:], "e:hm:s") 10 opts, args = getopt.getopt(sys.argv[1:], "e:hm:s")
10 11
11 minlev = None 12 minlev = None
12 exptag = None 13 exptag = None
13 dostats = False 14 dostats = False
14 for o, a in opts: 15 for o, a in opts:
15 if o == "-h": 16 if o == "-h":
16 print """Find data files with certain characteristics 17 print("""Find data files with certain characteristics
17 18
18 %s [-h] [-e exp] [-m min] [-s] file [file ..] 19 %s [-h] [-e exp] [-m min] [-s] file [file ..]
19 exp Limit to experiment tag exp 20 exp Limit to experiment tag exp
20 min Find files with power greater than min 21 min Find files with power greater than min
21 -s Print stats about files 22 -s Print stats about files
22 """ 23 """)
23 elif o == "-e": 24 elif o == "-e":
24 exptag = a 25 exptag = a
25 elif o == "-m": 26 elif o == "-m":
26 minlev = float(a) 27 minlev = float(a)
27 elif o == "-s": 28 elif o == "-s":
28 dostats = True 29 dostats = True
29 else: 30 else:
30 print "Unknown option " + o 31 print("Unknown option " + o)
31 sys.exit(1) 32 sys.exit(1)
32 33
33 if len(args) == 0: 34 if len(args) == 0:
34 print "Need at least one file to analyse" 35 print("Need at least one file to analyse")
35 sys.exit(1) 36 sys.exit(1)
36 37
37 minfiles = [] 38 minfiles = []
38 if dostats: 39 if dostats:
39 print "%-50s %7s %7s %7s (dBm)" % ("Name", "Min", "Mean", "Max") 40 print("%-50s %7s %7s %7s (dBm)" % ("Name", "Min", "Mean", "Max"))
40 for fn in args: 41 for fn in args:
41 dfile = datafile.DataFile(fn) 42 dfile = datafile.DataFile(fn)
42 43
43 if exptag != None and dfile['TAG'] != exptag: 44 if exptag != None and dfile['TAG'] != exptag:
44 continue 45 continue
46 if minlev != None: 47 if minlev != None:
47 if reduce(lambda x, y: x or y, dfile.powers > minlev): 48 if reduce(lambda x, y: x or y, dfile.powers > minlev):
48 minfiles.append(fn) 49 minfiles.append(fn)
49 50
50 if dostats: 51 if dostats:
51 print "%-50s %7.2f %7.2f %7.2f" % (fn, dfile.powers.min(), dfile.powers.mean(), dfile.powers.max()) 52 print("%-50s %7.2f %7.2f %7.2f" % (fn, dfile.powers.min(), dfile.powers.mean(), dfile.powers.max()))
52 53
53 if minlev != None: 54 if minlev != None:
54 if dostats: 55 if dostats:
55 print "" 56 print("")
56 print "Files with any sample exceeding %.2f dBm:" % (minlev) 57 print("Files with any sample exceeding %.2f dBm:" % (minlev))
57 for fn in minfiles: 58 for fn in minfiles:
58 print fn 59 print(fn)
59 60