def startup(self): """ 20002 is the magic number. Any different number and it didn't work. """ logger.debug(str(andor.GetAvailableCameras())) camHandle = andor.GetCameraHandle(0) logger.debug(str(camHandle)) logger.debug('set camera: ' + str(andor.SetCurrentCamera(camHandle[1]))) init = andor.Initialize("/usr/local/etc/andor") logger.debug('Init: ' + str(init)) state = andor.GetStatus() logger.debug('Status: ' + str(state)) logger.debug('SetAcquisitionMode: ' + str(andor.SetAcquisitionMode(1))) logger.debug('SetShutter: ' + str(andor.SetShutter(1, 0, 50, 50))) # make sure cooling is off when it first starts logger.debug('SetTemperature: ' + str(andor.SetTemperature(0))) logger.debug('SetFan ' + str(andor.SetFanMode(0))) logger.debug('SetCooler ' + str(andor.CoolerOFF())) return "connect " + str(init)
def getStatus(self): """ No input needed. Returns an integer value representing the camera status. E.g. 20075 means the camera is uninitialized. """ # if the first status[0] is 20075 then the camera is not initialized yet and # one needs to run the startup method. status = andor.GetStatus() return "status " + str(status[0]) + "," + str(status[1])
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) header = self.getHeader_2(attributes, 'heimdall') 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 = fits_utils.get_image_path('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) header = self.getHeader_2(attributes, 'heimdall') 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 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 = fits_utils.get_image_path('real') hdu.writeto(filename, clobber=True) logger.debug("wrote: {}".format(filename)) data = np.zeros(width // binning * height // binning, dtype='uint16') protocol.sendData("realSent %s" % filename) # print("Sending", "realSent%d" % (workingImNum)) workingImNum += 1 end = time.time() logger.debug("Took %f seconds" % (end - start)) start = time.time() return "real 1" # 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. """ elapse_time = 0 - time.clock() 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) header = self.getHeader_2(attributes, 'heimdall') 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) #data = np.fliplr(data) 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 = fits_utils.get_image_path('expose') hdu.writeto(filename, clobber=True) logger.debug("wrote: {}".format(filename)) elapse_time += time.clock() print("Took %.3f seconds." % elapse_time) return "expose " + str(success) + "," + str(filename) + "," + str( itime)