def load(paths): currents = set([])#List of the configurations of the instrument runsets = {}#Directionary of lists of run nodes, indexed by their instrument configuration for path in paths: base = os.path.dirname(path) manifest = XMLManifest(path,0) subruns = manifest.getRuns(base) for subrun in subruns: triangles = sorted(subrun.findall('Triangle'), key=lambda x: x.get('number')) current = (subrun.find('Flipper').text.strip(), subrun.find('GuideFields').text.strip(), subrun.find('PhaseCoil').text.strip(), subrun.find('SampleCoil').text.strip(), triangles[0].text.strip(), triangles[1].text.strip(), triangles[2].text.strip(), triangles[3].text.strip(), triangles[4].text.strip(), triangles[5].text.strip(), triangles[6].text.strip(), triangles[7].text.strip()) subrun.set("Base",base) if current in currents: runsets[current].append(subrun) else: currents.add(current) runsets[current]=[subrun] return runsets
def history_load(path): base = os.path.dirname(basedir+"%04i/Manifest.xml"%path) manifest = XMLManifest(basedir+"%04i/Manifest.xml"%path,0) subruns = manifest.getRuns(base) counts = np.array([(float(subrun.find('Monitor').get('count'))/ float(subrun.get('time'))) for subrun in subruns]) errs = np.array([np.sqrt(float(subrun.find('Monitor').get('count'))/ float(subrun.get('time'))) for subrun in subruns]) plt.hist(counts,bins=50)#[0,1,26,27,28,29,30,31,32,33,34,35,36,37,38,50]) plt.show() good = [x for x in counts if x >= 26 and x <=38] print np.mean(good) print np.std(good) print np.mean(errs[counts >= 20])
def onSave(self,event): """Split the data runs and save them to the disk""" run = int(self.runnumber.GetValue()) directory = path+"%i/"%run m = XMLManifest(directory+"Manifest.xml",0) subruns = m.getRuns(directory) cutoff = int(self.time.GetValue()) sets = partition(subruns,cutoff) print "Save!" for s,i in zip(sets,range(len(sets))): tottime = 0 with open(directory+"Combined_%i_%i.pel"%(run,i),"wb") as outfile: head = np.fromfile(directory+s[0].find("Detector").get("path"),dtype=np.int8,count=256) head.tofile(outfile) mon = np.zeros((1001,),dtype=np.int32) for subrun in s: tottime += float(subrun.get("time")) with open(directory+subrun.find("Detector").get("path"),"rb") as infile: infile.seek(256) temp = np.fromfile(infile,count=-1) temp.tofile(outfile) with open(directory+subrun.find("Monitor").get("path"),"rb") as infile: montemp = np.loadtxt(infile,dtype=np.int32,skiprows=3) montemp = np.resize(montemp,(1001,2)) mon += montemp[:,1] with open(directory+"Combined_%i_%i.txt"%(run,i),"w") as outmon: outmon.write("File Saved for Run Number "+str(run)+"_"+str(i)+".\n") outmon.write("This run had %d counts " % np.sum(mon)) outmon.write("and lasted %d milliseconds\n" % (float(tottime)*1000)) outmon.write("User Name=Unkown, Proposal Number=Unknown\n") for i in range(0,1000): outmon.write("%d\t%d\n"%(i+1,mon[i]))