From 288b5797e0d234eb679da7641ce95e7162cef6d3 Mon Sep 17 00:00:00 2001 From: "Peana, David" Date: Sun, 26 Feb 2023 09:41:05 -0500 Subject: [PATCH] routine --- andor_repo/andor/andor_driver.py | 5 +- .../flir/__pycache__/driver.cpython-38.pyc | Bin 4358 -> 4379 bytes flir_repo/flir/driver.py | 51 +++---- flir_repo/flir/testing.py | 76 +++++----- flir_repo/flir/testing_2.py | 135 ++++++++++++++++++ .../aqctl_picomotor.cpython-38.pyc | Bin 1688 -> 1688 bytes picomotor_repo/picomotor/aqctl_picomotor.py | 2 +- 7 files changed, 197 insertions(+), 72 deletions(-) create mode 100644 flir_repo/flir/testing_2.py diff --git a/andor_repo/andor/andor_driver.py b/andor_repo/andor/andor_driver.py index 27707cc..6e79538 100644 --- a/andor_repo/andor/andor_driver.py +++ b/andor_repo/andor/andor_driver.py @@ -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() @@ -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: diff --git a/flir_repo/flir/__pycache__/driver.cpython-38.pyc b/flir_repo/flir/__pycache__/driver.cpython-38.pyc index 778ce69e140f33f4cfd7d9729e6860457a50f480..fa315adba68c24683d3fed2fb856a35c38655cab 100644 GIT binary patch delta 412 zcmZounytha%FD~e00ciuza@)lZR9)7!e(q@Y-C}!`8JC;6Eh17%VbS<4`&{r5@#ST zt^yKOd^HSN3=0?+GB7fPGvuW)0%=BuDh-fm7SjUe5|$dqX2yk#j0|9PtRQtIY?J4) ziz~tO@IdrLGUPEu0OeAcnt`gpyvY~YqXcg8x#p!fCKr}w7H5`Z=I2e;=1`lQ$YIGX z1+<=lk%^Iyk!|vPj>Up2S^P2u)EO9}*h(|=N({|3CkJz8Fv?Bd!|BM_HTfTBgK&`| zP=_XGkqnS3QU(#KlV@@%a%wUcfjm{DJNX2cI^(>_AGl(G`h2;y7*}ns;Pzr-l%IT< z*BU7FpI4kwcd|I2HRIaJ!F(-h1|aiTA?C>e*->mRsh)Y6B}I}T4y$ucYGP55;pB}1 z!jlE~*%)t37Uy>o)dN|j4ZU}dW>e11VkBCCyNPu F005GIULXJf delta 448 zcmbQO)TYE2%FD~e00i}H#mOO>8~Kj2u$dTG8XKE#zRlvz#LUXVJXw?7!<7@L#2JW- z`{}$In)Gh@ww)uI3^dCW)^3bWaj5huH~>~6#-hpF!>%1^$>>B!hVS%IrT8l*zOkAa~`5vZp~2}o#i7Ri9v zDw8*JDe@KRfP|QfctApWlkak=GtQpO${hnVB#B##arx$6ZZ9TAxyd(pttI6_O4-3m zqqs726Vp=@i;5B}f!cKVtQl8L&fsftFa)V#h1dX6AI0X9>Y0~WQX~oDusY{}^cVrz zMSO6AAIQ4Jnw*ngoO*S#4!@JAK1j*{L>PkzI}l+%`JjOK diff --git a/flir_repo/flir/driver.py b/flir_repo/flir/driver.py index 6a6100e..2443b0b 100644 --- a/flir_repo/flir/driver.py +++ b/flir_repo/flir/driver.py @@ -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() @@ -109,28 +109,31 @@ 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: @@ -138,7 +141,7 @@ def get_image(self,num_of_im): 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() @@ -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): diff --git a/flir_repo/flir/testing.py b/flir_repo/flir/testing.py index 71a5d68..336d355 100644 --- a/flir_repo/flir/testing.py +++ b/flir_repo/flir/testing.py @@ -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 @@ -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() @@ -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() @@ -75,7 +57,7 @@ #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) @@ -83,35 +65,41 @@ 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] @@ -123,10 +111,10 @@ #%% -cam.EndAcquisition() +# cam.EndAcquisition() #%% -f = plt.figure() +# f = plt.figure() #%% Close camera diff --git a/flir_repo/flir/testing_2.py b/flir_repo/flir/testing_2.py new file mode 100644 index 0000000..a4f3159 --- /dev/null +++ b/flir_repo/flir/testing_2.py @@ -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() + + diff --git a/picomotor_repo/picomotor/__pycache__/aqctl_picomotor.cpython-38.pyc b/picomotor_repo/picomotor/__pycache__/aqctl_picomotor.cpython-38.pyc index ac886d74dd8c43ff64e3c9e0a3399b22834312c0..2adf28b03e9c24fc0e4ad4f3c512e4966d07677e 100644 GIT binary patch delta 28 icmbQiJA;=el$V!_0SG)9zb0?wNoQd+-dw_>!UOd diff --git a/picomotor_repo/picomotor/aqctl_picomotor.py b/picomotor_repo/picomotor/aqctl_picomotor.py index dbfa2c1..007815d 100644 --- a/picomotor_repo/picomotor/aqctl_picomotor.py +++ b/picomotor_repo/picomotor/aqctl_picomotor.py @@ -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...")