Пример #1
0
    def stop_rfpower(self):
        print('stop rf pwoer ')

        self.flag_rfpower = False
        time.sleep(1)
        stop_thread(self.sub_rfpower_thread)
        self.timer_rfpower.stop()
Пример #2
0
    def stop_gassupply(self):
        print('stop gas supply ')

        self.flag_gassupply = False
        time.sleep(1)
        stop_thread(self.sub_gassupply_thread)
        self.timer_gassupply.stop()
Пример #3
0
    def stop_water(self):
        print('stop water')

        self.flag_water = False
        time.sleep(1)
        stop_thread(self.sub_water_thread)
        self.timer_water.stop()
    def stop_pgpower(self):
        print('stop pgpower ')

        self.flag_pgpower = False
        time.sleep(1)
        stop_thread(self.sub_pgpower_thread)
        self.timer_pgpower.stop()
Пример #5
0
    def stop_egpower(self):
        print('stop egpower ')

        self.flag_egpowerhs1_2 = False
        self.flag_egpowerhs2_3_4 = False
        self.flag_egpowerhs3_5 = False
        time.sleep(1)
        stop_thread(self.sub_egpowerhs1_2_thread)
        stop_thread(self.sub_egpowerhs2_3_4_thread)
        stop_thread(self.sub_egpowerhs3_5_thread)
        self.timer_egpower.stop()
    def stop_total(self):
        print('stop gas supply ')

        self.flag_total = False
        time.sleep(1)
        stop_thread(self.sub_gassupply_thread)
        stop_thread(self.sub_rfpower_thread)
        stop_thread(self.sub_pgpower_thread)
        stop_thread(self.sub_egpowerhs1_1_2_thread)
        stop_thread(self.sub_egpowerhs3_6)

        self.timer_total.stop()
Пример #7
0
def runEpoch(mmc,device,rep):
    import time
    
    global epoch_seq #epochs items as list (name,exp,led,odor,duration,noRec)
    global meta_index # list: epoch name, start frame, end frame
    
    namep=window.path.text()
    print "create hdf5" 
    hdfpath = createHdf5andClose(namep,savepath)
    
    
    n_epoch=len(epoch_seq)
    total =0
    epoch_times =[]
    
    eps = 0.005 #delay... error in time passed
    lj_delay = 0#0.012
    count = 1 #epoch 0 effectuated before loop
    m=0 #tiff saving index
    namep=window.path.text()
    print "namep..."+str(namep)

    window.progressBar.setMinimum(0)
    
    window.progressBar.setMaximum(n_epoch+(rep-1)*n_epoch)

    print str(n_epoch)
    for i in range(n_epoch):
        total += epoch_seq[i][4]
        epoch_times.append(total)
    print str(n_epoch)+" epochs"
    print "should take "+str(total)+"s and repeated "+str(rep)+" time(s)"

    mmc.prepareSequenceAcquisition('Zyla')
    #print "preparing sequence acquisition took", time.clock()-start, "seconds"                                         
    
#    cv2.namedWindow('Video')
    
    text_file_globalTime = open(savepath+"/globalTime"+namep+".txt", 'w')
    #text_file_globalTime.write(str(time.clock()-start)+",  "+ser.readline()+"\n")
    
    
    for i in range(rep): #LOOP FOR TRIALS
            print "trial "+str(i+1)
            text_file = open(savepath+"/respi"+namep+"_trial_"+str(i+1)+".txt", 'w')
            text_file_globalTime.write( str(time.time())+",  "+str(i+1)+"\n")
            frame_i=0
                         
            #mmc.setProperty(DEVICE[0], 'Exposure', epoch_seq[0][1])
            setLed(device,epoch_seq[0][2])
            setOdor(device,epoch_seq[0][3])
            mmc.initializeCircularBuffer()                          
            mmc.startContinuousSequenceAcquisition(10)
            
            start=time.clock()  

            while time.clock()-start < total:
                if  mmc.getRemainingImageCount()>0 :
                    im = mmc.popNextImage()
                    #im = mmc.getLastImage()
                    #cv2.imshow('Video', im)  
                    #raw_input("pause")   
                    frames.append(im)
                    timestamps.append(time.clock()-start) #0.6s from start !!!
                    meta.append( (epoch_seq[count-1], i)) 
                
                if  (count < n_epoch) and (time.clock()-start+eps > epoch_times[count-1]) :
                    print "count "+str(count)
                    print epoch_seq[count-1][0]

                    print frame_i
                    print len(frames)-1
                    #mmc.setProperty(DEVICE[0], 'Exposure', epoch_seq[count][1])
                    setLed(device,epoch_seq[count][2])
                    setOdor(device,epoch_seq[count][3])
                    window.progressBar.setValue(count+i*n_epoch)
                    
#                 #saving index of previous epoch (name,start frame, end frame)
#                    frame_f=len(frames)-1
#                    meta_index.append((epoch_seq[count-1][0],frame_i,frame_f))
#                    frame_i=len(frames)
                    
                    if epoch_seq[count-1][5] == 0 :
                        frame_f=len(frames)-1
                        meta_index.append((epoch_seq[count-1][0],frame_i,frame_f))
                        frame_i=len(frames)
