Skip to content

Commit 7454186

Browse files
More responsive widget updates for AO Feature
1 parent e2dd0f3 commit 7454186

File tree

4 files changed

+64
-94
lines changed

4 files changed

+64
-94
lines changed

src/navigate/controller/sub_controllers/adaptive_optics.py

Lines changed: 42 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ def __init__(self, view, parent_controller):
6363

6464
self.view.popup.protocol("WM_DELETE_WINDOW", self.view.popup.dismiss)
6565

66-
self.parent_controller.configuration["experiment"]["AdaptiveOpticsParameters"][
67-
"HighlightedMode"
68-
] = None
66+
self.mirror_params = self.parent_controller.configuration["experiment"]["MirrorParameters"]
67+
self.ao_params = self.parent_controller.configuration["experiment"]["AdaptiveOpticsParameters"]
68+
self.tw_params = self.ao_params["TonyWilson"]
69+
70+
self.ao_params["HighlightedMode"] = None
6971

7072
#: list of dicts: list of dicts containing trace data
7173
self.trace_list = []
@@ -79,16 +81,6 @@ def __init__(self, view, parent_controller):
7981
#: dict: dictionary of mode labels
8082
self.mode_labels = self.view.get_labels()
8183

82-
# TODO: just for testing, remove later...
83-
#: list: list of cameras
84-
self.camera_list = self.view.camera_list
85-
self.camera_list[
86-
"values"
87-
] = self.parent_controller.configuration_controller.microscope_list
88-
self.camera_list.bind(
89-
"<<ComboboxSelected>>", lambda evt: self.change_camera(evt)
90-
)
91-
9284
#: Figure: figure for mirror plot
9385
self.fig = self.view.fig
9486

@@ -129,20 +121,27 @@ def __init__(self, view, parent_controller):
129121
"<Leave>", lambda evt: evt.widget.config(background="SystemButtonFace")
130122
)
131123

132-
self.populate_experiment_values()
124+
# update all experiment values each time one is changed
125+
# from navigate.view.custom_widgets.LabelInputWidgetFactory import LabelInput
126+
# for k in self.widgets:
127+
# input = self.widgets[k]
128+
# if type(input) == LabelInput:
129+
# input.widget.bind(
130+
# "<KeyRelease>", self.on_input_change
131+
# )
133132

134-
def change_camera(self, evt):
135-
"""Change the camera to the selected camera
133+
self.widgets["iterations"].widget.bind( "<KeyRelease>", self.on_input_change)
134+
self.widgets["steps"].widget.bind( "<KeyRelease>", self.on_input_change)
135+
self.widgets["amplitude"].widget.bind( "<KeyRelease>", self.on_input_change)
136136

137-
Parameters
138-
----------
139-
evt : Event
140-
The event that triggered this function
141-
"""
142-
# cam_id = evt.widget.get().split("_")[-1]
143-
# self.parent_controller.execute("change_camera", int(cam_id))
144-
cam_name = evt.widget.get()
145-
self.parent_controller.execute("resolution", cam_name)
137+
self.widgets["from"]["button"].bind( "<<ComboboxSelected>>", self.on_input_change)
138+
self.widgets["metric"]["button"].bind( "<<ComboboxSelected>>", self.on_input_change)
139+
self.widgets["fitfunc"]["button"].bind( "<<ComboboxSelected>>", self.on_input_change)
140+
141+
self.populate_experiment_values()
142+
143+
def on_input_change(self, evt):
144+
self.update_experiment_values()
146145

