Skip to content

Commit 7fbace9

Browse files
Merge pull request #920 from annie-xd-wang/set-camera-parameters
add new feature to set camera parameters
2 parents 8cee25b + 94ebda4 commit 7fbace9

File tree

4 files changed

+122
-1
lines changed

4 files changed

+122
-1
lines changed

src/navigate/controller/controller.py

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

12931293
elif event == "exposure_time":
12941294
self.channels_tab_controller.set_exposure_time(value[0], value[1])
1295+
elif event == "display_camera_parameters":
1296+
self.camera_setting_controller.update_camera_parameters_silent(*value)
12951297

12961298
def add_acquisition_mode(self, name, acquisition_obj):
12971299
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: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,3 +1471,108 @@ def data_func(self, frame_ids):
14711471
)
14721472

14731473
self.model.event_queue.put(("multiposition", table_values))
1474+
1475+
class SetCameraParameters:
1476+
"""
1477+
SetCameraParameters class for modifying the parameters of a camera.
1478+
1479+
This class provides functionality to update the parameters of a camera.
1480+
1481+
Notes:
1482+
------
1483+
- This class can set sensor_mode, readout_direction and rolling_shutter_with.
1484+
1485+
- If the value of a parameter is None it doesn't update the parameter value.
1486+
"""
1487+
1488+
def __init__(self, model, sensor_mode="Normal", readout_direction=None, rolling_shutter_width=None):
1489+
"""Initialize the ChangeResolution class.
1490+
1491+
1492+
Parameters:
1493+
----------
1494+
model : MicroscopeModel
1495+
The microscope model object used for resolution mode changes.
1496+
sensor_mode : str, optional
1497+
The desired sensor mode to set for the camera. "Normal" or "Light-Sheet"
1498+
readout_direction : str, optional
1499+
The readout direction to set for the camera.
1500+
"Top-to-Bottom", "Bottom-to-Top", "Bidirectional" or "Rev. Bidirectional"
1501+
rolling_shutter_width : int, optional
1502+
The number of pixels for the rolling shutter.
1503+
"""
1504+
#: MicroscopeModel: The microscope model associated with the resolution change.
1505+
self.model = model
1506+
1507+
#: dict: A dictionary defining the configuration for the resolution change
1508+
self.config_table = {
1509+
"signal": {"main": self.signal_func, "cleanup": self.cleanup},
1510+
"node": {"device_related": True},
1511+
}
1512+
1513+
#: str: The desired sensor mode to set for the camera.
1514+
self.sensor_mode = sensor_mode
1515+
1516+
#: str: The reading direction to set for the microscope.
1517+
self.readout_direction = readout_direction
1518+
1519+
#: int: The number of pixels for the rolling shutter.
1520+
try:
1521+
self.rolling_shutter_width = int(rolling_shutter_width)
1522+
except ValueError:
1523+
self.rolling_shutter_width = None
1524+
1525+
def signal_func(self):
1526+
"""Perform actions to change the resolution mode and update the active
1527+
microscope.
1528+
1529+
This method carries out actions to change the resolution mode of the microscope
1530+
by reconfiguring the microscope settings, updating the active microscope, and
1531+
resuming data acquisition.
1532+
1533+
Returns:
1534+
-------
1535+
bool
1536+
A boolean value indicating the success of the resolution change process.
1537+
"""
1538+
update_flag = False
1539+
update_sensor_mode = False
1540+
camera_parameters = self.model.configuration["experiment"]["CameraParameters"]
1541+
camera_config = self.model.configuration["configuration"]["microscopes"][
1542+
self.model.active_microscope_name
1543+
]["camera"]
1544+
updated_value = [None] * 3
1545+
if self.sensor_mode in ["Normal", "Light-Sheet"] and self.sensor_mode != camera_parameters["sensor_mode"]:
1546+
update_flag = True
1547+
update_sensor_mode = True
1548+
camera_parameters["sensor_mode"] = self.sensor_mode
1549+
updated_value[0] = self.sensor_mode
1550+
if camera_parameters["sensor_mode"] == "Light-Sheet":
1551+
if self.readout_direction in camera_config["supported_readout_directions"] and \
1552+
(update_sensor_mode or camera_parameters["readout_direction"] != self.readout_direction):
1553+
update_flag = True
1554+
camera_parameters["readout_direction"] = self.readout_direction
1555+
updated_value[1] = self.readout_direction
1556+
if self.rolling_shutter_width and (update_sensor_mode or self.rolling_shutter_width != camera_parameters["number_of_pixels"]):
1557+
update_flag = True
1558+
camera_parameters["number_of_pixels"] = self.rolling_shutter_width
1559+
updated_value[2] = self.rolling_shutter_width
1560+
1561+
if not update_flag:
1562+
return True
1563+
# pause data thread
1564+
self.model.pause_data_thread()
1565+
# end active microscope
1566+
self.model.active_microscope.end_acquisition()
1567+
# set parameters and prepare active microscope
1568+
waveform_dict = self.model.active_microscope.prepare_acquisition()
1569+
self.model.event_queue.put(("waveform", waveform_dict))
1570+
self.model.event_queue.put(("display_camera_parameters", updated_value))
1571+
# prepare channel
1572+
self.model.active_microscope.prepare_next_channel()
1573+
# resume data thread
1574+
self.model.resume_data_thread()
1575+
return True
1576+
1577+
def cleanup(self):
1578+
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
@@ -52,6 +52,7 @@
5252
StackPause, # noqa
5353
ZStackAcquisition, # noqa
5454
FindTissueSimple2D, # noqa
55+
SetCameraParameters, # noqa
5556
)
5657
from navigate.model.features.image_writer import ImageWriter # noqa
5758
from navigate.model.features.restful_features import IlastikSegmentation # noqa

0 commit comments

Comments
 (0)