X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=research%2FTCS%2Fprocess.py;h=a5f21f0cbbd8f3425b7f3887643c006ec19f1e91;hb=4ac4dae6c58dda0530d237f412241c0ce3f7c1a9;hp=2456d8aead242902f87b41f188025fe6f1dad0a2;hpb=3e2a3e9fd6eef4eea819b9998080d7ab63895a3d;p=matches%2Fhonours.git diff --git a/research/TCS/process.py b/research/TCS/process.py index 2456d8ae..a5f21f0c 100755 --- a/research/TCS/process.py +++ b/research/TCS/process.py @@ -15,9 +15,37 @@ import odict #ordered dictionary import copy import Gnuplot, Gnuplot.funcutils +import string gnuplot = Gnuplot.Gnuplot() +def Reset(): + gnuplot = Gnuplot.Gnuplot() + +def FindDataFiles(directory=".", depth=1, result=None): + if result == None: + result = [] + + for f in os.listdir(directory): + if os.path.isdir(directory+"/"+str(f)): + if depth > 1: + result += FindDataFiles(directory+"/"+str(f), depth-1, result) + continue + s = f.split(".") + if (len(s) == 2 and s[1] == "dat"): + result.append(directory+"/"+str(f)) + + return result + +def BaseName(f): + a = f.split("/") + return a[len(a)-1] + + +def DirectoryName(f, start=0,back=1): + a = f.split("/") + return string.join(a[start:(len(a)-back)], "/") + def GetData(filename): input_file = open(filename, "r") data = [] @@ -109,7 +137,7 @@ def Derivative(data, a=1, b=2, sigma=None,step=1): return result[0:len(result)-1] -def MaxNormalise(data, u=1): +def MaxNormalise(data, u=2): result = copy.deepcopy(data) if (len(data) <= 0): return result @@ -165,21 +193,38 @@ def SaveData(filename, data): out.write(str(a[i])) if (i < len(a) - 1): out.write("\t") - out.write("\n") + out.write("\n") -def CalibrateData(data, ammeter_scale=1e-6): +def AverageAllData(directory, save=None) + data_sets = [] + if save == None: save = directory+"/average.dat": + for d in FindDataFiles(directory): + data_sets.append(GetData(d)) + + a = Average(data_sets) + SaveData(save, a) + return a + +def CalibrateData(original, ammeter_scale=1e-6): + data = copy.deepcopy(original) for i in range(0, len(data)): data[i][1] = 16.8 * float(data[i][1]) / 4000.0 data[i][2] = ammeter_scale * 0.170 * float(data[i][2]) / 268.0 data[i][3] = ammeter_scale * 0.170 * float(data[i][3]) / 268.0 return data -def ShowTCS(filename, calibrate=True, normalise=False, show_error=False, plot=gnuplot.plot,w="lp", step=1): +def ShowTCS(filename, calibrate=True, normalise=False, show_error=False, plot=gnuplot.plot,with_="lp", step=1, output=None, title=""): if type(filename) == type(""): data = GetData(filename) else: data = filename - filename = "data" + filename = "tcs data" + + if (title == ""): + title = BaseName(filename) + + if (len(data) <= 0): + return data if calibrate: data = CalibrateData(data) @@ -193,30 +238,39 @@ def ShowTCS(filename, calibrate=True, normalise=False, show_error=False, plot=gn data = MaxNormalise(data) gnuplot("set ylabel \"dI(E)/dE (normalised)\"") - gnuplot("set title \"S(E)\"") + if (output != None and type(output) == type("")): + gnuplot("set term png size 640,480") + gnuplot("set output \""+str(output)+"\"") + + gnuplot("set title \"Total Current Spectrum S(E)\"") gnuplot("set xlabel \"U ("+str(units[0])+")\"") d = Derivative(data, 1, 2, step=step) - plot(Gnuplot.Data(d, using="2:3", with_=w,title="S(E) : " + str(filename))) + plot(Gnuplot.Data(d, using="2:3", with_=with_,title=title)) if (show_error): error1 = Derivative(data, 1, 2, -3,step=step) error2 = Derivative(data, 1, 2, +3,step=step) - gnuplot.replot(Gnuplot.Data(error1, using="2:3", with_=w,title="Error : Low bound")) - gnuplot.replot(Gnuplot.Data(error2, using="2:3", with_=w, title="Error : Upper bound")) + gnuplot.replot(Gnuplot.Data(error1, using="2:3", with_=w,title="-sigma/2")) + gnuplot.replot(Gnuplot.Data(error2, using="2:3", with_=w, title="+sigma/2")) + if (output != None and type(output) == type("")): + gnuplot("set term wxt") return data -def ShowData(filename,calibrate=True, normalise=False, show_error=False, plot=gnuplot.plot,w="lp", step=1): +def ShowData(filename,calibrate=True, normalise=False, show_error=False, plot=gnuplot.plot,with_="lp", step=1, output=None, title=""): if type(filename) == type(""): data = GetData(filename) else: data = filename - filename = "data" + filename = "raw data" + + if (title == ""): + title = BaseName(filename) if len(data) <= 0: - return + return data if calibrate: data = CalibrateData(data) units = ["V", "uA"] @@ -229,13 +283,17 @@ def ShowData(filename,calibrate=True, normalise=False, show_error=False, plot=gn data = MaxNormalise(data) gnuplot("set ylabel \"I(E) (normalised)\"") - gnuplot("set title \"S(E)\"") + if (output != None and type(output) == type("")): + gnuplot("set term png size 640,480") + gnuplot("set output \""+str(output)+"\"") + + gnuplot("set title \"Sample Current I(E)\"") gnuplot("set xlabel \"U ("+str(units[0])+")\"") #d = Derivative(data, 1, 2, step=step) - plot(Gnuplot.Data(data, using="2:3", with_=w,title="S(E) : " + str(filename))) + plot(Gnuplot.Data(data, using="2:3", with_=with_,title=title)) if (show_error): error1 = copy.deepcopy(data) error2 = copy.deepcopy(data) @@ -245,7 +303,9 @@ def ShowData(filename,calibrate=True, normalise=False, show_error=False, plot=gn error2[i][2] += 0.50*float(data[i][3]) gnuplot.replot(Gnuplot.Data(error1, using="2:3", with_=w,title="Error : Low bound")) gnuplot.replot(Gnuplot.Data(error2, using="2:3", with_=w, title="Error : Upper bound")) - + + if (output != None and type(output) == type("")): + gnuplot("set term wxt") return data def main():