147146
def set_highlighted_mode(self, evt, mode):
148147
"""Set the highlighted mode
@@ -155,7 +154,7 @@ def set_highlighted_mode(self, evt, mode):
155154
The mode to highlight
156155
"""
157156
evt.widget.config(background="red")
158-
self.parent_controller.configuration["experiment"]["AdaptiveOpticsParameters"][
157+
self.ao_params[
159158
"HighlightedMode"
160159
] = mode
161160
self.plot_tw_trace()
@@ -172,11 +171,7 @@ def deselect_all_modes(self):
172171

173172
def populate_experiment_values(self):
174173
"""Populate the experiment values"""
175-
self.camera_list.set(
176-
self.parent_controller.configuration["experiment"]["MicroscopeState"][
177-
"microscope_name"
178-
]
179-
)
174+
180175
self.widgets["save_report"]["variable"].set(
181176
self.parent_controller.configuration["experiment"][
182177
"AdaptiveOpticsParameters"
@@ -217,41 +212,26 @@ def update_experiment_values(self):
217212
modes_dict = {}
218213
coef_list = self.get_coef_from_widgets()
219214
keys = self.view.mode_names
215+
220216
for i, coef in enumerate(coef_list):
221217
modes_dict[keys[i]] = coef
222-
self.parent_controller.configuration["experiment"]["MirrorParameters"][
223-
"modes"
224-
] = modes_dict
225-
226-
self.parent_controller.configuration["experiment"]["AdaptiveOpticsParameters"][
227-
"TonyWilson"
228-
]["iterations"] = int(self.widgets["iterations"].get())
229-
self.parent_controller.configuration["experiment"]["AdaptiveOpticsParameters"][
230-
"TonyWilson"
231-
]["steps"] = int(self.widgets["steps"].get())
232-
self.parent_controller.configuration["experiment"]["AdaptiveOpticsParameters"][
233-
"TonyWilson"
234-
]["amplitude"] = float(self.widgets["amplitude"].get())
235-
self.parent_controller.configuration["experiment"]["AdaptiveOpticsParameters"][
236-
"TonyWilson"
237-
]["from"] = self.widgets["from"]["variable"].get()
238-
self.parent_controller.configuration["experiment"]["AdaptiveOpticsParameters"][
239-
"TonyWilson"
240-
]["metric"] = self.widgets["metric"]["variable"].get()
241-
self.parent_controller.configuration["experiment"]["AdaptiveOpticsParameters"][
242-
"TonyWilson"
243-
]["fitfunc"] = self.widgets["fitfunc"]["variable"].get()
244-
245-
self.parent_controller.configuration["experiment"]["AdaptiveOpticsParameters"][
246-
"save_report"
247-
] = self.widgets["save_report"]["variable"].get()
218+
219+
self.mirror_params["modes"] = modes_dict
248220

249-
for k in self.modes_armed.keys():
250-
self.parent_controller.configuration["experiment"][
251-
"AdaptiveOpticsParameters"
252-
]["TonyWilson"]["modes_armed"][k] = self.modes_armed[k]["variable"].get()
221+
try:
222+
self.tw_params["iterations"] = int(self.widgets["iterations"].get())
223+
self.tw_params["steps"] = int(self.widgets["steps"].get())
224+
self.tw_params["amplitude"] = float(self.widgets["amplitude"].get())
225+
self.tw_params["from"] = self.widgets["from"]["variable"].get()
226+
self.tw_params["metric"] = self.widgets["metric"]["variable"].get()
227+
self.tw_params["fitfunc"] = self.widgets["fitfunc"]["variable"].get()
228+
except ValueError:
229+
pass
230+
231+
self.ao_params["save_report"] = self.widgets["save_report"]["variable"].get()
253232

254-
# print(self.parent_controller.configuration['experiment']['MirrorParameters']['modes'])
233+
for k in self.modes_armed.keys():
234+
self.tw_params["modes_armed"][k] = self.modes_armed[k]["variable"].get()
255235

256236
def get_coef_from_widgets(self):
257237
"""Get the coefficients from the widgets

src/navigate/model/features/adaptive_optics.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ class TonyWilson:
159159

160160
def __init__(self,
161161
model,
162-
n_iter=None,
163-
n_steps=None,
164-
coef_amp=None
162+
verbose=False
165163
):
166164
"""Initialize the Tony Wilson iterative AO routine
167165
@@ -173,15 +171,6 @@ def __init__(self,
173171
#: int: Number of modes
174172
self.n_modes = None
175173

176-
#: int: Number of iterations
177-
self.n_iter = n_iter
178-
179-
#: int: Number of steps
180-
self.n_steps = n_steps
181-
182-
#: float: Coefficient amplitude
183-
self.coef_amp = coef_amp
184-
185174
#: bool: True if all iterations are done, False otherwise
186175
self.done_all = False
187176

@@ -191,6 +180,8 @@ def __init__(self,
191180
#: list: detailed report to save as JSON after
192181
self.report = []
193182

183+
self.verbose = verbose
184+
194185
# TODO: I don't think these are used...
195186
self.laser = None
196187
self.laser_power = 0
@@ -371,7 +362,7 @@ def pre_func_signal(self):
371362
self.target_signal_id = 0
372363
self.total_frame_num = self.get_tw_frame_num()
373364

374-
print(f"Total frame num: {self.total_frame_num}")
365+
# print(f"Total frame num: {self.total_frame_num}")
375366

376367
if self.start_from == "flat":
377368
self.best_coefs = np.zeros(self.n_modes, dtype=np.float32)
@@ -395,8 +386,8 @@ def in_func_signal(self):
395386
bool
396387
True if the signal is done, False otherwise
397388
"""
389+
398390
out_str = "in_func_signal\n"
399-
400391
out_str += f"\tSignal:\t{self.signal_id}\n"
401392

402393
step = self.signal_id % self.n_steps
@@ -427,6 +418,7 @@ def in_func_signal(self):
427418

428419
try:
429420
curr_mirror_coefs = self.mirror_controller.get_modal_coefs()[0]
421+
430422
out_str += (
431423
f"\tCoefs:\t[{' '.join([f'{c:.2f}' for c in curr_mirror_coefs])}]\n"
432424
)
@@ -445,7 +437,6 @@ def in_func_signal(self):
445437
if (applied_coefs == curr_mirror_coefs).all() or (applied_coefs == 0).all():
446438
self.signal_id += 1
447439

448-
out_str += "\tSending tw_frame_queue...\n"
449440
self.tw_frame_queue.put(
450441
(
451442
self.model.frame_id,
@@ -458,7 +449,8 @@ def in_func_signal(self):
458449
else:
459450
out_str += "\tMirror update failed...\n"
460451

461-
print(out_str)
452+
if self.verbose:
453+
print(out_str)
462454

463455
return self.signal_id >= self.total_frame_num
464456

@@ -470,8 +462,6 @@ def end_func_signal(self):
470462
bool
471463
True if the signal is done, False otherwise
472464
"""
473-
print("end_func_signal() called!!!")
474-
475465
if self.model.stop_acquisition:
476466
return True
477467

@@ -642,13 +632,14 @@ def in_func_data(self, frame_ids=[]):
642632
self.done_all = True
643633
out_str += "\tDone all!!!\n"
644634

645-
out_str += "\tSending tw_data_queue...\n"
646635
self.tw_data_queue.put((self.frames_done,))
647636

648-
print(out_str)
637+
if self.verbose:
638+
print(out_str)
639+
elif self.done_itr:
640+
print(f"Done iteration {itr + 1} / {self.n_iter} ...")
649641

650642
if self.frames_done >= self.total_frame_num:
651-
print(">>> in_func_data ended!!!")
652643
return frame_ids
653644

654645
def build_report(self):
@@ -680,8 +671,6 @@ def end_func_data(self):
680671
bool
681672
True if the data is done, False otherwise
682673
"""
683-
print("end_func_data() called!!!")
684-
685674
if self.done_all:
686675
self.best_coefs = self.best_coefs_overall
687676
# self.model.stop_acquisition = True

src/navigate/model/features/common_features.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,6 @@ def toggle_projection_mode(self):
219219
else:
220220
self.disable_projection()
221221

222-
# debugging
223-
print(f"------- galvo_stage (enabled = {self.enable}) --------\n")
224-
mems = vars(self.galvo_stage)
225-
for mem in mems:
226-
print(f"{mem}:\t{mems[mem]}")
227-
print("----------------------------------------------------\n")
228-
229222
return True
230223

231224
def setup_projection(self):

src/navigate/model/model.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,16 @@ def run_command(
730730
coefficients = self.active_microscope.mirror.set_from_wcs_file(path=args[0])
731731
self.update_mirror(coef=coefficients)
732732
elif command == "tony_wilson":
733-
tony_wilson = TonyWilson(self)
734-
tony_wilson.run(*args)
733+
# tony_wilson = TonyWilson(self)
734+
# tony_wilson.run(*args)
735+
self.configuration["experiment"]["MicroscopeState"][
736+
"image_mode"
737+
] = "customized"
738+
self.addon_feature = [
739+
{"name": PrepareNextChannel},
740+
{"name": TonyWilson}
741+
]
742+
self.run_command("acquire")
735743

736744
elif command == "load_feature":
737745
"""

0 commit comments

Comments
 (0)