Skip to content

Commit f2f04c2

Browse files
Merge pull request #879 from annie-xd-wang/set-default-waveform-template
2 parents 7dd370a + 3e8c27c commit f2f04c2

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

src/navigate/controller/controller.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,17 @@ def update_experiment_setting(self):
440440
441441
"""
442442
self.camera_setting_controller.update_experiment_values()
443+
444+
# set waveform template
445+
if self.acquire_bar_controller.mode in ["live", "single", "z-stack"]:
446+
camera_setting = self.configuration["experiment"]["CameraParameters"]
447+
if camera_setting["sensor_mode"] == "Light-Sheet" and camera_setting[
448+
"readout_direction"
449+
] in ["Bidirectional", "Rev. Bidirectional"]:
450+
self.waveform_tab_controller.set_waveform_template("Bidirectional")
451+
else:
452+
self.waveform_tab_controller.set_waveform_template("Default")
453+
443454
# update multi-positions
444455
positions = self.multiposition_tab_controller.get_positions()
445456
update_config_dict(
@@ -752,9 +763,11 @@ def execute(self, command, *args):
752763
)
753764

754765
# Save the waveform_constants.yaml file.
755-
save_yaml_file(file_directory=file_directory,
756-
content_dict=self.configuration['waveform_constants'],
757-
filename="waveform_constants.yml")
766+
save_yaml_file(
767+
file_directory=file_directory,
768+
content_dict=self.configuration["waveform_constants"],
769+
filename="waveform_constants.yml",
770+
)
758771

759772
self.camera_setting_controller.solvent = self.configuration["experiment"][
760773
"Saving"
@@ -985,7 +998,6 @@ def capture_image(self, command, mode, *args):
985998
)
986999
self.execute("stop_acquire")
9871000

988-
9891001
# Display the Image in the View
9901002
self.camera_view_controller.try_to_display_image(image_id=image_id)
9911003
images_received += 1

src/navigate/controller/sub_controllers/waveform_tab_controller.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,20 @@ def set_mode(self, mode):
328328
"""
329329
state = "normal" if mode == "stop" else "disabled"
330330
self.view.waveform_settings.inputs["waveform_template"].widget["state"] = state
331+
332+
def set_waveform_template(self, template_name):
333+
"""Set the waveform template name
334+
335+
Parameters
336+
----------
337+
template_name : str
338+
Set the waveform template name
339+
340+
Examples
341+
--------
342+
>>> self.set_waveform_template(template_name)
343+
"""
344+
self.view.waveform_settings.inputs["waveform_template"].set(template_name)
345+
self.parent_controller.configuration["experiment"]["MicroscopeState"][
346+
"waveform_template"
347+
] = template_name

test/controller/test_controller.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pathlib import Path
22
from types import SimpleNamespace
3+
from unittest.mock import MagicMock
34

45
import pytest
56

@@ -48,6 +49,11 @@ def controller(tk_root):
4849
waveform_templates_path,
4950
args,
5051
)
52+
# To make sure the testcases won't hang on because of the model.event_queue
53+
# The changes here won't affect other testcases,
54+
# because the testcases from other files use DummyController and DummyModel instead of this controller fixture
55+
controller.model = MagicMock()
56+
controller.model.get_offset_variance_maps.return_value = (None, None)
5157

5258
yield controller
5359

@@ -89,3 +95,43 @@ def test_prepare_acquire_data(controller):
8995
def test_execute(controller):
9096
controller.execute("acquire", "single")
9197
assert True
98+
99+
100+
@pytest.mark.parametrize(
101+
"acquisition_mode, sensor_mode, readout_direction, template_name, expected_template_name",
102+
[
103+
("live", "Normal", "", "Bidirectional", "Default"),
104+
("z-stack", "Normal", "", "Bidirectional", "Default"),
105+
("customized", "Normal", "", "Bidirectional", "Bidirectional"),
106+
("live", "Light-Sheet", "Top-To-Bottom", "Bidirectional", "Default"),
107+
("live", "Light-Sheet", "Bidirectional", "Bidirectional", "Bidirectional"),
108+
("customized", "Light-Sheet", "Bidirectional", "Bidirectional", "Bidirectional",),
109+
("z-stack", "Light-Sheet", "Bidirectional", "Default", "Bidirectional"),
110+
("z-stack", "Light-Sheet", "Top-To-Bottom", "Default", "Default"),
111+
],
112+
)
113+
def test_waveform_template(
114+
controller,
115+
acquisition_mode,
116+
sensor_mode,
117+
readout_direction,
118+
template_name,
119+
expected_template_name,
120+
):
121+
controller.configuration["experiment"]["MicroscopeState"][
122+
"waveform_template"
123+
] = template_name
124+
controller.configuration["experiment"]["MicroscopeState"][
125+
"image_mode"
126+
] = acquisition_mode
127+
controller.configuration["experiment"]["CameraParameters"]["number_of_pixels"] = 10
128+
controller.populate_experiment_setting(in_initialize=True)
129+
130+
controller.camera_setting_controller.mode_widgets["Readout"].set(readout_direction)
131+
controller.camera_setting_controller.mode_widgets["Sensor"].set(sensor_mode)
132+
controller.update_experiment_setting()
133+
134+
assert (
135+
controller.configuration["experiment"]["MicroscopeState"]["waveform_template"]
136+
== expected_template_name
137+
)

0 commit comments

Comments
 (0)