@@ -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 ()
0 commit comments