Process script for TCS
authorSam Moore <sam@daedalus.(none)>
Mon, 15 Oct 2012 15:06:42 +0000 (23:06 +0800)
committerSam Moore <sam@daedalus.(none)>
Mon, 15 Oct 2012 15:06:42 +0000 (23:06 +0800)
research/TCS/process.py

index 88a536f..46da7c6 100755 (executable)
@@ -52,6 +52,20 @@ def DirectoryName(f, start=0,back=1):
        return string.join(a[start:(len(a)-back)], "/")
 
 def GetData(filename, key=1):
+
+       if type(filename) != type(""):
+               if type(filename) == type([]):
+                       return filename
+               else:
+                       return [[0,0,0,0]]
+       
+
+       if os.path.isdir(filename):
+               if os.path.exists(filename.strip("/")+"/average.dat"):
+                       os.remove(filename.strip("/")+"/average.dat")
+               AverageAllData(filename)
+               return GetData(filename.strip("/")+"/average.dat")
+
        input_file = open(filename, "r")
        data = {}
        for line in input_file:
@@ -77,18 +91,6 @@ def GetData(filename, key=1):
 def DoNothing(data):
        return data
 
-def AverageAllDataSets(directory=".", function=DoNothing):
-       dirs = {}
-       for f in os.listdir(directory):
-               if os.path.isdir(directory+"/"+str(f)) == True:
-                       data_set = []
-                       for datafile in os.listdir(directory+"/"+str(f)):
-                               if datafile.split(".")[1] == "dat":
-                                       data_set.append(GetData(f))
-
-                       avg = Average(data_set)
-                       dirs.update({f : avg})
-       return dirs
 
 def GetDataSets(directory="."):
        data_sets = []
@@ -163,6 +165,9 @@ def MaxNormalise(data, u=2):
        if (len(data) <= 0):
                return result
        maxval = max(data, key = lambda e : e[u])[u]
+       
+       if maxval == 0:
+               return result
 
        for d in result:
                d[u] = d[u] / maxval
@@ -216,11 +221,14 @@ def SaveData(filename, data):
                                out.write("\t")
                out.write("\n")
 
-def AverageAllData(directory, save=None):
+def AverageAllData(directory, save=None, normalise=True):
        data_sets = []
        if save == None: save = directory+"/average.dat"
-       for d in FindDataFiles(directory):
-               data_sets.append(GetData(d))
+       for f in FindDataFiles(directory):
+               d = GetData(f)
+               if normalise:
+                       d = MaxNormalise(d)
+               data_sets.append(d)
        
        a = Average(data_sets)
        SaveData(save, a)
@@ -534,7 +542,7 @@ def main():
                if sys.argv[i] == "--raw":
                        plotFunc = ShowData
                elif sys.argv[i] == "--tcs":
-                       plotFunc = ShowTCS
+                       plotFunc = lambda e : ShowTCS(e, show_peak=False)
                elif sys.argv[i] == "--output":
                        if i+1 >= len(sys.argv):
                                sys.stderr.write("Need argument for "+sys.argv[i]+" switch\n")

UCC git Repository :: git.ucc.asn.au