Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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])
Ejemplo n.º 3
0
    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]))
Ejemplo n.º 4
0
def controlThunk(conn,steptime=120):
    """An infinite loop that controls the insturment and coils"""
    i = Instrument.Instrument()
    password = i.getPassword()
    beamon = True
    coils = Coils.Coils()
    running = False
    flipping = False
    count = 0
    starttime = 0
    command = ones
    generator = command(i,coils,(1,1))
    n = generator.next()
    logging.debug("Starting Main Loop")
    while True:
        if (not running) and (not conn.poll()):
            sleep(0.01)
            continue
        if conn.poll():
            cmd,args=conn.recv()
            if cmd==QUIT:
                if running:
                    i.stop()
                break
            if cmd==START:
                if running:
                    logging.warning("Please stop the current run before starting the next run.")
                else:
                    logging.debug("Creating generator")
                    generator = command(i,coils,args[0])
                    logging.debug("Starting generator")
                    n = generator.next()
                    i.updateRunnumber()
                    manifest = XMLManifest(i.getPath()+"Manifest.xml",
                                           i.getRunnumber())
                    i.start()
                    starttime = clock()
                    ltime = asctime(localtime())
                    logging.debug("Starting running")
                    running = True
            if cmd==STOP:
                (time,monitor_count,detector_count) = i.stop()
                mp = {"subrun":i.subrun} #Manifest Parameters
                mp["time"]=time
                mp["start"]=ltime
                mp["monitor count"]=monitor_count
                mp["monitor file"]=i.getLocalMonitorFile()
                mp["detector count"]=detector_count
                mp["detector file"]=i.getLocalMonitorFile()[:-7]+".pel"
                mp["flipping current"]=coils.getFlipper()
                mp["phase current"]=coils.getPhase()
                mp["guide current"]=coils.getGuides()
                mp["sample current"]=coils.getSample()
                for tri in range(1,9):
                    mp["triangle %d"%tri]=coils.getTriangle(tri)
                manifest.addRun(mp)
                running = False
            if cmd==FLIPPER: coils.flipper(args[0])
            if cmd==GUIDES: coils.guides(args[0])
            if cmd==PHASE: coils.phase(args[0])
            if cmd==SAMPLE: coils.sample(args[0])
            if cmd==TRIANGLE: coils.triangle(args[0],args[1])
            if cmd==SET_PARAM:
                if running:
                    logging.warning("Cannot adjust detector paramters while the instrument is running")
                else:
                    i.setParam(args[0],args[1])
            if cmd==QUERY:
                conn.send(i.query(args[0]))
            if cmd==SET_COMMAND:
                command = args[0]
        if running:
            #if we've run long enough, start a new sub-run
            if clock()-starttime > steptime*n:
                logging.debug("Stopping Instrument")
                (time,monitor_count,detector_count) = i.stop()
                mp = {"subrun":i.subrun} #Manifest Parameters
                mp["time"]=time
                mp["start"]=ltime
                mp["monitor count"]=monitor_count
                mp["monitor file"]=i.getLocalMonitorFile()
                mp["detector count"]=detector_count
                mp["detector file"]=i.getLocalMonitorFile()[:-7]+".pel"
                mp["flipping current"]=coils.getFlipper()
                mp["phase current"]=coils.getPhase()
                mp["guide current"]=coils.getGuides()
                mp["sample current"]=coils.getSample()
                logging.debug("E-mail time")
                if beamon and monitor_count/time < 2.0:
                    mailmessage("LENS is down","I am not recieving many neutrons.  Is the beam off?",password)
                    beamon=False
                elif not beamon and monitor_count/time > 2.0:
                    mailmessage("LENS is up","I am recieving neutrons again.",password)
                    beamon=True    
                for tri in range(1,9):
                    mp["triangle %d"%tri]=coils.getTriangle(tri)
                logging.debug("Update Manifest")
                manifest.addRun(mp)
                ltime = asctime(localtime())
                starttime = clock()
                n=generator.next()
                logging.debug("Starting Instrument")
                i.start()
    del i