5 # @purpose Process TCS data
13 import re # Regular expressions - for removing comments
14 import odict #ordered dictionary
16 import Gnuplot, Gnuplot.funcutils
18 gnuplot = Gnuplot.Gnuplot()
20 def GetData(filename):
21 input_file = open(filename, "r")
23 for line in input_file:
24 line = re.sub("#.*", "", line).strip("\r\n ")
27 data.append(map(lambda e : float(e), line.split("\t")))
35 for i in range(1, len(data)-1):
36 dE = data[i+1][1] - data[i][1]
42 dI += data[i+1][2] - data[i][2]
44 result.append([data[i][1], (dI / (n * dE)) ] ) #/ data[i][2]])
55 if (len(sys.argv) < 2):
56 sys.stderr.write(sys.argv[0] + " - Require arguments (filename)\n")
60 gnuplot("set style data lp")
61 gnuplot("set key outside right")
62 #gnuplot("set title \"Au on Si (50min 3.5A 3-6 e-8mbar)\"")
63 #gnuplot("set xlabel \"E (DAC Counts)\"")
64 #gnuplot("set ylabel \"S(E) (ADC/DAC Counts)\"")
65 #gnuplot("set term postscript colour")
66 #gnuplot("set output \"test.eps\"")
67 for i in range(1, len(sys.argv)):
68 tcs.append(map(lambda e : [e[1], e[2]], GetData(sys.argv[i])))
69 #tcs.append(GetTCS(GetData(sys.argv[i])))
70 if (len(tcs[i-1]) > 0):
71 gnuplot.replot(Gnuplot.Data(tcs[i-1], title="", with_="lp"))
73 # Now average the data
82 avg.update({p[0] : [p[1], 1]})
85 avg[a] = float(avg[a][0]) / float(avg[a][1])
88 gnuplot.replot(Gnuplot.Data(sorted(avg.items(), key = lambda e : e[0]), title="Average", with_="l lw 2"))
90 sys.stdout.write("Save averaged data as (blank for no save): ")
91 filename = sys.stdin.readline().strip(" \r\n\t")
93 out = open(filename, "w", 0)
94 for a in sorted(avg.items(), key = lambda e : e[0]):
95 out.write(str(a[0]) + "\t" + str(a[1]) + "\n")
100 if __name__ == "__main__":