#                        nrec = 0
#                        mmc.stopSequenceAcquisition()
#                        mmc.clearCircularBuffer() 
                    if (epoch_seq[count][5] == 1):
                        print "stop recording "+str(epoch_seq[count][4])+ "sec"
                        time.sleep(epoch_seq[count][4])
                        mmc.clearCircularBuffer()
                        #meta_index.pop()

#                        if epoch_seq[count-1][5] == 1:
#                            mmc.initializeCircularBuffer()   
#                            mmc.startContinuousSequenceAcquisition(10)
#                            nrec=1                    
                    count += 1
                if ser.inWaiting() :
                            text_file.write(str(time.clock()-start)+",  "+ser.readline()+"\n")
#                if cv2.waitKey(1) >= 0:
#                    break
            frame_f=len(frames)-1
            meta_index.append((epoch_seq[count-1][0],frame_i,frame_f))
            frame_i=len(frames)
            
            m_i_trial.append(meta_index)
            meta_index=[]
            
            window.progressBar.setValue(n_epoch+i*n_epoch)
            #reset
            device.setFIOState(green_lj, 0)
            device.setFIOState(red_lj, 1)
            #device.setFIOState(v1_lj, 0)
            #device.setFIOState(v2_lj, 0)
            DAC0_VALUE = device.voltageToDACBits(0, dacNumber = 0, is16Bits = False)
            device.getFeedback(u3.DAC0_8(DAC0_VALUE))        
            DAC1_VALUE = device.voltageToDACBits(0, dacNumber = 1, is16Bits = False)
            device.getFeedback(u3.DAC1_8(DAC1_VALUE))       
                      
            print str(total)+"s acquisition took", time.clock()-start, "seconds"
            
            mmc.stopSequenceAcquisition()
            mmc.clearCircularBuffer() 
            if i < rep: #end of an epoch
                    #time spent savong files
                    savingTime=time.time()
                    #print "saving tiff.."+str(len(frames))+" frames"
                    #namep=window.path.text()
                    framesnp = np.asarray(frames)
                    
                    #display avg green
                    print "save green"+str(i)+" in "+savepath
                    scipy.misc.imsave(savepath+'/green'+str(i)+'.jpg', np.mean(framesnp[0:20],axis=0))
                    #plt.imshow(np.mean(framesnp[0:20],axis=0))
                    
                    #saveAsMultipageTif(framesnp,savepath,namep,meta,k=512)#
                    #m = saveAsMultipageTif_inter(framesnp,savepath,namep,m)
                    #print "number of tiff files :"+str(m)
                    print "save trial hdf5"
                    print m_i_trial[-1]
                    print i+1
                    hdfs=saveTrialHdf5andClose(hdfpath,framesnp,m_i_trial[-1],i+1,epoch_seq) #modified added epoch
                    print "closing hdfs"
                    hdfs.close()
                    print "closed"
                    #print "save respiratory signal"
                    # text_file = open("respi"+".txt", 'w')
                    print "empty frames list.."
                    frames[:]=[]
                    text_file.close()
                    timeSpentSaving=time.time()-savingTime
                    newDelay=window.dur_2.value()-timeSpentSaving
                    print "in total wating for "+str(window.dur_2.value())+" s"
                    print "after time spent saving wating for "+str(newDelay)+" s"
                    if (newDelay>0):
                        time.sleep(newDelay)
            count =1
    
    #cv2.destroyAllWindows()
                                

    
    #print "nOfFrames :"+str(len(frames)) 
    print "exposure was", mmc.getProperty('Zyla','Exposure')                                               
    print "Framerate was", mmc.getProperty('Zyla','FrameRate')             
    print "saving metadata, timestamps and comments"
    
    if not os.path.exists(savepath+"/"+namep):
        os.makedirs(savepath+"/"+namep)
    
    with open(savepath+"/"+namep+"/epoch.p", "wb") as fp:   #Pickling
        pickle.dump(epoch_seq, fp)
    with open(savepath+"/"+namep+"/comment.p", "wb") as fpp:   #Pickling
        pickle.dump(window.comment.toPlainText(), fpp)
    with open(savepath+"/"+namep+"/timestamps.p", "wb") as fppp:   #Pickling
        pickle.dump(timestamps, fppp)
    with open(savepath+"/"+namep+"/meta.p", "wb") as fppp:   #Pickling
        pickle.dump(meta, fppp)
    with open(savepath+"/"+namep+"/m_i_trial.p", "wb") as fppp:   #Pickling
        pickle.dump(m_i_trial, fppp)

    print "restart kernel to be safe"
    
    text_file_globalTime.close()
    print "global time txt closed"

    
    window.progressBar.setValue(0)       
import sys

data = [0]
ser = serial.Serial("COM4", 9600, timeout=0.5)
t = [0]

start_time = time.time()
time2 = []
while time.time() - start_time < 3:
    line = ser.readline()
    print('data: ', float(line))

# Calibration
print('Beginning calibration')
print('Please make your arm straight for 3 seconds...')
time.sleep(3)
ser.reset_input_buffer()
ser.reset_output_buffer()
arm_straight = float(ser.readline())  # Voltage for ~180 degrees
print('Done')

print('Please bend your arm for 3 seconds...')
time.sleep(3)
ser.reset_input_buffer()
ser.reset_output_buffer()
arm_bent = float(ser.readline())  # Voltage for 45 degrees
print('Done')

print(arm_straight, arm_bent)

ser.reset_input_buffer()