Skip to content

Commit

Permalink
Pre Shift Speed Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dpeana committed Apr 6, 2022
1 parent fa43e0f commit e473f15
Show file tree
Hide file tree
Showing 19 changed files with 306 additions and 83 deletions.
8 changes: 4 additions & 4 deletions andor_repo/andor.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Metadata-Version: 1.0
Metadata-Version: 2.1
Name: andor
Version: 0.0.0
Summary: UNKNOWN
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN

UNKNOWN

5 changes: 2 additions & 3 deletions andor_repo/andor/andor_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ def __init__(self):
self.cam = atmcd()# atmcd("") was working. Switch back if a problem! Without the "" also appears to be working #load the atmcd library
# self.reset()


(ret) = self.cam.Initialize("/usr/local/etc/andor") #initialise camera # C:\Program Files\Andor SDK
(ret, iSerialNumber) = self.cam.GetCameraSerialNumber()

(ret) = self.cam.CoolerON()
(ret) = self.cam.SetCoolerMode(1)
(ret) = self.cam.SetTemperature(-40) #David added this
(ret) = self.cam.SetTemperature(-60) #David added this
(ret) = self.cam.SetHSSpeed(0,0) #David added this 0
(ret) = self.cam.SetVSSpeed(4)#.3) #David added this
(ret) = self.cam.SetVSAmplitude(0) #David added this
Expand Down Expand Up @@ -49,7 +48,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.012) # Set exposure time here!
(ret) = self.cam.SetExposureTime(0.001) # Set exposure time here! 0.012
(ret, self.fminExposure, self.fAccumulate, self.fKinetic) = self.cam.GetAcquisitionTimings()

##############################################################
Expand Down
4 changes: 2 additions & 2 deletions andor_repo/andor/atmcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def __init__(self):
self.dll = cdll.LoadLibrary(dllname)
elif sys.platform == "win32":
if platform.architecture()[0] == "64bit" :
dllname = "C:\\Program Files\\Andor SDK\\atmcd64d.dll"
dllname = "C:\\Program Files\\Andor SOLIS\\atmcd64d.dll"
else:
dllname = "C:\\Program Files\\Andor SDK\\atmcd32d.dll"
dllname = "C:\\Program Files\\Andor SOLIS\\atmcd32d.dll"
self.dll = windll.LoadLibrary(dllname)
else:
print("Cannot detect operating system, will now stop")
Expand Down
234 changes: 234 additions & 0 deletions flir_repo/driver_spyder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@

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
import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"

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 = 964 #964 #OFFSET #964 pixels default
IMAGE_WIDTH = 1288 #1288 #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

CHOSEN_TRIGGER = 2

logger = logging.getLogger(__name__)


class UnexpectedResponse(Exception):
pass

# Set camera serial numbers
serial_1 = '20343286'

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

# Get camera list
cam_list = system.GetCameras()

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

###################### init #################################

# Initialize cameras
cam_1.Init()

# 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_1.AcquisitionMode.SetValue(PySpin.AcquisitionMode_Continuous)
cam_1.ExposureAuto.SetValue(PySpin.ExposureAuto_Off)
cam_1.ExposureMode.SetValue(PySpin.ExposureMode_Timed) #Timed or TriggerWidth (must comment out trigger parameters other that Line)
cam_1.ExposureTime.SetValue(1000)
cam_1.GainAuto.SetValue(PySpin.GainAuto_Off)
cam_1.Gain.SetValue(GAIN_VALUE)

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

cam_1.PixelFormat.SetValue(PySpin.PixelFormat_Mono16)
cam_1.Width.SetValue(IMAGE_WIDTH)
cam_1.Height.SetValue(IMAGE_HEIGHT)
# cam_1.OffsetX.SetValue(WIDTH_OFFSET)
# cam_1.OffsetY.SetValue(HEIGHT_OFFSET)

#This takes an image quickly. The first image is always corrupt for whatever reason. This picture is not saved.
cam_1.TriggerMode.SetValue(PySpin.TriggerMode_Off)
cam_1.BeginAcquisition()
cam_1.EndAcquisition()

cam_1.TriggerSource.SetValue(PySpin.TriggerSource_Line0)
cam_1.TriggerSelector.SetValue(PySpin.TriggerSelector_FrameStart)
cam_1.TriggerActivation.SetValue(PySpin.TriggerActivation_RisingEdge)

cam_1=cam_1

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

#################### await_trigger ###################################

cam_1.ExposureTime.SetValue(int(4000)) # microseconds
cam_1.TriggerMode.SetValue(PySpin.TriggerMode_Off)
cam_1.TriggerMode.SetValue(PySpin.TriggerMode_On)
cam_1.BeginAcquisition()

#################### convert_images ###################################
images=[]

image = cam_1.GetNextImage()
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()

cam_1.EndAcquisition()

#################### save_image ###################################

image = Image.fromarray(images[0])

