def frameSaving(mmc, tiffWriterList, nbImages, maxFrames, window, app, exit): "In charge of saving frames and actualize the GUI" imageCount = 0 mmc.startContinuousSequenceAcquisition(1) while (imageCount < (nbImages) and not exit.is_set()): if mmc.getRemainingImageCount( ) > 0: #Returns number of image in circular buffer, stop when seq acq finished #Enter this loop BETWEEN acquisition #trigImage(labjack) #Generate a pulse, which allows to flag the entry in this code statement with the oscilloscope img = mmc.popNextImage( ) #Gets and removes the next image from the circular buffer ##read input from labjack saveFrame(img, tiffWriterList, (imageCount), maxFrames) # saving frame of previous acquisition imageCount += 1 ##UPDATE of the GUI window.progressBar.setValue( imageCount) #Update the gui of evolution of the acquisition # if (imageCount % 10) == 0: ##Process events in the Queue each 10 frames # app.processEvents() #Keep the GUI responsive even while this fct is executing # print 'processEvents im num : ',imageCount #Close tiff file open tiffWritersClose(tiffWriterList) #Stop camera acquisition mmc.stopSequenceAcquisition() mmc.clearCircularBuffer() return imageCount
def _circularBufferCleaning(self, imageCount): """ Get the last images in the circular buffer if the acquisition was aborted. This step ensure that there is the same amount of metadata than frames saved. """ if (not self.acqRunning) or ( not self.loopRunning ): #Check if sequence acquisition was aborted or loop was paused. print('cycleTime :', self.cycleTime) sleep(self.cycleTime) print('remaining images in the circular buffer :', self.mmc.getRemainingImageCount()) while (self.mmc.getRemainingImageCount() > 0): print 'getting last image, num : ', imageCount img = self.mmc.popNextImage( ) #Gets and removes the next image from the circular buffer saveFrame( img, self.tiffWriterList, (imageCount), self.maxFrames) # saving frame of previous acquisition imageCount += 1 sleep(self.cycleTime) #Close tiff file open tiffWritersClose(self.tiffWriterList) if ((self.nbFrames / self.maxFrames) >= 1): #check that multiples .tif were initialized # --> CHECK WICH .tif are empty and suppress it if self.stimName: emptyTiffDel(self.stimName, self.savePath, imageCount, self.maxFrames, self.tiffWriterList) else: emptyTiffDel(self.experimentName, self.savePath, imageCount, self.maxFrames, self.tiffWriterList)
def _frameSaving(self): """ In charge of saving frames """ self.mmc.clearCircularBuffer() imageCount = 0 self.mmc.startContinuousSequenceAcquisition(1) while (imageCount < (self.nbFrames) and self.acqRunning and self.loopRunning): if self.mmc.getRemainingImageCount( ) > 0: #Returns number of image in circular buffer, stop when seq acq finished #Enter this loop BETWEEN acquisition #trigImage(labjack) #Generate a pulse, which allows to flag the entry in this code statement with the oscilloscope img = self.mmc.popNextImage( ) #Gets and removes the next image from the circular buffer saveFrame( img, self.tiffWriterList, (imageCount), self.maxFrames) # saving frame of previous acquisition imageCount += 1 self.progressSig.emit(imageCount) #Stop camera acquisition #Ensure that no more frames are taken self.mmc.stopSequenceAcquisition() #### IF ABORTED acquisition ##### self._circularBufferCleaning(imageCount) #Close tiff file open tiffWritersClose(self.tiffWriterList) print 'end of the _frameSavingThread' return imageCount
def sequenceAcqCamTrig(mmc, nbImages, maxFrames, intervalMs, deviceLabel, ledList, tiffWriterList, textFile, labjack, window, app, exit): "Prepare and start the sequence acquisition. Write frame in an tiff file during acquisition. LED triggered by camera output" readOutFrame = 10 #ms ##Minimal time between 2 frames (cf page 45 zyla hardware guide) #Get the time ##TO FIX : is it the right place to put it on ? timeStamps = [] #timeStamps.append(time()) #Useless to have a timestamp here #exp = mmc.getProperty(deviceLabel,'Exposure') print "Interval between images : ", (intervalMs + readOutFrame), "ms" print "Nb of frames : ", nbImages imageCount = 0 #mmc.prepareSequenceAcquisition(deviceLabel) #mmc.startSequenceAcquisition(nbImages, intervalMs, False) #numImages Number of images requested from the camera #intervalMs The interval between images, currently only supported by Andor cameras #stopOnOverflow whether or not the camera stops acquiring when the circular buffer is full mmc.startContinuousSequenceAcquisition(intervalMs + readOutFrame) timeStamps.append(time()) while ( imageCount < (nbImages) and not exit.is_set() ): #Loop stops if we have the number of frames wanted OR if abort button is press (see abortFunc) #sleep(0.001*(intervalMs-10)) #Delay in seconds, can be closed to intervalMs to limit loops for nothing #Launching acquisition if mmc.getRemainingImageCount( ) > 0: #Returns number of image in circular buffer, stop when seq acq finished #Enter this loop BETWEEN acquisition #trigImage(labjack) imageCount += 1 img = mmc.popNextImage( ) #Gets and removes the next image from the circular buffer timeStamps.append(time()) saveFrame(img, tiffWriterList, (imageCount - 1), maxFrames) # saving frame of previous acquisition window.progressBar.setValue( imageCount) #Update the gui of evolution of the acquisition app.processEvents( ) #Allows the GUI to be responsive even while this fct is executing /!\ check time affection of this skills #Print the real interval between images ## Can be done in post-processing with timeStamps for i in range(0, len(timeStamps) - 1): print "delta time between t", i + 1, " and t", i, " : ", ( timeStamps[i + 1] - timeStamps[i]) #Close tiff file open tiffWritersClose(tiffWriterList) #Stop camera acquisition mmc.stopSequenceAcquisition() mmc.clearCircularBuffer() return imageCount
def run(self): self.isStarted.emit() #Launching the frame acquisition # if self.acquMode == "Labjack": # print'sequ acq about to start' # self.imageCount = self._sequenceAcqu() # print'run fct done' if self.acquMode == "Run": #self.arduinoSync() self.imageCount = self._seqAcqCyclops() elif self.acquMode == "Loop": interruptAIN = 1 stopSignalState = False waitToCheckSignal = 0.5 #Instanciate a SignalInterrupt object to listen to the labjack and the moment when SYNC signal goes low self.stopInterrupt = SignalInterrupt(self.labjack, interruptAIN, waitToCheckSignal, stopSignalState) self.stopInterrupt.stateReachedInterrupt.connect(self.pauseLoop) self.stopInterrupt.start() stimNumber = 1 self.startAcquisitionTime = time() print 'start acquisition time :', self.startAcquisitionTime while (self.acqRunning): print 'Stimulation nb ', stimNumber self._loopPreparation(stimNumber) #Wait for the raise of the SYNC signal #if waitForSignal(self.labjack, channel=1): #waitForSignal(device, signalType="TTL", channelType="AIN", channel=1) while (not risingEdge(self.labjack, interruptAIN)) and self.acqRunning: continue if self.acqRunning: self.loopRunning = True self.imageCount = self._seqAcqCyclops() print self.imageCount stimNumber += 1 else: #Close tiff file open tiffWritersClose(self.tiffWriterList) #close the metadata .txt file self.textFile.close() saveFcts.acqFilesDel(self.stimName, self.savePath) print 'abort loop' self.stopInterrupt.abort( ) #Stop the listenning action of the Interrupt else: print 'Please select a valid mode of triggering the LED' print 'end of the thread' self.isFinished.emit()
def saveImageSeqThreads(self): name = window.name.text() ## get Name from text area duration = self.dur.value()*1000 ## get duration from spinbox and converted it in ms ledRatio = [self.rRatio.value(),self.gRatio.value(),self.bRatio.value()] # [r,g,b]## get LED ratio maxFrames = int(self.framesPerFileLabel.text()) expRatio =self.expRatio.value() #intervalMs = 0 ## TO remove from every code file #If abort button was hit, enable execution again, and exit.is_set() will return False (cf sequAcq fct) exit.clear() #Initialise sequence acqu (ledList, nbFrames) = sequenceInit(duration, ledRatio, int(float(mmc.getProperty(DEVICE[0], 'Exposure')))) #Initialize progressBar window.progressBar.setMaximum(nbFrames) #Initialize tiffWriter object (tiffWriterList, textFile,savePath) = filesInit(name, nbFrames, maxFrames) pool = ThreadPool(processes=2) async_result1 = pool.apply_async(sequenceAcqLabjackTrig, (mmc, nbFrames, maxFrames, expRatio, DEVICE[0], ledList, tiffWriterList, textFile, labjack, window, app, exit,)) async_result2 = pool.apply_async(guiUpdating, (self.dur.value(), app, exit,)) # do some other stuff in the main process imageCount = async_result1.get() # get the return value from your function. print imageCount #close the pool and wait for the work to finish pool.close() pool.join() print 'execution done' #print 'Labjack trig cam fct' #imageCount = sequenceAcqLabjackTrig(mmc, nbFrames, maxFrames, expRatio, DEVICE[0], ledList, tiffWriterList, textFile, labjack, window, app, exit) ##### IF ABORTED acquisition --> CHECK WICH .tif are empty and suppress it ##### if exit.is_set() and ((nbFrames/maxFrames)>=1): #check if abort fct was called and that multiples .tif were initialized tiffWriterDel(name, savePath, imageCount, maxFrames, tiffWriterList) #Closing all files opened textFile.close() tiffWritersClose(tiffWriterList) print 'Acquisition done' window.progressBar.setValue(0)
def saveImageSeq(self): name = self.name.text() ## get Name from text area duration = self.dur.value()*1000 ## get duration from spinbox and converted it in ms ledRatio = [self.rRatio.value(),self.gRatio.value(),self.bRatio.value()] # [r,g,b]## get LED ratio maxFrames = int(self.framesPerFileLabel.text()) expRatio =self.expRatio.value() intervalMs = 0 ## TO remove from every code file #If abort button was hit, enable execution again, and exit.is_set() will return False (cf sequAcq fct) exit.clear() #Initialise sequence acqu (ledList, nbFrames) = sequenceInit(duration, ledRatio, int(float(mmc.getProperty(DEVICE[0], 'Exposure')))) #Initialize progressBar window.progressBar.setMaximum(nbFrames) #Initialize tiffWriter object (tiffWriterList, textFile,savePath) = filesInit(name, nbFrames, maxFrames) if self.ledTrigBox.currentText() == 'Software' : #Launch seq acq : carries the images acquisition AND saving imageCount = sequenceAcqSoftTrig(mmc, nbFrames, maxFrames, intervalMs, DEVICE[0], ledList, tiffWriterList, textFile,labjack,window, app, exit) elif self.ledTrigBox.currentText() == 'Camera' : print 'LED camera trigger function' imageCount = sequenceAcqCamTrig(mmc, nbFrames, maxFrames, intervalMs, DEVICE[0], ledList, tiffWriterList, textFile,labjack,window, app, exit) elif self.ledTrigBox.currentText() == 'Labjack - Cyclops mode': print 'Labjack trig cam fct' imageCount = sequenceAcqLabjackTrig(mmc, nbFrames, maxFrames, expRatio, DEVICE[0], ledList, tiffWriterList, textFile, labjack, window, app, exit) else: print 'Labjack trig custom fct' imageCount = sequenceAcqLabjackTrig2(mmc, nbFrames, maxFrames, expRatio, DEVICE[0], ledList, tiffWriterList, textFile, labjack, window, app, exit) ##### IF ABORTED acquisition --> CHECK WICH .tif are empty and suppress it ##### if exit.is_set() and ((nbFrames/maxFrames)>=1): #check if abort fct was called and that multiples .tif were initialized tiffWriterDel(name, savePath, imageCount, maxFrames, tiffWriterList) #Closing all files opened textFile.close() tiffWritersClose(tiffWriterList) print 'Acquisition done' window.progressBar.setValue(0)
def sequenceAcqSoftTrig(mmc, nbImages, maxFrames, intervalMs, deviceLabel, ledList, tiffWriterList, textFile, labjack, window, app, exit): "Prepare and start the sequence acquisition. Write frame in an tiff file during acquisition." readOutFrame = 10 #ms ##Minimal time between 2 frames (cf page 45 zyla hardware guide) #Get the time ##TO FIX : is it the right place to put it on ? timeStamps = [] #timeStamps.append(time()) #Useless to have a timestamp here #exp = mmc.getProperty(deviceLabel,'Exposure') print "Interval between images : ", (intervalMs + readOutFrame), "ms" print "Nb of frames : ", nbImages imageCount = 0 #Initialize the good LED for first image if ledList[imageCount] == 'r': #print "Blue off" greenOff(labjack) redOn(labjack) elif ledList[imageCount] == 'g': redOff(labjack) greenOn(labjack) else: redOff(labjack) greenOff(labjack) #mmc.prepareSequenceAcquisition(deviceLabel) #mmc.startSequenceAcquisition(nbImages, intervalMs, False) #numImages Number of images requested from the camera #intervalMs The interval between images, currently only supported by Andor cameras #stopOnOverflow whether or not the camera stops acquiring when the circular buffer is full mmc.startContinuousSequenceAcquisition(intervalMs + readOutFrame) timeStamps.append(time()) while ( imageCount < (nbImages) and not exit.is_set() ): #Loop stops if we have the number of frames wanted OR if abort button is press (see abortFunc) #Launching acquisition if mmc.getRemainingImageCount( ) > 0: #Returns number of image in circular buffer, stop when seq acq finished #Enter this loop BETWEEN acquisition #trigImage(labjack) #Generate a pulse, which allows to flag the entry in this code statement with the oscilloscope imageCount += 1 #Lighting good LED for next acquisition if ledList[imageCount] == 'r': #print "Blue off" greenOff(labjack) redOn(labjack) elif ledList[imageCount] == 'g': redOff(labjack) greenOn(labjack) else: redOff(labjack) greenOff(labjack) #sleep(0.005) #Wait 5ms to ensure LEDS are on img = mmc.popNextImage( ) #Gets and removes the next image from the circular buffer t = time() timeStamps.append(t) ##read input from labjack saveMetadata(textFile, str(t), ledList[(imageCount - 1)], str(imageCount - 1)) saveFrame(img, tiffWriterList, (imageCount - 1), maxFrames) # saving frame of previous acquisition window.progressBar.setValue( imageCount) #Update the gui with evolution of the acquisition app.processEvents( ) #Keep the GUI responsive even while this fct is executing #Turning off all LEDS greenOff(labjack) redOff(labjack) #Print the real interval between images ## Can be done in post-processing with timeStamps for i in range(0, len(timeStamps) - 1): print "delta time between t", i + 1, " and t", i, " : ", ( timeStamps[i + 1] - timeStamps[i]) #Close tiff file open tiffWritersClose(tiffWriterList) #Stop camera acquisition mmc.stopSequenceAcquisition() mmc.clearCircularBuffer() return imageCount