4242from scipy .optimize import curve_fit
4343
4444# Local imports
45+ from navigate .model .features .common_features import PrepareNextChannel
4546from navigate .model .features .feature_container import load_features
4647import navigate .model .analysis .image_contrast as img_contrast
4748from navigate .model .features .image_writer import ImageWriter
@@ -156,7 +157,12 @@ def fourier_annulus(im, radius_1=0, radius_2=64):
156157class TonyWilson :
157158 """Tony Wilson iterative AO routine"""
158159
159- def __init__ (self , model , n_iter = None , n_steps = None , coef_amp = None ):
160+ def __init__ (self ,
161+ model ,
162+ n_iter = None ,
163+ n_steps = None ,
164+ coef_amp = None
165+ ):
160166 """Initialize the Tony Wilson iterative AO routine
161167
162168 Parameters
@@ -193,6 +199,10 @@ def __init__(self, model, n_iter=None, n_steps=None, coef_amp=None):
193199 #: navigate.model.Model: Model object
194200 self .model = model
195201
202+ self .tw_settings = self .model .configuration ["experiment" ][
203+ "AdaptiveOpticsParameters"
204+ ]["TonyWilson" ]
205+
196206 #: navigate.model.devices.mirrors.mirror_imop.ImagineOpticsMirror: Mirror object
197207 self .mirror_controller = self .model .active_microscope .mirror .mirror_controller
198208
@@ -206,9 +216,7 @@ def __init__(self, model, n_iter=None, n_steps=None, coef_amp=None):
206216
207217 #: list: List of coefficients to change
208218 self .change_coef = []
209- modes_armed_dict = self .model .configuration ["experiment" ][
210- "AdaptiveOpticsParameters"
211- ]["TonyWilson" ]["modes_armed" ]
219+ modes_armed_dict = self .tw_settings ["modes_armed" ]
212220
213221 #: list: List of mode names
214222 self .mode_names = modes_armed_dict .keys ()
@@ -217,17 +225,11 @@ def __init__(self, model, n_iter=None, n_steps=None, coef_amp=None):
217225 self .change_coef += [i ]
218226 self .n_coefs = len (self .change_coef )
219227
220- self .start_from = self .model .configuration ["experiment" ][
221- "AdaptiveOpticsParameters"
222- ]["TonyWilson" ]["from" ]
228+ self .start_from = self .tw_settings ["from" ]
223229
224- self .metric = self .model .configuration ["experiment" ][
225- "AdaptiveOpticsParameters"
226- ]["TonyWilson" ]["metric" ]
230+ self .metric = self .tw_settings ["metric" ]
227231
228- self .fit_func = self .model .configuration ["experiment" ][
229- "AdaptiveOpticsParameters"
230- ]["TonyWilson" ]["fitfunc" ]
232+ self .fit_func = self .tw_settings ["fitfunc" ]
231233
232234 # if start_from == "flat":
233235 # self.best_coefs = np.zeros(self.n_modes, dtype=np.float32)
@@ -284,38 +286,47 @@ def run(self, *args):
284286 return
285287
286288 # Opens correct shutter and puts all signals to false
287- self .model .prepare_acquisition ()
288- self .model .active_microscope .prepare_next_channel ()
289+ # self.model.prepare_acquisition()
290+ # self.model.active_microscope.prepare_next_channel()
291+
292+ self .model .addon_feature = [
293+ [
294+ {"name" : PrepareNextChannel },
295+ {"name" : TonyWilson }
296+ ]
297+ ]
289298
290- # load signal and data containers
291- self .model .signal_container , self .model .data_container = load_features (
292- self .model , [[{"name" : TonyWilson }]]
293- )
299+ self .model .configuration ["experiment" ]["MicroscopeState" ][
300+ "image_mode"
301+ ] = "customized"
294302
295- self .model .signal_thread = threading .Thread (
296- target = self .model .run_acquisition , name = "TonyWilson Signal"
297- )
303+ self .model .run_command ("acquire" )
298304
299- self .model .data_thread = threading .Thread (
300- target = self .model .run_data_process ,
301- # args=(frame_num,),
302- kwargs = {"data_func" : self .image_writer .save_image },
303- name = "TonyWilson Data" ,
304- )
305+ # # load signal and data containers
306+ # self.model.signal_container, self.model.data_container = load_features(
307+ # self.model, [[{"name": TonyWilson}]]
308+ # )
309+
310+ # self.model.signal_thread = threading.Thread(
311+ # target=self.model.run_acquisition, name="TonyWilson Signal"
312+ # )
313+
314+ # self.model.data_thread = threading.Thread(
315+ # target=self.model.run_data_process,
316+ # # args=(frame_num,),
317+ # kwargs={"data_func": self.image_writer.save_image},
318+ # name="TonyWilson Data",
319+ # )
305320
306- print ("\n **** STARTING TONY WILSON ****\n " )
321+ # print("\n**** STARTING TONY WILSON ****\n")
307322
308- # Start Threads
309- self .model .signal_thread .start ()
310- self .model .data_thread .start ()
323+ # # Start Threads
324+ # self.model.signal_thread.start()
325+ # self.model.data_thread.start()
311326
312327 def get_tw_frame_num (self ):
313328 """Calculate how many frames are needed: iterations x steps x num_coefs"""
314- settings = self .model .configuration ["experiment" ]["AdaptiveOpticsParameters" ][
315- "TonyWilson"
316- ]
317- frames = settings ["iterations" ] * settings ["steps" ] * self .n_coefs
318- return frames
329+ return self .tw_settings ["iterations" ] * self .tw_settings ["steps" ] * self .n_coefs
319330
320331 # don't need this?
321332 def get_steps (self , ranges , step_size ):
@@ -346,18 +357,11 @@ def pre_func_signal(self):
346357 # Timing
347358 self .start_time = time .time ()
348359
349- tw_settings = self .model .configuration ["experiment" ][
350- "AdaptiveOpticsParameters"
351- ]["TonyWilson" ]
352-
353360 self .done_all = False
354361
355- if self .n_iter is None :
356- self .n_iter = tw_settings ["iterations" ]
357- if self .n_steps is None :
358- self .n_steps = tw_settings ["steps" ]
359- if self .coef_amp is None :
360- self .coef_amp = tw_settings ["amplitude" ]
362+ self .n_iter = self .tw_settings ["iterations" ]
363+ self .n_steps = self .tw_settings ["steps" ]
364+ self .coef_amp = self .tw_settings ["amplitude" ]
361365
362366 self .coef_sweep = np .linspace (
363367 - self .coef_amp , self .coef_amp , self .n_steps
0 commit comments