def realTimeExposure(self, protocol, imType, itime, binning=1): """ Inputs are the Evora server protocol, the image type, the integration time, and the binning size. Runs camera in RunTillAbort mode. """ #global acquired retval,width,height = andor.GetDetector() logger.debug('GetDetector: ' + str(retval) + " " + str(width) + " " + str(height)) logger.debug("SetAcquisitionMode: " + str(andor.SetAcquisitionMode(5))) logger.debug('SetReadMode: ' + str(andor.SetReadMode(4))) logger.debug('SetImage: ' + str(andor.SetImage(binning,binning,1,width,1,height))) logger.debug('GetDetector (again): ' + str(andor.GetDetector())) logger.debug('SetExposureTime: ' + str(andor.SetExposureTime(itime))) logger.debug('SetKineticTime: ' + str(andor.SetKineticCycleTime(0))) if(imType == "bias"): andor.SetShutter(1,2,0,0) # TLL mode high, shutter mode Permanently Closed, 0 millisec open/close logger.debug('SetExposureTime: ' + str(andor.SetExposureTime(0))) else: if(imType in ['flat', 'object']): andor.SetShutter(1,0,5,5) else: andor.SetShutter(1,2,0,0) logger.debug('SetExposureTime: ' + str(andor.SetExposureTime(itime))) # TLL mode high, shutter mode Fully Auto, 5 millisec open/close data = np.zeros(width//binning*height//binning, dtype='uint16') logger.debug("SetHSSpeed: " + str(andor.SetHSSpeed(0, 1))) # read time on real is fast because they aren't science images logger.debug('StartAcquisition: ' + str(andor.StartAcquisition())) status = andor.GetStatus() logger.debug(str(status)) workingImNum = 1 start = time.time() end = 0 while(status[1]==andor.DRV_ACQUIRING): progress = andor.GetAcquisitionProgress() currImNum = progress[2] # won't update until an acquisition is done status = andor.GetStatus() if(status[1] == andor.DRV_ACQUIRING and currImNum == workingImNum): logger.debug("Progress: " + str(andor.GetAcquisitionProgress())) results = andor.GetMostRecentImage16(data) # store image data logger.debug(str(results) + 'success={}'.format(results == 20002)) # print if the results were successful if(results == andor.DRV_SUCCESS): # if the array filled store successfully data=data.reshape(width//binning,height//binning) # reshape into image logger.debug(str(data.shape) + " " + str(data.dtype)) hdu = fits.PrimaryHDU(data,do_not_scale_image_data=True,uint=True) #filename = time.strftime('/tmp/image_%Y%m%d_%H%M%S.fits') filename = als.getImagePath('real') hdu.writeto(filename,clobber=True) logger.debug("wrote: {}".format(filename)) data = np.zeros(width//binning*height//binning, dtype='uint16') protocol.sendData("realSent " + filename) workingImNum += 1 end = time.time() logger.debug("Took %f seconds" % (end-start)) start = time.time() return "real 1" # exits with 1 for success
def kseriesExposure(self, protocol, imType, itime, filter="", readTime=3, numexp=1, binning=1, numAccum=1, accumCycleTime=0, kCycleTime=0): """ This handles multiple image acquisition using the camera kinetic series capability. The basic arguements are the passed in protocol, the image type, integration time, filter type, readout index, number of exposures, and binning type. In the future this function could be modified to include accumulations or add time the kinetic cycle time. Accumulations are how many images should be readout as one, and kCycleTime can add time between each exposure that is taken. """ global isAborted isAborted = False retval,width,height = andor.GetDetector() logger.debug('GetDetector: ' + str(retval) + " " + str(width) + " " + str(height)) logger.debug("SetAcquisitionMode: " + str(andor.SetAcquisitionMode(3))) logger.debug('SetReadMode: ' + str(andor.SetReadMode(4))) logger.debug('SetImage: ' + str(andor.SetImage(binning,binning,1,width,1,height))) logger.debug('GetDetector (again): ' + str(andor.GetDetector())) if(imType == "bias"): itime = 0 andor.SetShutter(1,2,0,0) # TLL mode high, shutter mode Permanently Closed, 0 millisec open/close logger.debug('SetExposureTime: ' + str(andor.SetExposureTime(0))) else: if(imType in ['flat', 'object']): andor.SetShutter(1,0,5,5) else: andor.SetShutter(1,2,0,0) logger.debug('SetExposureTime: ' + str(andor.SetExposureTime(itime))) # TLL mode high, shutter mode Fully Auto, 5 millisec open/close logger.debug("SetNumberOfAccumulations: " + str(andor.SetNumberAccumulations(numAccum))) # number of exposures to be combined logger.debug("SetAccumulationTime: " + str(andor.SetAccumulationCycleTime(accumCycleTime))) logger.debug("SetNumberOfKinetics: " + str(andor.SetNumberKinetics(numexp))) # this is the number of exposures the user wants logger.debug('SetKineticTime: ' + str(andor.SetKineticCycleTime(accumCycleTime))) logger.debug("SetTriggerMode: " + str(andor.SetTriggerMode(0))) logger.debug("Timings: " + str(andor.GetAcquisitionTimings())) logger.debug("SetHSSpeed: " + str(andor.SetHSSpeed(0, readTime))) # default readTime is index 3 which is 0.5 MHz or ~6 sec # write headers attributes = [imType, binning, itime, filter] header = self.getHeader(attributes) logger.debug('StartAcquisition: ' + str(andor.StartAcquisition())) status = andor.GetStatus() logger.debug(str(status)) imageAcquired = False counter = 1 while(status[1] == andor.DRV_ACQUIRING): status = andor.GetStatus() progress = andor.GetAcquisitionProgress() runtime = 0 if(progress[2] == counter or (not isAborted and progress[2] == 0 and imageAcquired)): runtime -= time.clock() data = np.zeros(width//binning*height//binning, dtype='uint16') # reserve room for image results = andor.GetMostRecentImage16(data) # store image data logger.debug(str(results) + " " + 'success={}'.format(results == 20002)) # print if the results were successful logger.debug('image number: ' + str(progress[2])) if(results == andor.DRV_SUCCESS): # if the array filled store successfully data=data.reshape(width//binning,height//binning) # reshape into image logger.debug(str(data.shape) + " " + str(data.dtype)) hdu = fits.PrimaryHDU(data,do_not_scale_image_data=True,uint=True, header=header) #filename = time.strftime('/data/forTCC/image_%Y%m%d_%H%M%S.fits') filename = als.getImagePath('series') hdu.writeto(filename,clobber=True) logger.debug("wrote: {}".format(filename)) protocol.sendData("seriesSent"+str(counter)+" "+str(counter)+","+str(itime)+","+filename) # make a new header and write time to it for new exposure. header = self.getHeader(attributes) if(counter == numexp): logger.info("entered abort") isAborted = True imageAcquired = True counter += 1 runtime += time.clock() logger.debug("Took %f seconds to write." % runtime) return "series 1,"+str(counter) # exits with 1 for success
def expose(self, imType=None, expnum=None, itime=2, binning=1, filter="", readTime=3): """ expNum is deprecated and should be removed. This handles a single exposure and no more. Inputs are the image type integration time, binning type filter type, as a string, and the index for the specified horizontal readout time. """ if expnum is None: self.num += 1 expnum = self.num else: self.num = expnum if imType is None: # if the image type is not specified it defaults to object imType = "object" retval, width, height = andor.GetDetector() logger.debug('GetDetector: ' + str(retval) + " " + str(width) + " " + str(height)) # print 'SetImage:', andor.SetImage(1,1,1,width,1,height) logger.debug('SetReadMode: ' + str(andor.SetReadMode(4))) logger.debug('SetAcquisitionMode: ' + str(andor.SetAcquisitionMode(1))) logger.debug('SetImage: ' + str(andor.SetImage(binning,binning,1,width,1,height))) logger.debug('GetDetector (again): ' + str(andor.GetDetector())) if(imType == "bias"): andor.SetShutter(1,2,0,0) # TLL mode high, shutter mode Permanently Closed, 0 millisec open/close logger.debug('SetExposureTime: ' + str(andor.SetExposureTime(0))) else: if(imType in ['flat', 'object']): andor.SetShutter(1,0,5,5) else: andor.SetShutter(1,2,0,0) logger.debug('SetExposureTime: ' + str(andor.SetExposureTime(itime))) # TLL mode high, shutter mode Fully Auto, 5 millisec open/close # set Readout speeds 0, 1, 2, or 3 #print("SetVSSpeed:", andor.SetVSSpeed(3)) logger.debug("SetHSSpeed: " + str(andor.SetHSSpeed(0, readTime))) # default readTime is index 3 which is 0.5 MHz or ~6 sec results, expTime, accTime, kTime = andor.GetAcquisitionTimings() logger.debug("Adjusted Exposure Time: " + str([results, expTime, accTime, kTime])) attributes = [imType, binning, itime, filter] header = self.getHeader(attributes) logger.debug('StartAcquisition: ' + str(andor.StartAcquisition())) status = andor.GetStatus() logger.debug(str(status)) while status[1] == andor.DRV_ACQUIRING: status = andor.GetStatus() data = np.zeros(width//binning*height//binning, dtype='uint16') logger.debug(str(data.shape)) result = andor.GetAcquiredData16(data) success = None if(result == 20002): success = 1 # for true else: success = 0 # for false logger.debug(str(result) + 'success={}'.format(result == 20002)) filename = None if success == 1: data=data.reshape(width//binning,height//binning) logger.debug(str(data.shape) + " " + str(data.dtype)) hdu = fits.PrimaryHDU(data,do_not_scale_image_data=True,uint=True, header=header) #filename = time.strftime('/data/forTCC/image_%Y%m%d_%H%M%S.fits') filename = als.getImagePath('expose') hdu.writeto(filename,clobber=True) logger.debug("wrote: {}".format(filename)) return "expose " + str(success) + ","+str(filename) + "," + str(itime)