Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new feature to set camera parameters #920

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/navigate/controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,8 @@ def update_event(self):

elif event == "exposure_time":
self.channels_tab_controller.set_exposure_time(value[0], value[1])
elif event == "display_camera_parameters":
self.camera_setting_controller.update_camera_parameters_silent(*value)

def add_acquisition_mode(self, name, acquisition_obj):
if name in self.plugin_acquisition_modes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,14 @@ def update_sensor_mode(self, *args):
Parameters
----------
*args : Variable length argument list.
usually args[0] is tkinter.Event or a str
"""
# Camera Mode
sensor_value = self.mode_widgets["Sensor"].widget.get()
if len(args) > 0 and type(args[0]) is str:
sensor_value = args[0]
self.mode_widgets["Sensor"].widget.set(sensor_value)
else:
sensor_value = self.mode_widgets["Sensor"].widget.get()
if sensor_value == "Normal":
self.mode_widgets["Readout"].set(" ")
self.mode_widgets["Readout"].widget["state"] = "disabled"
Expand Down Expand Up @@ -558,3 +563,11 @@ def update_camera_device_related_setting(self):
# Center position
self.roi_widgets["Center_X"].set(self.default_width / 2)
self.roi_widgets["Center_Y"].set(self.default_height / 2)

def update_camera_parameters_silent(self, sensor_mode=None, readout_direction=None, number_of_pixels=None):
if sensor_mode:
self.update_sensor_mode(sensor_mode)
if readout_direction:
self.mode_widgets["Readout"].set(readout_direction)
if number_of_pixels:
self.mode_widgets["Pixels"].set(number_of_pixels)
105 changes: 105 additions & 0 deletions src/navigate/model/features/common_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,3 +1412,108 @@ def data_func(self, frame_ids):
)

self.model.event_queue.put(("multiposition", table_values))

class SetCameraParameters:
"""
SetCameraParameters class for modifying the parameters of a camera.

This class provides functionality to update the parameters of a camera.

Notes:
------
- This class can set sensor_mode, readout_direction and rolling_shutter_with.

- If the value of a parameter is None it doesn't update the parameter value.
"""

def __init__(self, model, sensor_mode="Normal", readout_direction=None, rolling_shutter_width=None):
"""Initialize the ChangeResolution class.


Parameters:
----------
model : MicroscopeModel
The microscope model object used for resolution mode changes.
sensor_mode : str, optional
The desired sensor mode to set for the camera. "Normal" or "Light-Sheet"
readout_direction : str, optional
The readout direction to set for the camera.
"Top-to-Bottom", "Bottom-to-Top", "Bidirectional" or "Rev. Bidirectional"
rolling_shutter_width : int, optional
The number of pixels for the rolling shutter.
"""
#: MicroscopeModel: The microscope model associated with the resolution change.
self.model = model

#: dict: A dictionary defining the configuration for the resolution change
self.config_table = {
"signal": {"main": self.signal_func, "cleanup": self.cleanup},
"node": {"device_related": True},
}

#: str: The desired sensor mode to set for the camera.
self.sensor_mode = sensor_mode

#: str: The reading direction to set for the microscope.
self.readout_direction = readout_direction

#: int: The number of pixels for the rolling shutter.
try:
self.rolling_shutter_width = int(rolling_shutter_width)
except ValueError:
self.rolling_shutter_width = None

def signal_func(self):
"""Perform actions to change the resolution mode and update the active
microscope.

This method carries out actions to change the resolution mode of the microscope
by reconfiguring the microscope settings, updating the active microscope, and
resuming data acquisition.

Returns:
-------
bool
A boolean value indicating the success of the resolution change process.
"""
update_flag = False
update_sensor_mode = False
camera_parameters = self.model.configuration["experiment"]["CameraParameters"]
camera_config = self.model.configuration["configuration"]["microscopes"][
self.model.active_microscope_name
]["camera"]
updated_value = [None] * 3
if self.sensor_mode in ["Normal", "Light-Sheet"] and self.sensor_mode != camera_parameters["sensor_mode"]:
update_flag = True
update_sensor_mode = True
camera_parameters["sensor_mode"] = self.sensor_mode
updated_value[0] = self.sensor_mode
if camera_parameters["sensor_mode"] == "Light-Sheet":
if self.readout_direction in camera_config["supported_readout_directions"] and \
(update_sensor_mode or camera_parameters["readout_direction"] != self.readout_direction):
update_flag = True
camera_parameters["readout_direction"] = self.readout_direction
updated_value[1] = self.readout_direction
if self.rolling_shutter_width and (update_sensor_mode or self.rolling_shutter_width != camera_parameters["number_of_pixels"]):
update_flag = True
camera_parameters["number_of_pixels"] = self.rolling_shutter_width
updated_value[2] = self.rolling_shutter_width

if not update_flag:
return True
# pause data thread
self.model.pause_data_thread()
# end active microscope
self.model.active_microscope.end_acquisition()
# set parameters and prepare active microscope
waveform_dict = self.model.active_microscope.prepare_acquisition()
self.model.event_queue.put(("waveform", waveform_dict))
self.model.event_queue.put(("display_camera_parameters", updated_value))
# prepare channel
self.model.active_microscope.prepare_next_channel()
# resume data thread
self.model.resume_data_thread()
return True

def cleanup(self):
self.model.resume_data_thread()
1 change: 1 addition & 0 deletions src/navigate/model/features/feature_related_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
StackPause, # noqa
ZStackAcquisition, # noqa
FindTissueSimple2D, # noqa
SetCameraParameters, # noqa
)
from navigate.model.features.image_writer import ImageWriter # noqa
from navigate.model.features.restful_features import IlastikSegmentation # noqa
Expand Down
Loading