# Save images
msec = str(time.time())[11:14]
filename = 'H%s_M%d_S%g_MS' % (int(time.strftime("%H", time.localtime())), int(time.strftime("%M", time.localtime())),int(time.strftime("%S", time.localtime())))
filename = filename+msec
##########################Save locally############################################
pre1 = time.time()
if os.path.isfile(r"S:\flir_images\Image_"+filename+".png") == True:
image.save(r"S:\flir_images\Image_"+filename+"(2).png")
post1=time.time()-pre1
print("Saved image "+filename+"(2).png locally in",post1*1000, "millisecond")
else:
image.save(r"S:\flir_images\Image_"+filename+".png")
post1=time.time()-pre1
print("Saved image "+filename+".png locally in",post1*1000, "millisecond")
##########################Save locally############################################

#########################Save to datadepot############################################
# pre2 = time.time()
# if os.path.isfile(r"N:\data\flir_images\Image_"+filename+".png") == True:
# image.save(r"N:\data\flir_images\Image_"+filename+"(2).png")
# post2=time.time()-pre2
# print("Saved image "+filename+"(2).png to datadepot in",post2*1000, "millisecond")
# else:
# image.save(r"N:\data\flir_images\Image_"+filename+".png")
# post2=time.time()-pre2
# print("Saved image "+filename+".png to datadepot in",post2*1000, "millisecond")
#########################Save to datadepot############################################

# print((post2-post1)*1000, "millisecond lag between datadepot and local saves")


# def reset():
# cam_1.DeInit()
# cam_1.EndAcquisition()
# del cam
# cam_list.Clear()
# PySpin.System.CloseInstance()



#####################################################################
# async def _ser_readline():
# c = await port.read(1)
# print(c)
# r = c
# while c != b"\n":
# c = await port.read(1)
# r += c
# return r

# async def _ser_send( cmd, get_response=True):
# """Send a string to the serial port."""

# Low-level routine for sending serial commands to device. It sends
# strings and listens for a response terminated by a carriage return.
# example:
# ser_send("F0 1.0") # sets the freq of channel 0 to 1.0 MHz

# if simulation:
# logger.info("simulation _ser_send(\"%s\")", cmd)
# else:
# logger.debug("_ser_send(\"%s\")", cmd)
# port.ser.reset_input_buffer()
# await port.write((cmd + "\r\n").encode())
# if get_response:
# result = (await _ser_readline()).rstrip().decode()
# logger.debug("got response from device: %s", result)
# if result != "OK":
# errstr = error_codes.get(result, "Unrecognized reply")
# s = "Erroneous reply from device: {ec}, {ecs}".format(
# ec=result, ecs=errstr)
# raise ValueError(s)
# else:
# pass

# async def setup():
# """Initial setup of FLIR."""
# await _ser_send("E d", get_response=False)



























# 1. Get image
# 2. Convert to array immediately
# 3. Bin it (roi) (trash most of array)
# 4. (For abs imaging: background )


















9 changes: 4 additions & 5 deletions flir_repo/flir.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
Metadata-Version: 1.0
Metadata-Version: 2.1
Name: flir
Version: 0.0.0
Summary: UNKNOWN
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN

UNKNOWN

1 change: 0 additions & 1 deletion flir_repo/flir.egg-info/entry_points.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
[console_scripts]
aqctl_flir = flir.aqctl_flir:main

Binary file modified flir_repo/flir/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified flir_repo/flir/__pycache__/aqctl_flir.cpython-38.pyc
Binary file not shown.
Binary file modified flir_repo/flir/__pycache__/driver.cpython-38.pyc
Binary file not shown.
11 changes: 5 additions & 6 deletions flir_repo/flir/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
global trigtype
SOFTWARE = 1
HARDWARE = 2
trigtype=SOFTWARE
trigtype=HARDWARE
class TriggerType():
def __init__(self, softtrig):
global trigtype
Expand All @@ -53,8 +53,7 @@ def __init__(self):
# try:

# Set camera serial numbers
serial_1 = '20343286' # abs camera
#serial_2 = '20409335'# fluorescence camera
serial_1 = '20409335' # 20343286' # abs camera (286 was the original abs camera and 335 is the new one)

# Get system
self.system = PySpin.System.GetInstance()
Expand All @@ -77,7 +76,7 @@ def __init__(self):
cam.ExposureMode.SetValue(PySpin.ExposureMode_Timed) #Timed or TriggerWidth (must comment out trigger parameters other that Line)
cam.ExposureTime.SetValue(100) #us
cam.GainAuto.SetValue(PySpin.GainAuto_Off)
cam.Gain.SetValue(1)# Previously 23.8
cam.Gain.SetValue(23.8)# Previously 23.8

#cam.Gamma.SetValue(GAMMA_VALUE) #always fails?
#cam.AdcBitDepth.SetValue(PySpin.AdcBitDepth_Bit16) #always fails?
Expand Down Expand Up @@ -109,7 +108,7 @@ def __init__(self):

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

Expand Down Expand Up @@ -140,7 +139,7 @@ def get_image(self,num_of_im):
images=[]
for i in range(num_of_im):
# print("Before GetNextImage")
image = self.cam_1.GetNextImage(20000) #timeout (ms) 10000
image = self.cam_1.GetNextImage(50000) #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()
Expand Down
Loading

0 comments on commit e473f15

Please sign in to comment.