|
|
@@ -34,17 +34,20 @@ if os.path.exists(Path + hw_fName): |
|
|
|
__FILTER_PWM__ = hwSettings["filterSet"] # Filter locations |
|
|
|
|
|
|
|
# Default camera settings |
|
|
|
__SHUTTER_SPEED__ = hwSettings["SHUTTER_SPEED"] # Shutter speed time in SECONDS. |
|
|
|
DEFAULT_ISO = hwSettings["DEFAULT_ISO"] |
|
|
|
ISO_F1 = hwSettings["ISO_F1"] |
|
|
|
ISO_F2 = hwSettings["ISO_F2"] |
|
|
|
ISO_F3 = hwSettings["ISO_F3"] |
|
|
|
__DEFAULT_SHUTTER_SPEED__ = hwSettings["DEFAULT_SHUTTER_SPEED"] # Shutter speed time in SECONDS. |
|
|
|
__SHUTTER_SPEED_L1__ = hwSettings["SHUTTER_SPEED_L1"] # Shutter speed time in SECONDS. |
|
|
|
__SHUTTER_SPEED_L2__ = hwSettings["SHUTTER_SPEED_L2"] # Shutter speed time in SECONDS. |
|
|
|
__SHUTTER_SPEED_L3__ = hwSettings["SHUTTER_SPEED_L3"] # Shutter speed time in SECONDS. |
|
|
|
__DEFAULT_ISO__ = hwSettings["DEFAULT_ISO"] |
|
|
|
__ISO_F1__ = hwSettings["ISO_F1"] |
|
|
|
__ISO_F2__ = hwSettings["ISO_F2"] |
|
|
|
__ISO_F3__ = hwSettings["ISO_F3"] |
|
|
|
|
|
|
|
# Light frequencies |
|
|
|
DEFAULT_LIGHT_FREQ = hwSettings["DEFAULT_LIGHT_FREQ"] |
|
|
|
LIGHT_FREQ_F1 = hwSettings["LIGHT_FREQ_F1"] |
|
|
|
LIGHT_FREQ_F2 = hwSettings["LIGHT_FREQ_F2"] |
|
|
|
LIGHT_FREQ_F3 = hwSettings["LIGHT_FREQ_F3"] |
|
|
|
__DEFAULT_LIGHT_FREQ__ = hwSettings["DEFAULT_LIGHT_FREQ"] |
|
|
|
__LIGHT_FREQ_F1__ = hwSettings["LIGHT_FREQ_F1"] |
|
|
|
__LIGHT_FREQ_F2__ = hwSettings["LIGHT_FREQ_F2"] |
|
|
|
__LIGHT_FREQ_F3__ = hwSettings["LIGHT_FREQ_F3"] |
|
|
|
|
|
|
|
# Replicates |
|
|
|
__REPLICATES__ = hwSettings["cameraRepetitions"] |
|
|
@@ -64,22 +67,25 @@ else: |
|
|
|
__FILTER_PWM__["No_Filter"] = 1460 # No filter (RGB image). |
|
|
|
|
|
|
|
# Default camera settings |
|
|
|
__SHUTTER_SPEED__ = 0.1 # Shutter speed time in SECONDS. |
|
|
|
DEFAULT_ISO = 10 |
|
|
|
ISO_F1 = 100 |
|
|
|
ISO_F2 = 100 |
|
|
|
ISO_F3 = 400 |
|
|
|
__DEFAULT_SHUTTER_SPEED__ = 0.1 # Shutter speed time in SECONDS. |
|
|
|
__SHUTTER_SPEED_L1__ = 0.1 # Shutter speed time in SECONDS. |
|
|
|
__SHUTTER_SPEED_L2__ = 0.1 # Shutter speed time in SECONDS. |
|
|
|
__SHUTTER_SPEED_L3__ = 0.1 # Shutter speed time in SECONDS. |
|
|
|
__DEFAULT_ISO__ = 10 |
|
|
|
__ISO_F1__ = 100 |
|
|
|
__ISO_F2__ = 100 |
|
|
|
__ISO_F3__ = 400 |
|
|
|
|
|
|
|
# Light frequencies |
|
|
|
DEFAULT_LIGHT_FREQ = 20000 |
|
|
|
LIGHT_FREQ_F1 = 200 |
|
|
|
LIGHT_FREQ_F2 = 200 |
|
|
|
LIGHT_FREQ_F3 = 200 |
|
|
|
__DEFAULT_LIGHT_FREQ__ = 20000 |
|
|
|
__LIGHT_FREQ_F1__ = 200 |
|
|
|
__LIGHT_FREQ_F2__ = 200 |
|
|
|
__LIGHT_FREQ_F3__ = 200 |
|
|
|
|
|
|
|
# Replicates |
|
|
|
__REPLICATES__ = 3 |
|
|
|
|
|
|
|
def _img_settings(Camera, Filter=None): |
|
|
|
def _img_settings(Camera, Filter=None, Wavelength=None): |
|
|
|
""" |
|
|
|
Private method. Define camera settings. Auto-exposure or |
|
|
|
auto-white-balance result in aleatory camera settings depending upon |
|
|
@@ -105,6 +111,9 @@ def _img_settings(Camera, Filter=None): |
|
|
|
Filter : string or None, optional |
|
|
|
Specify filter being used. Used in case there is a need to specify |
|
|
|
camera settings for each filter installed in the light modulator. |
|
|
|
Wavelength : int |
|
|
|
Value between 0 and 3, where 0 means *Filter_1*, 1 means |
|
|
|
*Filter_2*, 2 means *Filter_3* and 3 means *No_Filter*. |
|
|
|
|
|
|
|
Returns |
|
|
|
------- |
|
|
@@ -117,18 +126,28 @@ def _img_settings(Camera, Filter=None): |
|
|
|
Camera.hflip = True # Ensures well A1 is in the bottom-left. |
|
|
|
Camera.awb_mode = 'off' |
|
|
|
Camera.awb_gains = (1.45, 1.45) |
|
|
|
SHUTTER_SPEED = __SHUTTER_SPEED__ # Shutter speed _IN SECONDS_. |
|
|
|
# De-couple shutter speeds from filters used, link to LED. |
|
|
|
# Set ISO for each Filter. |
|
|
|
if Filter == "Filter_1": |
|
|
|
Camera.iso = ISO_F1 |
|
|
|
Camera.iso = __ISO_F1__ |
|
|
|
elif Filter == "Filter_2": |
|
|
|
# SHUTTER_SPEED = 5 # Uncomment after Rob/Kai tests |
|
|
|
Camera.iso = ISO_F2 |
|
|
|
Camera.iso = __ISO_F2__ |
|
|
|
elif Filter == "Filter_3": |
|
|
|
Camera.iso = ISO_F3 |
|
|
|
Camera.iso = __ISO_F3__ |
|
|
|
else: # NO_FILTER |
|
|
|
Camera.iso = __DEFAULT_ISO__ |
|
|
|
# Set shutter speeds for each LED |
|
|
|
if Wavelength == 0: |
|
|
|
SHUTTER_SPEED = __SHUTTER_SPEED_L1__ |
|
|
|
elif Wavelength == 1: |
|
|
|
SHUTTER_SPEED = __SHUTTER_SPEED_L2__ |
|
|
|
elif Wavelength == 2: |
|
|
|
SHUTTER_SPEED = __SHUTTER_SPEED_L3__ |
|
|
|
else: |
|
|
|
Camera.iso = DEFAULT_ISO |
|
|
|
SHUTTER_SPEED = __DEFAULT_SHUTTER_SPEED__ |
|
|
|
|
|
|
|
Camera.framerate = 1/SHUTTER_SPEED # slowest SHUTTER_SPEED = 1/framerate. Autoadjust. |
|
|
|
Camera.shutter_speed = int(SHUTTER_SPEED * 10**6) # Translate SHUTTER_SPEED to µS. |
|
|
|
Camera.shutter_speed = int(SHUTTER_SPEED * 10**6) # Translate SHUTTER_SPEED to µs. |
|
|
|
# max_res = Camera.MAX_RESOLUTION # How big can the image be? |
|
|
|
# Camera.resolution = (int(max_res[0]), int(max_res[1])) |
|
|
|
Camera.resolution = (1640, 1232) # Smallest resolution with full FoV (partial FoV results in plate not fully captured). |
|
|
@@ -238,7 +257,7 @@ def img_acquisition_routine_replicates(self, light_intensity, wavelength, |
|
|
|
""" |
|
|
|
for r in range(replicates): |
|
|
|
self._device._modulate_LED_intensity(light_intensity, channel=wavelength) |
|
|
|
t.sleep(__SHUTTER_SPEED__) |
|
|
|
t.sleep(self._device._camera.shutter_speed / 10**6) # From µs to seconds. |
|
|
|
yield photo_path + file_name + str(r) + self._pic_ext |
|
|
|
if light_intensity == 255 or flag is True: |
|
|
|
yield photo_path + "findWells" + self._pic_ext |
|
|
@@ -503,12 +522,12 @@ class SetupDevice: |
|
|
|
light_panel = dev() |
|
|
|
if len(self._GPIO_PIN) == 1: |
|
|
|
light_panel.set_mode(self._GPIO_PIN[0], OUTPUT) |
|
|
|
light_panel.set_PWM_frequency(self._GPIO_PIN[0], DEFAULT_LIGHT_FREQ) # Hz (20KHz max with -s 2). |
|
|
|
light_panel.set_PWM_frequency(self._GPIO_PIN[0], __DEFAULT_LIGHT_FREQ__) # Hz (20KHz max with -s 2). |
|
|
|
light_panel.write(self._GPIO_PIN[0], 0) # Init off state. |
|
|
|
elif len(self._GPIO_PIN) == 3: |
|
|
|
for pin in self._GPIO_PIN: |
|
|
|
light_panel.set_mode(pin, OUTPUT) |
|
|
|
light_panel.set_PWM_frequency(pin, DEFAULT_LIGHT_FREQ) # Hz (20KHz max with -s 2). |
|
|
|
light_panel.set_PWM_frequency(pin, __DEFAULT_LIGHT_FREQ__) # Hz (20KHz max with -s 2). |
|
|
|
# light_panel.write(pin, 0) # Init off state. |
|
|
|
else: |
|
|
|
raise ValueError("Channels must be 1 < chnl < 3, but ", |
|
|
@@ -733,7 +752,7 @@ class SetupDevice: |
|
|
|
|
|
|
|
self._FILTER_PIN = FILTER_PIN |
|
|
|
self._HEATER_PIN = HEATER_PIN |
|
|
|
self.__SHUTTER_SPEED__ = __SHUTTER_SPEED__ |
|
|
|
self.__SHUTTER_SPEED__ = __DEFAULT_SHUTTER_SPEED__ |
|
|
|
|
|
|
|
# Initialise hardware. |
|
|
|
self._light_panel, self._heater,\ |
|
|
@@ -1090,39 +1109,39 @@ class SetProtocol: |
|
|
|
# Check if `wavelenght' is WHITE, as it is produced by combining mutiple PIN |
|
|
|
if wavelength == 3: |
|
|
|
for PIN in range(len(self._device._GPIO_PIN)): |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[PIN], DEFAULT_LIGHT_FREQ) |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[PIN], __DEFAULT_LIGHT_FREQ__) |
|
|
|
else: |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[wavelength], LIGHT_FREQ_F1) |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[wavelength], __LIGHT_FREQ_F1__) |
|
|
|
elif flt == "Filter_2": |
|
|
|
# Check if `wavelenght' is WHITE, as it is produced by combining mutiple PIN |
|
|
|
if wavelength == 3: |
|
|
|
for PIN in range(len(self._device._GPIO_PIN)): |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[PIN], DEFAULT_LIGHT_FREQ) |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[PIN], __DEFAULT_LIGHT_FREQ__) |
|
|
|
else: |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[wavelength], LIGHT_FREQ_F2) |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[wavelength], __LIGHT_FREQ_F2__) |
|
|
|
elif flt == "Filter_3": |
|
|
|
# Check if `wavelenght' is WHITE, as it is produced by combining mutiple PIN |
|
|
|
if wavelength == 3: |
|
|
|
for PIN in range(len(self._device._GPIO_PIN)): |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[PIN], DEFAULT_LIGHT_FREQ) |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[PIN], __DEFAULT_LIGHT_FREQ__) |
|
|
|
else: |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[wavelength], LIGHT_FREQ_F3) |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[wavelength], __LIGHT_FREQ_F3__) |
|
|
|
elif flt == "No_Filter": |
|
|
|
if wavelength == 0: |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[wavelength], LIGHT_FREQ_F1) |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[wavelength], __LIGHT_FREQ_F1__) |
|
|
|
elif wavelength == 1: |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[wavelength], LIGHT_FREQ_F2) |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[wavelength], __LIGHT_FREQ_F2__) |
|
|
|
elif wavelength == 2: |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[wavelength], LIGHT_FREQ_F3) |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[wavelength], __LIGHT_FREQ_F3__) |
|
|
|
else: |
|
|
|
for PIN in range(len(self._device._GPIO_PIN)): |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[PIN], DEFAULT_LIGHT_FREQ) |
|
|
|
self._device._light_panel.set_PWM_frequency(self._device._GPIO_PIN[PIN], __DEFAULT_LIGHT_FREQ__) |
|
|
|
# Set camera on-the-fly to adapt to different wavelenghts. |
|
|
|
# Because this step happens with any filter, it does not require |
|
|
|
# a post-read reset. |
|
|
|
self._preheat_channel(wavelength) # Preheat LEDs. **DO NOT** move from here. |
|
|
|
self._device._camera = _img_settings(self._device._camera, |
|
|
|
Filter=flt) |
|
|
|
Filter=flt, Wavelength=wavelength) |
|
|
|
servo_state = self._device.set_filter(flt, current_pwm=servo_state) |
|
|
|
self._data_acquisition(light_range, current_time, flt, |
|
|
|
wavelength, referenceRead) |