Skip to content

Commit

Permalink
routinw
Browse files Browse the repository at this point in the history
  • Loading branch information
dpeana committed Jul 6, 2021
1 parent b983044 commit 1299b57
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions andor_repo/andor/andor_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,30 @@ def __init__(self):
(ret) = self.cam.SetCoolerMode(1)
(ret) = self.cam.SetTemperature(-40) #David added this
(ret) = self.cam.SetHSSpeed(0,0) #David added this
(ret) = self.cam.SetVSSpeed(3)#.3) #David added this
(ret) = self.cam.SetVSSpeed(4)#.3) #David added this
(ret) = self.cam.SetVSAmplitude(0) #David added this
(ret) = self.cam.SetPreAmpGain(3) #David added this
(ret) = self.cam.SetPreAmpGain(2) #David added this
(ret) = self.cam.SetBaselineClamp(1)
(ret) = self.cam.SetOutputAmplifier(0) # 0 is EMCCD. David added this
(ret) = self.cam.SetEMGainMode(0) # Max is 300? David added this
(ret) = self.cam.SetEMGainMode(3) # Max is 300? David added this
(ret) = self.cam.SetEMCCDGain(50) # Max is 300? David added this
(ret) = self.cam.SetCountConvertMode(2)
(ret) = self.cam.SetCountConvertWavelength(float(852))
# (ret,low,high) = self.cam.GetEMGainRange()
# print(low,high)
#The only setting I have missed is the readout rate which I could not find. might be SetHSSpeed and SetHorizontalSpeed
(ret) = self.cam.SetCountConvertMode(1) # 1 is electron, 2 is photon
# (ret) = self.cam.SetCountConvertWavelength(float(852))

#The only setting I have missed is the readout rate which I could not find. might be SetHorizontalSpeed

(ret) = self.cam.SetShutter(0,1,50,50) # (0,1,50,50) opens shutter. (0,2,50,50) closes shutter.
(ret) = self.cam.SetAcquisitionMode(1)
# (ret) = self.cam.SetAcquisitionMode(1)

##############################################################
(ret) = self.cam.SetFastExtTrigger(1)
(ret) = self.cam.SetAcquisitionMode(3)
(ret) = self.cam.SetNumberKinetics(2)
(ret) = self.cam.EnableKeepCleans(0)
#(ret) = SetIsolatedCropMode(1, 30, 30, 1, 1)
##############################################################


(ret) = self.cam.SetReadMode(4)

(ret) = self.cam.SetTriggerMode(1) # 0 is internal, 1 is external, 6 is external start?
Expand All @@ -42,6 +52,10 @@ def __init__(self):
(ret) = self.cam.SetExposureTime(0.01) # Set exposure time here!
(ret, self.fminExposure, self.fAccumulate, self.fKinetic) = self.cam.GetAcquisitionTimings()

##############################################################
(ret) = self.cam.PrepareAcquisition()
##############################################################

if atmcd.DRV_SUCCESS==ret:
print("Andor Initializiation was successful...")
else:
Expand All @@ -52,10 +66,11 @@ def __init__(self):
# ,Pre-Amp Gain (Gain 3), Output Amplifier (Electron Multiplying), Electron Multiplier (EM) Gain (Enabled->2)


def retrieve_trigger(self):
def retrieve_trigger(self,images=1):
# print("Retrieving trigger...")
# time1 = time.time()
win32event.WaitForSingleObject(self.event, 12000) # 12000 is 12 second timeout
for i in range(images):
win32event.WaitForSingleObject(self.event, 6000) # 12000 is 12 second timeout
# print(time.time()-time1)

def reset_image(self):
Expand All @@ -67,21 +82,28 @@ def start_acquisition_event(self):
self.cam.SetDriverEvent(self.event)
self.cam.StartAcquisition()

def get_last_image(self):
(ret, fullFrameBuffer) = self.cam.GetMostRecentImage(self.imageSize) # GetImages(somethinghere) might be a better command if we want to do background subtraction
image = np.reshape(fullFrameBuffer, (512,512)) #Converts c_long 262k array to 512x512 image numpy array
return image

def trigger_count(self):
_,__,x = self.cam.GetNumberAvailableImages()
print(x,"triggers received")
return x

def get_last_image(self):
(ret, fullFrameBuffer) = self.cam.GetMostRecentImage(self.imageSize) # GetImages(somethinghere) might be a better command if we want to do background subtraction
image = np.reshape(fullFrameBuffer, (512,512)) #Converts c_long 262k array to 512x512 image numpy array
return image

def get_specific_image(self):
(ret, fullFrameBuffer, validfirst, validlast) = self.cam.GetImages(1,1,self.imageSize)
def get_specific_image(self, image_number):
(ret, fullFrameBuffer, validfirst, validlast) = self.cam.GetImages(image_number,image_number,self.imageSize)
image = np.reshape(fullFrameBuffer, (512,512)) #Converts c_long 262k array to 512x512 image numpy array
return image

def get_all_images(self,image_number = 2):
image_arr = [0]*image_number
for i in range(image_number):
(ret, image_arr[i], validfirst, validlast) = self.cam.GetImages(i+1,i+1,self.imageSize)
image_arr[i] = np.reshape(image_arr[i], (512,512)) #Converts c_long 262k array to 512x512 image numpy array
return image_arr

def plot_image(self,image=None):
if type(image) == type(None):
image = self.get_last_image()
Expand Down

0 comments on commit 1299b57

Please sign in to comment.