diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/find.py	Wed Sep 28 12:30:20 2011 +0930
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+
+import datafile
+import getopt
+import numpy
+import sys
+
+if __name__ == "__main__":
+    opts, args = getopt.getopt(sys.argv[1:], "e:hm:s")
+
+    minlev = None
+    exptag = None
+    dostats = False
+    for o, a in opts:
+        if o == "-h":
+            print """Find data files with certain characteristics
+
+%s [-h] [-e exp] [-m min] [-s] file [file ..]
+	exp	Limit to experiment tag exp
+        min	Find files with power greater than min
+        -s	Print stats about files
+"""
+        elif o == "-e":
+            exptag = a
+        elif o == "-m":
+            minlev = float(a)
+        elif o == "-s":
+            dostats = True
+        else:
+            print "Unknown option " + o
+            sys.exit(1)
+            
+    if len(args) == 0:
+        print "Need at least one file to analyse"
+        sys.exit(1)
+
+    minfiles = []
+    if dostats:
+        print "%-50s %7s %7s %7s (dBm)" % ("Name", "Min", "Mean", "Max")
+    for fn in args:
+        dfile = datafile.DataFile(fn)
+
+        if exptag != None and dfile['TAG'] != exptag:
+            continue
+        
+        if minlev != None:
+            if reduce(lambda x, y: x or y, dfile.powers > minlev):
+                minfiles.append(fn)
+
+        if dostats:
+            print "%-50s %7.2f %7.2f %7.2f" % (fn, dfile.powers.min(), dfile.powers.mean(), dfile.powers.max())
+                                               
+    if minlev != None:
+        if dostats:
+            print ""
+        print "Files with any element exceeding %.2f dBm:" % (minlev)
+        for fn in minfiles:
+            print fn
+