Skip to content

Commit

Permalink
routine
Browse files Browse the repository at this point in the history
  • Loading branch information
dpeana committed Feb 26, 2023
1 parent 6b3dc40 commit 288b579
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 72 deletions.
5 changes: 2 additions & 3 deletions andor_repo/andor/andor_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self):
(ret, self.xpixels, self.ypixels) = self.cam.GetDetector()
self.imageSize = self.xpixels*self.ypixels
(ret) = self.cam.SetImage(1, 1, 1, self.xpixels, 1, self.ypixels)
(ret) = self.cam.SetExposureTime(0.010) # seoncds, Set exposure time here!
(ret) = self.cam.SetExposureTime(0.030) # seoncds, Set exposure time here!
(ret, self.fminExposure, self.fAccumulate, self.fKinetic) = self.cam.GetAcquisitionTimings()

(ret) = self.cam.PrepareAcquisition()
Expand Down Expand Up @@ -125,8 +125,7 @@ def get_crop_image(self, cropx_min = 419, cropx_max = 459, cropy_min = 358, crop
(ret, fullFrameBuffer, validfirst, validlast) = self.cam.GetImages(image_number,image_number,self.imageSize)
image = np.reshape(fullFrameBuffer, (512,512))
image = image[cropx_min:cropx_max,cropy_min:cropy_max]*1
#[18:21,17:20] for 3x3 array as of 11/16/22
# image[19:20,18:20] = image[19:20,18:20] + 10000 # This line is used for visualizing pixels of interest on image in artiq
# image[19:21,18:20] = image[19:21,18:20] + 10000 # This line is used for visualizing pixels of interest on image in artiq
if zero == False:
image = image * 1
if zero == True:
Expand Down
Binary file modified flir_repo/flir/__pycache__/driver.cpython-38.pyc
Binary file not shown.
51 changes: 27 additions & 24 deletions flir_repo/flir/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def __init__(self):
# try:

# Set camera serial numbers
#serial_1 = '20343286' # Back objective camera
serial_1 = '20409335' # Diagonal fluorescence (on stage carriage)
serial_1 = '20343286' # Back objective camera
# serial_1 = '20409335' # Diagonal fluorescence (on stage carriage)

# Get system
self.system = PySpin.System.GetInstance()
Expand Down Expand Up @@ -109,36 +109,39 @@ def __init__(self):

def await_trigger(self, EXPOSURE_TIME):
try:
# time.sleep(0.01)
self.cam_1.ExposureTime.SetValue(int(EXPOSURE_TIME))
self.cam_1.BeginAcquisition()

# This is a trigger test
# for i in range(1000):
# if self.cam_1.LineStatus() == True:
# self.postpicture()
# self.cam_1.TriggerMode.SetValue(PySpin.TriggerMode_Off)
# time.sleep(1)
# else:
# time.sleep(0.01)
# print("Trying again or exiting")


print("Awaiting trigger...")
self.cam_1.EndAcquisition()
except:
try:
self.cam_1.EndAcquisition()
# time.sleep(0.01)
self.cam_1.ExposureTime.SetValue(int(EXPOSURE_TIME))
self.cam_1.BeginAcquisition()

# This is a trigger test
# for i in range(1000):
# if self.cam_1.LineStatus() == True:
# self.postpicture()
# self.cam_1.TriggerMode.SetValue(PySpin.TriggerMode_Off)
# time.sleep(1)
# else:
# time.sleep(0.01)
# print("Trying again or exiting")


print("Awaiting trigger...")
except:
pass
print("Error in await_trigger(), try restarting artiq")
try:
self.cam_1.EndAcquisition()
except:
pass
print("Error in await_trigger(), try restarting artiq")

def get_image(self,num_of_im):
# try:
# Acquire images. Output is python list of images as numpy arrays
images=[]
for i in range(num_of_im):
# print("Before GetNextImage")
image = self.cam_1.GetNextImage(6000) #timeout (ms) 20000
image = self.cam_1.GetNextImage(10000) #timeout (ms) 6000
# print("Picture Successfully taken at: ",time.strftime("%d %b %Y %H:%M:%S", time.localtime()))
images.append(np.array(image.GetData(),dtype="uint16").reshape((image.GetHeight(),image.GetWidth()))) #convert PySpin ImagePtr into numpy array
image.Release()
Expand All @@ -157,11 +160,11 @@ def get_next_image(self):
# Acquire images. Output is python list of images as numpy arrays

# print("Before GetNextImage")
image = self.cam_1.GetNextImage(20000) #timeout (ms) 20000
image = self.cam_1.GetNextImage(10000) #timeout (ms) 20000
# print("Picture Successfully taken at: ",time.strftime("%d %b %Y %H:%M:%S", time.localtime()))
img = np.array(image.GetData(),dtype="uint16").reshape((image.GetHeight(),image.GetWidth())) #convert PySpin ImagePtr into numpy array
image.Release()

# self.cam_1.EndAcquisition()
return img

def end_acquisition(self):
Expand Down
76 changes: 32 additions & 44 deletions flir_repo/flir/testing.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
# #%%
# import matplotlib.pyplot as plt
# import driver
# t = driver.FLIR()

# #%%

# t.await_trigger(int(50))

# output = t.convert_image(1)
# img = output[0]



# plt.imshow(img)

# t.reset()


#%% Import libraries
import math
import logging
Expand All @@ -26,18 +7,19 @@
import matplotlib.pyplot as plt
import keyboard
import time
imporKeyboardInterrupt
# imporKeyboardInterrupt
import sys
import time
import numpy as np
from PIL import Image
import PySpin



#%% Initialize camera
#% Initialize camera
# Set camera serial numbers
serial_1 = '20343286' # abs camera
#serial_2 = '20409335'# fluorescence camera
serial = '20343286' # abs camera
# serial = '20409335'# fluorescence camera

# Get system
system = PySpin.System.GetInstance()
Expand All @@ -46,7 +28,7 @@
cam_list = system.GetCameras()

# Get cameras by serial
cam = cam_list.GetBySerial(serial_1)
cam = cam_list.GetBySerial(serial)

# Initialize cameras
cam.Init()
Expand Down Expand Up @@ -75,43 +57,49 @@
#cam.EndAcquisition()

print("FLIR driver initialization successful... (pretrig)")
#%%
##%%
cam.V3_3Enable.SetValue(True)
cam.TriggerMode.SetValue(PySpin.TriggerMode_Off)
cam.TriggerSource.SetValue(PySpin.TriggerSource_Line0)
cam.TriggerMode.SetValue(PySpin.TriggerMode_On)

cam.TriggerSelector.SetValue(1) #0,1 PySpin.TriggerSelector_FrameStart
cam.TriggerActivation.SetValue(PySpin.TriggerActivation_RisingEdge)



print("FLIR driver initialization successful... (posttrig)")

#%% Begin Acquisition
##% Begin Acquisition
#cam.TriggerMode.SetValue(PySpin.TriggerMode_Off)
cam.ExposureTime.SetValue(int(50)) #min value 49.2us
# cam.ExposureTime.SetValue(int(50)) #min value 49.2us



cam.BeginAcquisition()
print("Beginning acquisition")


#%% Get Images
num_of_im = 1
num_of_im = 5
images=[]
for i in range(num_of_im):
print("Before GetNextImage")
#print('num images in use',cam.GetNumImagesInUse())
#print('data streams', cam.GetNumDataStreams())
image = cam.GetNextImage(5000) #timeout (ms) 10000
#print('num images in use',cam.GetNumImagesInUse())
#print('data streams', cam.GetNumDataStreams())
print(image.IsIncomplete())
print("Picture Successfully taken at: ",time.strftime("%d %b %Y %H:%M:%S", time.localtime()))
images.append(np.array(image.GetData(),dtype="uint16").reshape((image.GetHeight(),image.GetWidth()))) #convert PySpin ImagePtr into numpy array
image.Release()
#print('num images in use', cam.GetNumImagesInUse())
#print('data streams', cam.GetNumDataStreams())

try:
print("Before GetNextImage")
# print('num images in use',cam.GetNumImagesInUse())
# print('data streams', cam.GetNumDataStreams())
image = cam.GetNextImage(1000) #timeout (ms) 10000
# print('num images in use',cam.GetNumImagesInUse())
# print('data streams', cam.GetNumDataStreams())
print(image.IsIncomplete())
print("Picture Successfully taken at: ",time.strftime("%d %b %Y %H:%M:%S", time.localtime()))
images.append(np.array(image.GetData(),dtype="uint16").reshape((image.GetHeight(),image.GetWidth()))) #convert PySpin ImagePtr into numpy array
image.Release()
# print('num images in use', cam.GetNumImagesInUse())
# print('data streams', cam.GetNumDataStreams())
except:
print("failed")
cam.EndAcquisition()
#%% Plot image
for i in range(num_of_im):
img = images[i]
Expand All @@ -123,10 +111,10 @@


#%%
cam.EndAcquisition()
# cam.EndAcquisition()

#%%
f = plt.figure()
# f = plt.figure()


#%% Close camera
Expand Down
135 changes: 135 additions & 0 deletions flir_repo/flir/testing_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import math
import logging
import asyncio
import asyncserial
import os
import matplotlib.pyplot as plt
import keyboard
import time
import PySpin
import sys
import time
import numpy as np
from PIL import Image

GAIN_VALUE = 23.8 #in dB, 0-40;
#GAMMA_VALUE = 0.5 #0.25-1

# MOT_OFFSET_HEIGHT = 0 #These corrections are for a MOT that is not at the center of the frame
# MOT_OFFSET_WIDTH = 0
#OFFSET = 964 #52 #652 #This will be the pixel width and height of the roi
IMAGE_HEIGHT = 960 #964 is max #OFFSET #964 pixels default
IMAGE_WIDTH = 1280 #1288 is max #OFFSET #1288 pixels default
# HEIGHT_OFFSET = round((964+1-IMAGE_HEIGHT-MOT_OFFSET_HEIGHT)/2)#(964-IMAGE_HEIGHT)/2) # Y, to keep in middle of sensor
# WIDTH_OFFSET = round((1288+1-IMAGE_WIDTH-MOT_OFFSET_WIDTH)/2)#(1288-IMAGE_WIDTH)/2) # X, to keep in middle of sensor

global continue_recording
continue_recording = True

global trigtype
SOFTWARE = 1
HARDWARE = 2
trigtype=HARDWARE
class TriggerType():
def __init__(self, softtrig):
global trigtype
if softtrig is True:
trigtype=SOFTWARE
else:
trigtype=HARDWARE

CHOSEN_TRIGGER = trigtype

logger = logging.getLogger(__name__)

# try:

# Set camera serial numbers
serial_1 = '20343286' # Back objective camera
# serial_1 = '20409335' # Diagonal fluorescence (on stage carriage)

# Get system
system = PySpin.System.GetInstance()

# Get camera list
cam_list = system.GetCameras()


# Get cameras by serial
cam = cam_list.GetBySerial(serial_1)

# Initialize cameras
cam.Init()

#cam.FactoryReset()

# Set acquisition mode to acquire a single frame, this ensures acquired images are sync'd since camera 2 and 3 are setup to be triggered
cam.AcquisitionMode.SetValue(PySpin.AcquisitionMode_Continuous)
cam.ExposureAuto.SetValue(PySpin.ExposureAuto_Off)
cam.ExposureMode.SetValue(PySpin.ExposureMode_Timed) #Timed or TriggerWidth (must comment out trigger parameters other that Line)
cam.ExposureTime.SetValue(50) #us
cam.GainAuto.SetValue(PySpin.GainAuto_Off)
cam.Gain.SetValue(23.8)# Previously 23.8

#cam.Gamma.SetValue(GAMMA_VALUE) #always fails?
#cam.AdcBitDepth.SetValue(PySpin.AdcBitDepth_Bit16) #always fails?

cam.PixelFormat.SetValue(PySpin.PixelFormat_Mono16)
cam.Width.SetValue(1280)
cam.Height.SetValue(960)
# cam.OffsetX.SetValue(WIDTH_OFFSET)
# cam.OffsetY.SetValue(HEIGHT_OFFSET)

#This takes an image quickly. The first image is always corrupt for whatever reason. This picture is not saved.
#cam.BeginAcquisition()
#cam.EndAcquisition()

cam.V3_3Enable.SetValue(True)
cam.TriggerMode.SetValue(PySpin.TriggerMode_Off)
cam.TriggerSource.SetValue(PySpin.TriggerSource_Line0)
cam.TriggerMode.SetValue(PySpin.TriggerMode_On)

cam.TriggerSelector.SetValue(1) #0,1 PySpin.TriggerSelector_FrameStart
cam.TriggerActivation.SetValue(PySpin.TriggerActivation_RisingEdge)


cam_1=cam

print("FLIR driver initialization successful...")
# except:
# print("Error in __init__(), try restarting artiq")

# Await Trigger

cam_1.ExposureTime.SetValue(int(50))
cam_1.BeginAcquisition()

print("Awaiting trigger...")

# cam_1.EndAcquisition()

#%% Get Image

num_of_im = 5
images=[]
try:
for i in range(num_of_im):
print("Before GetNextImage")
image = cam_1.GetNextImage(1000) #timeout (ms) 20000
print("Picture Successfully taken at: ",time.strftime("%d %b %Y %H:%M:%S", time.localtime()))
images.append(np.array(image.GetData(),dtype="uint16").reshape((image.GetHeight(),image.GetWidth()))) #convert PySpin ImagePtr into numpy array
image.Release()

except:
cam_1.EndAcquisition()
print("failed...ending acquisition")

#%% Plot image
for i in range(num_of_im):
img = images[i]
print( np.amax(img) , np.amin(img) )
plt.imshow(img)
plt.colorbar()
plt.show()


Binary file not shown.
2 changes: 1 addition & 1 deletion picomotor_repo/picomotor/aqctl_picomotor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def main():
# if args.device is None:
# print("Starting in Simulation mode...")
# dev = andor(args.device if not args.simulation else None)
dev = picomotor("COM4")
dev = picomotor("COM3")
#asyncio.get_event_loop().run_until_complete(dev.setup())
try:
print("picomotor server startup on port",args.port,"successful...")
Expand Down

0 comments on commit 288b579

Please sign in to comment.