def take_image(filename): """take_image: The function will create a Operating System timestamp variable (OS_time), configure the 2 IRCSP cameras to take an image (image1 & image2) and store the FPA temperatures (temp1 & temp2) into an HDF5 File format with a unique naming convention. Parameters: filename - the filename of the HDF5 file. Returns: HDF5 file with 2 FLIR Boson Images, 2 FPA Temperatures & OS_time string. """ # Time/Speed Test - Start start = datetime.datetime.now() #Create Timestamp for File Creation Tracking now = datetime.datetime.now() OS_time = now.strftime("%H:%M") camera1 = Boson(port='COM4') #camera2 = Boson(port='COM6') print(camera1.find_video_device()) #print(camera2.find_video_device()) #set FFC to manual #camera1.set_ffc_manual() #camera2.set_ffc_manual() #get FPA temperature #temp1 = camera1.get_fpa_temperature() #temp2 = camera2.get_fpa_temperature() #Take Image #image1 = camera1.grab(device_id = 1) #image2 = camera2.grab(device_id = 2) #Close Camera camera1.close() #camera2.close() # Open as Read-Write ("a" - creates file if doesn't exist) #with h5py.File(filename, "a") as h5: #h5.attrs["OS_time"] = OS_time #h5["image1"] = image1 #h5["image2"] = image2 #h5["temp1"] = temp1 #h5["temp2"] = temp2 #Time/Speed Test - Finish finish = datetime.datetime.now() print("Image Capture File: ", filename, " created in ", finish - start) #Adjust Sleep for File Creation Rate - (File/Seconds) time.sleep(10)
def _connect(self, device, port, baudrate, loglevel): try: self.camera = Boson(port, baudrate, loglevel) self.camera.setup_video(device) self.camera.grab() if not self.camera.cap.isOpened(): warnings.warn("Failed to open camera") self.camera = None except IOError: warnings.warn("Failed to find camera") self.camera = None
def test_capture_unix(): with Boson() as camera: res = camera.grab() assert res is not None assert len(res.shape) == 2 assert res.dtype == "uint16"
def test_ffc_request(): with Boson() as camera: n_frames = camera.get_frame_count() print(n_frames) camera.do_ffc() time.sleep(1) ffc_frame = camera.get_last_ffc_frame_count() assert (ffc_frame - n_frames) < 200
def test_capture_windows(): with Boson() as camera: # Currently have no way of figuring this out res = camera.grab() assert res is not None assert len(res.shape) == 2 assert res.dtype == "uint16"
class ThreadedBoson(ThreadedCamera): def __init__(self, device=None, port=None, baudrate=921600, loglevel=logging.WARNING): super(ThreadedBoson, self).__init__() self.temperature = None self._connect(device, port, baudrate, loglevel) def _connect(self, device, port, baudrate, loglevel): try: self.camera = Boson(port, baudrate, loglevel) self.camera.setup_video(device) self.camera.grab() if not self.camera.cap.isOpened(): warnings.warn("Failed to open camera") self.camera = None except IOError: warnings.warn("Failed to find camera") self.camera = None def height(self): return self.camera.cap.get(cv2.CAP_PROP_FRAME_HEIGHT) def width(self): return self.camera.cap.get(cv2.CAP_PROP_FRAME_WIDTH) def channels(self): return 1 def dtype(self): return np.uint16 def _grab(self): image = np.expand_dims(self.camera.grab(), -1) self.min_count = image.min() self.max_count = image.max() return image def close(self): self.camera.close() def get_target_fps(self): return self.camera.cap.get(cv2.CAP_PROP_FPS)
def test_ffc_temperature(): with Boson() as camera: assert camera.get_last_ffc_temperature() > 0
And a single polarization state (unpol, H,V, ect) Output will be saved as a hdf5 file Uses flirpy, make sure enviroment is open uses python-usbtmc @author: khart """ from flirpy.camera.boson import Boson import matplotlib.pyplot as plt import numpy as np import h5py import time #choose the ROI ymin = 100 ymax = 250 xmin = 100 xmax = 200 camera1 = Boson() print(camera1.find_serial_device()) image1 = camera1.grab() t1 = camera1.get_fpa_temperature() camera1.close() print('cam temp is ' + str(t1) + ' C') plt.matshow(image1[xmin:xmax, ymin:ymax]) plt.colorbar() plt.show()
# -*- coding: utf-8 -*- """ Created on Tue Sep 8 09:50:57 2020 @author: khart """ import matplotlib.pyplot as plt from flirpy.camera.boson import Boson camera1 = Boson(port='COM5') camera2 = Boson(port='COM6') print(camera1.find_video_device()) print(camera2.find_video_device()) # set FFC to manual camera1.set_ffc_manual() camera2.set_ffc_manual() # get FPA temperature temp1 = camera1.get_fpa_temperature() temp2 = camera2.get_fpa_temperature() # take image im1 = camera1.grab(device_id=1) im2 = camera2.grab(device_id=2) camera1.close() camera2.close() plt.imshow(im1)
save_path = 'C:\\Users\\khart\\Documents\\IRCSP2_data\\mono_data\\' name = 'cam1_test' #choose the ROI ymin = 0; ymax = 250; xmin = 0; xmax = 320; #initialize monochromator instr = initialize() shutter(instr,1) #initialize camera camera = Boson() #choose wavelengths samps = 80; waves = np.linspace(6,14,samps); response = np.zeros(samps); err = np.zeros(samps); images = []; i =0; while i <samps: changeWavelength(instr,waves[i]); image = camera.grab(); images.append(image) response[i] = np.mean(image[ymin:ymax,xmin:xmax]); err[i] = np.std(image[ymin:ymax,xmin:xmax]);
def test_ffc_temperature_threshold(): with Boson() as camera: temp_diff = 5.0 camera.set_ffc_temperature_threshold(temp_diff) assert camera.get_ffc_temperature_threshold() == temp_diff
def test_ffc_mode_auto(): with Boson() as camera: camera.set_ffc_auto() mode = camera.get_ffc_mode() assert mode == flirpy.camera.boson.FLR_BOSON_AUTO_FFC
def test_open_boson(): camera = Boson() camera.close()
from flirpy.camera.boson import Boson import flirpy.camera.boson import pytest import os import time if Boson.find_video_device() is None: pytest.skip("Boson not connected, skipping tests", allow_module_level=True) def test_open_boson(): camera = Boson() camera.close() @pytest.mark.skipif(os.name != "nt", reason="Skipping Windows-only test") def test_capture_windows(): with Boson() as camera: # Currently have no way of figuring this out res = camera.grab() assert res is not None assert len(res.shape) == 2 assert res.dtype == "uint16" @pytest.mark.skipif(os.name == "nt", reason="Skipping on Windows") def test_capture_unix(): with Boson() as camera: res = camera.grab()
# -*- coding: utf-8 -*- """ Created on Fri Apr 16 11:24:49 2021 @author: khart """ from flirpy.camera.boson import Boson import matplotlib.pyplot as plt import cv2 import numpy as np import time import h5py #initialize camera camera = Boson() camera.set_ffc_manual() wait = 5 frames = 100 def take_image(frames): image = np.zeros([frames, 256, 320]) for i in range(frames): im = camera.grab(device_id=1) image[i] = im return (np.mean(image, axis=0)) plt.imshow(take_image(3)) camera.close()
def test_frame_count(): with Boson() as camera: assert camera.get_frame_count() > 0
def test_get_serial(): with Boson() as camera: assert camera.get_camera_serial() != 0
def test_ffc_frame_threshold(): with Boson() as camera: thresh = 6000 camera.set_ffc_frame_threshold(thresh) assert camera.get_ffc_frame_threshold() == thresh
from flirpy.camera.boson import Boson c = Boson(port="COM14") c.grab() c2 = Boson(port="COM17") c2.grab() c.close()
def test_ffc_mode_manual(): with Boson() as camera: camera.set_ffc_manual() mode = camera.get_ffc_mode() assert mode == flirpy.camera.boson.FLR_BOSON_MANUAL_FFC
""" from flirpy.camera.boson import Boson import numpy as np import matplotlib.pyplot as plt import os.path import h5py import time #ask user to input correct COM port COM = input("What is the COM PORT? \n ") print("Attempting to open ", COM) #open camera object and set FFC to manual try: cam = Boson(COM) cam.setup_video(device_id=1) cam.set_ffc_manual() temp = cam.get_fpa_temperature() print('The FPA temp is ', temp, ' C') except: print('Could not open COM port, check camera is not in use') #Ask user if an initical ffc is requested ffc = input('would you like to do an initial ffc? [y,n] \n') if ffc in ['Y', 'y', 'Yes', 'yes', 'YES']: print('Initiating FFC') cam.do_ffc() #Ask user how many images and at what intervals
def test_get_sensor_serial(): # Skipped until proper CRC is implemented with Boson() as camera: assert camera.get_sensor_serial() != 0
from flirpy.camera.boson import Boson import matplotlib.pyplot as plt import cv2 import numpy as np import time import h5py """options for measurement""" save_path = 'C:\\Users\\khart\\Documents\\IRCSP2_data\\NUC\\may19\\polarized\\' meas_num = 10 # number of measurements to average over wait = .1 # time between samples angle_step = 1 angle_start = 0 angle_stop = 360 """DO NOT CHANGE""" camera1 = Boson(port='COM5') camera2 = Boson(port='COM6') # set FFC to manual camera1.set_ffc_manual() camera2.set_ffc_manual() # SET UP MOTOR motor = apt.Motor(83830282) # set velocity parameters to be maximum [minv, a, v] = motor.get_velocity_parameters() [maxa, maxv] = motor.get_velocity_parameter_limits() print('homing motor') motor.set_velocity_parameters(minv, maxa, maxv)
#choose the ROI ymin = 0; ymax = 250; xmin = 0; xmax = 320; #choose wavelengths samps = 5; temp1 = np.zeros(samps);temp2 = np.zeros(samps) avgs1 = np.zeros(samps);avgs2 = np.zeros(samps) images1 = [];images2 = [] i =0; while i <samps: camera1 = Boson(port = "COM5") print(camera1.find_serial_device()) image1 = camera1.grab(); t1 = camera1.get_fpa_temperature() camera1.close() camera2 = Boson(port = "COM6") image2 = camera2.grab(); print(camera2.find_serial_device()) t2 = camera2.get_fpa_temperature() camera2.close() print('sample #'+str(i)+' temp1 is '+str(t1)+' C, '+'temp2 is '+str(t2)+' C') images1.append(image1) temp1[i] = t1 avgs1[i] = np.mean(image1)
def test_get_firmware_revision(): with Boson() as camera: rev = camera.get_firmware_revision() assert len(rev) == 3
"""options for measurement""" name = "dark" save_path = 'C:\\Users\\khart\\Documents\\IRCAM_data\\jun032021\\' #SET UP MOTOR motor = apt.Motor(83830277) #set velocity parameters to be maximum [minv, a, v] = motor.get_velocity_parameters() [maxa, maxv] = motor.get_velocity_parameter_limits() motor.set_velocity_parameters(minv, maxa, maxv) motor.move_home(True) #initialize camera camera = Boson(port='COM4') camera.set_ffc_manual() wait = 5 frames = 100 def take_image(frames): image = np.zeros([frames, 256, 320]) for i in range(frames): im = camera.grab(device_id=1) image[i] = im return (np.mean(image, axis=0)) #measurement sequence I0 = take_image(frames)
def test_get_fpa_temperature(): with Boson() as camera: # In principle this could be exactly zero, but it's quite unlikely. assert camera.get_fpa_temperature() != 0
single_cam_mono_sweep Created on Wed Dec 9 13:12:18 2020 This script will sweep over wavelength on the monochomator for a single measurement configuration. This includes image capture for a single camera (no MS) And a single polarization state (unpol, H,V, ect) Output will be saved as a hdf5 file Uses flirpy, make sure enviroment is open uses python-usbtmc @author: khart """ from flirpy.camera.boson import Boson import matplotlib.pyplot as plt import numpy as np import h5py import time #initialize camera camera1 = Boson(port="COM5") camera2 = Boson(port="COM6") print(camera1.find_video_device()) print(camera2.find_video_device()) #close camera camera1.close() camera2.close()
def test_get_part_number(): with Boson() as camera: pn = camera.get_part_number() assert pn != ""