@@ -133,10 +133,19 @@ def __init__(self, view, parent_controller):
133133 self .cam_settings_widgets ["FOV_Y" ].get_variable ().trace_add (
134134 "write" , lambda * args : self .update_fov ("x" )
135135 )
136- self .stack_acq_widgets ["abs_z_start" ].get_variable ().trace_add (
136+ # primary z/f
137+ self .primary_z_axis = self .stack_acq_widgets ["z_device" ].get ().split (" - " )[1 ]
138+ self .primary_f_axis = self .stack_acq_widgets ["f_device" ].get ().split (" - " )[1 ]
139+ self .stack_acq_widgets ["z_device" ].get_variable ().trace_add (
140+ "write" , lambda * args : self .update_fov ("z_device" )
141+ )
142+ self .stack_acq_widgets ["f_device" ].get_variable ().trace_add (
143+ "write" , lambda * args : self .update_fov ("f_device" )
144+ )
145+ self .stack_acq_widgets ["start_position" ].get_variable ().trace_add (
137146 "write" , lambda * args : self .update_fov ("z" )
138147 )
139- self .stack_acq_widgets ["abs_z_end " ].get_variable ().trace_add (
148+ self .stack_acq_widgets ["end_position " ].get_variable ().trace_add (
140149 "write" , lambda * args : self .update_fov ("z" )
141150 )
142151 self .stack_acq_widgets ["start_focus" ].get_variable ().trace_add (
@@ -158,12 +167,6 @@ def __init__(self, view, parent_controller):
158167 self .variables [f"{ axis } _fov" ].trace_add (
159168 "write" , lambda * args , axis = axis : self .calculate_tiles (axis )
160169 )
161- self .variables [f"{ axis } _start" ].trace_add (
162- "write" , lambda * args , axis = axis : self .update_fov (axis )
163- )
164- self .variables [f"{ axis } _end" ].trace_add (
165- "write" , lambda * args , axis = axis : self .update_fov (axis )
166- )
167170
168171 # Calculating Number of Tiles traces
169172 self .variables [f"{ axis } _dist" ].trace_add (
@@ -248,45 +251,7 @@ def set_table(self):
248251 pandas dataframe which is then set as the new table data.
249252 The table is then redrawn.
250253 """
251- if False in self .is_validated .values ():
252- messagebox .showwarning (
253- title = "Navigate" ,
254- message = "Can't calculate positions, "
255- "please make sure all FOV Dists are correct!" ,
256- )
257- return
258-
259- x_start = float (self .variables ["x_start" ].get ())
260- x_stop = float (self .variables ["x_end" ].get ())
261- x_tiles = int (self .variables ["x_tiles" ].get ())
262-
263- y_start = float (self .variables ["y_start" ].get ())
264- y_stop = float (self .variables ["y_end" ].get ())
265- y_tiles = int (self .variables ["y_tiles" ].get ())
266254
267- # shift z by coordinate origin of local z-stack
268- z_start = float (self .variables ["z_start" ].get ()) - float (
269- self .stack_acq_widgets ["start_position" ].get ()
270- )
271- z_stop = float (self .variables ["z_end" ].get ()) - float (
272- self .stack_acq_widgets ["end_position" ].get ()
273- )
274- z_tiles = int (self .variables ["z_tiles" ].get ())
275-
276- # Default to fixed theta
277- r_start = float (self .stage_position_vars ["theta" ].get ())
278- r_stop = float (self .stage_position_vars ["theta" ].get ())
279- r_tiles = 1
280-
281- f_start = float (self .variables ["f_start" ].get ()) - float (
282- self .stack_acq_widgets ["start_focus" ].get ()
283- )
284- f_stop = float (self .variables ["f_end" ].get ()) - float (
285- self .stack_acq_widgets ["end_focus" ].get ()
286- )
287- f_tiles = int (self .variables ["f_tiles" ].get ())
288-
289- # for consistency, always go from low to high
290255 def sort_vars (a , b ):
291256 """Sort two variables from low to high
292257
@@ -305,38 +270,55 @@ def sort_vars(a, b):
305270 if a > b :
306271 return b , a
307272 return a , b
273+
274+ if False in self .is_validated .values ():
275+ messagebox .showwarning (
276+ title = "Navigate" ,
277+ message = "Can't calculate positions, "
278+ "please make sure all FOV Dists are correct!" ,
279+ )
280+ return
281+
282+ tiling_setting = {}
283+ for axis in self ._axes :
284+ start_pos = float (self .variables [f"{ axis } _start" ].get ())
285+ stop_pos = float (self .variables [f"{ axis } _end" ].get ())
286+ tiles = int (self .variables [f"{ axis } _tiles" ].get ())
287+ fov = float (self .variables [f"{ axis } _fov" ].get ())
288+
289+ if axis == self .primary_z_axis :
290+ start_pos -= float (
291+ self .stack_acq_widgets ["start_position" ].get ()
292+ )
293+ stop_pos -= float (
294+ self .stack_acq_widgets ["end_position" ].get ()
295+ )
296+ elif axis == self .primary_f_axis :
297+ start_pos -= float (
298+ self .stack_acq_widgets ["start_focus" ].get ()
299+ )
300+ stop_pos -= float (
301+ self .stack_acq_widgets ["end_focus" ].get ()
302+ )
303+
304+ start_pos , stop_pos = sort_vars (start_pos , stop_pos )
305+ tiling_setting [f"{ axis } _start" ] = start_pos
306+ # tiling_setting[f"{axis}_stop"] = stop_pos
307+ tiling_setting [f"{ axis } _tiles" ] = tiles
308+ tiling_setting [f"{ axis } _length" ] = fov
308309
309- x_start , x_stop = sort_vars (x_start , x_stop )
310- y_start , y_stop = sort_vars (y_start , y_stop )
311- z_start , z_stop = sort_vars (z_start , z_stop )
312- r_start , r_stop = sort_vars (r_start , r_stop )
313- f_start , f_stop = sort_vars (f_start , f_stop )
310+ tiling_setting ["theta_start" ] = float (self .stage_position_vars ["theta" ].get ())
311+ # tiling_setting["theta_stop"] = float(self.stage_position_vars["theta"].get())
312+ tiling_setting ["theta_tiles" ] = 1
313+ tiling_setting ["theta_length" ] = 0
314314
315315 overlap = float (self ._percent_overlap ) / 100
316- table_values = compute_tiles_from_bounding_box (
317- x_start = x_start ,
318- x_tiles = x_tiles ,
319- x_length = float (self .variables ["x_fov" ].get ()),
320- x_overlap = overlap ,
321- y_start = y_start ,
322- y_tiles = y_tiles ,
323- y_length = float (self .variables ["y_fov" ].get ()),
324- y_overlap = overlap ,
325- z_start = z_start ,
326- z_tiles = z_tiles ,
327- z_length = float (self .variables ["z_fov" ].get ()),
328- z_overlap = overlap ,
329- theta_start = r_start ,
330- theta_tiles = r_tiles ,
331- theta_length = 0 ,
332- theta_overlap = overlap ,
333- f_start = f_start ,
334- f_tiles = f_tiles ,
335- f_length = float (self .variables ["f_fov" ].get ()),
336- f_overlap = overlap ,
316+ columns , table_values = compute_tiles_from_bounding_box (
317+ overlap = overlap ,
318+ ** tiling_setting
337319 )
338320
339- update_table (self .multipoint_table , table_values )
321+ update_table (self .multipoint_table , table_values , columns )
340322
341323 # If we have additional axes, create self.d{axis} for each
342324 # additional axis, to ensure we keep track of the step size
@@ -498,39 +480,60 @@ def update_fov(self, axis=None):
498480 """
499481
500482 if axis is None :
501- axis = self ._axes
483+ axes = self ._axes
502484 elif isinstance (axis , str ):
503- axis = [axis ]
485+ if axis == "z_device" :
486+ # get the new primary z axis
487+ primary_z = self .stack_acq_widgets ["z_device" ].get ().split (" - " )[1 ]
488+ if self .primary_z_axis != primary_z :
489+ self .variables [f"{ primary_z } _fov" ].set (self .variables [f"{ self .primary_z_axis } _fov" ].get ())
490+ self .variables [f"{ self .primary_z_axis } _fov" ].set (0 )
491+ self .primary_z_axis = primary_z
492+ return
493+ elif axis == "f_device" :
494+ # get the new primary f axis
495+ primary_f = self .stack_acq_widgets ["f_device" ].get ().split (" - " )[1 ]
496+ if self .primary_f_axis != primary_f :
497+ self .variables [f"{ primary_f } _fov" ].set (self .variables [f"{ self .primary_f_axis } _fov" ].get ())
498+ self .variables [f"{ self .primary_f_axis } _fov" ].set (0 )
499+ self .primary_f_axis = primary_f
500+ return
501+ else :
502+ axes = [axis ]
504503
505- for ax in axis :
504+ for ax in axes :
506505 try :
507506 # Calculate signed fov
508507 if ax == "y" :
509508 y = float (self .cam_settings_widgets ["FOV_X" ].get ()) * sign (
510509 float (self .variables ["x_end" ].get ())
511510 - float (self .variables ["x_start" ].get ())
512511 )
512+ axis = "y"
513513 elif ax == "x" :
514514 x = float (self .cam_settings_widgets ["FOV_Y" ].get ()) * sign (
515515 float (self .variables ["y_end" ].get ())
516516 - float (self .variables ["y_start" ].get ())
517517 )
518+ axis = "x"
518519 elif ax == "z" :
519520 z = float (self .stack_acq_widgets ["end_position" ].get ()) - float (
520521 self .stack_acq_widgets ["start_position" ].get ()
521522 )
523+ axis = self .primary_z_axis
522524 elif ax == "f" :
523525 f = float (self .stack_acq_widgets ["end_focus" ].get ()) - float (
524526 self .stack_acq_widgets ["start_focus" ].get ()
525527 )
528+ axis = self .primary_f_axis
526529
527530 # for ax in self._axes:
528531 # self._fov[ax] = locals().get(ax)
529- self .variables [f"{ ax } _fov" ].set (
532+ self .variables [f"{ axis } _fov" ].set (
530533 abs (locals ().get (ax ))
531534 ) # abs(self._fov[ax]))
532535
533- self .calculate_tiles (ax )
536+ self .calculate_tiles (axis )
534537 except (TypeError , ValueError ) as e :
535538 logger .debug (
536539 f"Controller - Tiling Wizard - Caught ValueError: { e } . "
0 commit comments