Skip to content

Commit c7a3780

Browse files
committed
add new feature to set camera parameters
Currently can set sensor mode, readout direction and the number of pixels for the rolling shutter.
1 parent d4329e9 commit c7a3780

File tree

4 files changed

+120
-1
lines changed

4 files changed

+120
-1
lines changed

src/navigate/controller/controller.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,8 @@ def update_event(self):
12801280

12811281
elif event == "exposure_time":
12821282
self.channels_tab_controller.set_exposure_time(value[0], value[1])
1283+
elif event == "display_camera_parameters":
1284+
self.camera_setting_controller.update_camera_parameters_silent(*value)
12831285

12841286
def add_acquisition_mode(self, name, acquisition_obj):
12851287
if name in self.plugin_acquisition_modes:

src/navigate/controller/sub_controllers/camera_setting_controller.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,14 @@ def update_sensor_mode(self, *args):
315315
Parameters
316316
----------
317317
*args : Variable length argument list.
318+
usually args[0] is tkinter.Event or a str
318319
"""
319320
# Camera Mode
320-
sensor_value = self.mode_widgets["Sensor"].widget.get()
321+
if len(args) > 0 and type(args[0]) is str:
322+
sensor_value = args[0]
323+
self.mode_widgets["Sensor"].widget.set(sensor_value)
324+
else:
325+
sensor_value = self.mode_widgets["Sensor"].widget.get()
321326
if sensor_value == "Normal":
322327
self.mode_widgets["Readout"].set(" ")
323328
self.mode_widgets["Readout"].widget["state"] = "disabled"
@@ -558,3 +563,11 @@ def update_camera_device_related_setting(self):
558563
# Center position
559564
self.roi_widgets["Center_X"].set(self.default_width / 2)
560565
self.roi_widgets["Center_Y"].set(self.default_height / 2)
566+
567+
def update_camera_parameters_silent(self, sensor_mode=None, readout_direction=None, number_of_pixels=None):
568+
if sensor_mode:
569+
self.update_sensor_mode(sensor_mode)
570+
if readout_direction:
571+
self.mode_widgets["Readout"].set(readout_direction)
572+
if number_of_pixels:
573+
self.mode_widgets["Pixels"].set(number_of_pixels)

src/navigate/model/features/common_features.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,3 +1412,106 @@ def data_func(self, frame_ids):
14121412
)
14131413

14141414
self.model.event_queue.put(("multiposition", table_values))
1415+
1416+
class SetCameraParameters:
1417+
"""
1418+
SetCameraParameters class for modifying the parameters of a camera.
1419+
1420+
This class provides functionality to update the parameters of a camera.
1421+
1422+
Notes:
1423+
------
1424+
- This class can set sensor_mode, readout_direction and rolling_shutter_with.
1425+
1426+
- If the value of a parameter is None it doesn't update the parameter value.
1427+
"""
1428+
1429+
def __init__(self, model, sensor_mode="Normal", readout_direction=None, rolling_shutter_width=None):
1430+
"""Initialize the ChangeResolution class.
1431+
1432+
1433+
Parameters:
1434+
----------
1435+
model : MicroscopeModel
1436+
The microscope model object used for resolution mode changes.
1437+
sensor_mode : str, optional
1438+
The desired sensor mode to set for the camera. "Normal" or "Light-Sheet"
1439+
readout_direction : str, optional
1440+
The readout direction to set for the camera.
1441+
"Top-to-Bottom", "Bottom-to-Top", "Bidirectional" or "Rev. Bidirectional"
1442+
rolling_shutter_width : int, optional
1443+
The number of pixels for the rolling shutter.
1444+
"""
1445+
#: MicroscopeModel: The microscope model associated with the resolution change.
1446+
self.model = model
1447+
1448+
#: dict: A dictionary defining the configuration for the resolution change
1449+
self.config_table = {
1450+
"signal": {"main": self.signal_func, "cleanup": self.cleanup},
1451+
"node": {"device_related": True},
1452+
}
1453+
1454+
#: str: The desired sensor mode to set for the camera.
1455+
self.sensor_mode = sensor_mode
1456+
1457+
#: str: The reading direction to set for the microscope.
1458+
self.readout_direction = readout_direction
1459+
1460+
#: int: The number of pixels for the rolling shutter.
1461+
try:
1462+
self.rolling_shutter_width = int(rolling_shutter_width)
1463+
except ValueError:
1464+
self.rolling_shutter_width = None
1465+
1466+
def signal_func(self):
1467+
"""Perform actions to change the resolution mode and update the active
1468+
microscope.
1469+
1470+
This method carries out actions to change the resolution mode of the microscope
1471+
by reconfiguring the microscope settings, updating the active microscope, and
1472+
resuming data acquisition.
1473+
1474+
Returns:
1475+
-------
1476+
bool
1477+
A boolean value indicating the success of the resolution change process.
1478+
"""
1479+
update_flag = False
1480+
update_sensor_mode = False
1481+
camera_parameters = self.model.configuration["experiment"]["CameraParameters"]
1482+
camera_config = self.model.configuration["configuration"]["microscopes"][
1483+
self.model.active_microscope_name
1484+
]["camera"]
1485+
updated_value = [None] * 3
1486+
if self.sensor_mode in ["Normal", "Light-Sheet"] and self.sensor_mode != camera_parameters["sensor_mode"]:
1487+
update_flag = True
1488+
update_sensor_mode = True
1489+
camera_parameters["sensor_mode"] = self.sensor_mode
1490+
updated_value[0] = self.sensor_mode
1491+
if camera_parameters["sensor_mode"] == "Light-Sheet":
1492+
if self.readout_direction in camera_config["supported_readout_directions"] and \
1493+
(update_sensor_mode or camera_parameters["readout_direction"] != self.readout_direction):
1494+
update_flag = True
1495+
camera_parameters["readout_direction"] = self.readout_direction
1496+
updated_value[1] = self.readout_direction
1497+
if self.rolling_shutter_width and (update_sensor_mode or self.rolling_shutter_width != camera_parameters["number_of_pixels"]):
1498+
update_flag = True
1499+
camera_parameters["number_of_pixels"] = self.rolling_shutter_width
1500+
updated_value[2] = self.rolling_shutter_width
1501+
1502+
if not update_flag:
1503+
return True
1504+
# pause data thread
1505+
self.model.pause_data_thread()
1506+
# end active microscope
1507+
self.model.active_microscope.end_acquisition()
1508+
# set parameters and prepare active microscope
1509+
waveform_dict = self.model.active_microscope.prepare_acquisition()
1510+
self.model.event_queue.put(("waveform", waveform_dict))
1511+
self.model.event_queue.put(("display_camera_parameters", updated_value))
1512+
# resume data thread
1513+
self.model.resume_data_thread()
1514+
return True
1515+
1516+
def cleanup(self):
1517+
self.model.resume_data_thread()

src/navigate/model/features/feature_related_functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
StackPause, # noqa
5252
ZStackAcquisition, # noqa
5353
FindTissueSimple2D, # noqa
54+
SetCameraParameters, # noqa
5455
)
5556
from navigate.model.features.image_writer import ImageWriter # noqa
5657
from navigate.model.features.restful_features import IlastikSegmentation # noqa

0 commit comments

Comments
 (0)