55import matplotlib
66import numpy as np
77from matplotlib import pyplot as plt
8- from matplotlib .backends .backend_tkagg import FigureCanvasTkAgg , NavigationToolbar2Tk
8+ from matplotlib .backends .backend_tkagg import (
9+ FigureCanvasTkAgg ,
10+ NavigationToolbar2Tk ,
11+ )
912
1013matplotlib .use ("tkagg" )
1114
@@ -24,15 +27,21 @@ def initUI(self):
2427 """Initialize the GUI for fourigui."""
2528
2629 self .loaded = False # denotes whether a dataset is loaded
27- self .transformed = False # denotes whether dataset is Fourier transformed
28- self .cutted = False # denotes whether cutoff frequencies are applied to dataset
30+ self .transformed = (
31+ False # denotes whether dataset is Fourier transformed
32+ )
33+ self .cutted = (
34+ False # denotes whether cutoff frequencies are applied to dataset
35+ )
2936 self .transcutted = False # denotes whether cutoff frequencies are applied and Fourier transformed
3037
3138 self .master .title ("FouriGUI" )
3239 self .pack (fill = tk .BOTH , expand = True )
3340
3441 print ("\n New Session started ..." )
35- print ("Enjoy exploring the beautiful reconstructions in real and in reciprocal space!" )
42+ print (
43+ "Enjoy exploring the beautiful reconstructions in real and in reciprocal space!"
44+ )
3645
3746 # 4 frames:
3847 # frame 00: all buttons
@@ -54,7 +63,9 @@ def initUI(self):
5463 self .filename_entry .grid (row = 0 , column = 1 , columnspan = 3 )
5564 self .filename_entry .insert (0 , "/path/data.h5" )
5665
57- loadbutton = Button (frame00 , text = "load" , command = lambda : self .load_cube ())
66+ loadbutton = Button (
67+ frame00 , text = "load" , command = lambda : self .load_cube ()
68+ )
5869 loadbutton .grid (row = 0 , column = 4 )
5970
6071 # row 1: change axis area
@@ -125,7 +136,9 @@ def initUI(self):
125136 self .colorbarmax .grid (row = 3 , column = 3 )
126137 self .colorbarmin = tk .Entry (frame00 , width = 7 )
127138 self .colorbarmin .grid (row = 4 , column = 3 )
128- set_range = Button (frame00 , text = "set range" , command = lambda : self .colorrange_upd ())
139+ set_range = Button (
140+ frame00 , text = "set range" , command = lambda : self .colorrange_upd ()
141+ )
129142 set_range .grid (row = 2 , column = 4 )
130143 toglobalmax = Button (
131144 frame00 ,
@@ -151,7 +164,9 @@ def initUI(self):
151164 anilabel .grid (row = 7 , column = 3 , columnspan = 2 , sticky = tk .W )
152165 self .anientry = tk .Entry (frame00 , width = 7 )
153166 self .anientry .grid (row = 8 , column = 3 )
154- anibutton = Button (frame00 , text = "animation" , command = lambda : self .animation ())
167+ anibutton = Button (
168+ frame00 , text = "animation" , command = lambda : self .animation ()
169+ )
155170 anibutton .grid (row = 8 , column = 4 )
156171
157172 # row 10-12 Fourier transformation
@@ -170,7 +185,9 @@ def initUI(self):
170185 self .qmaxentry = tk .Entry (frame00 , width = 7 )
171186 self .qmaxentry .grid (row = 12 , column = 3 )
172187 self .cutoff = tk .IntVar ()
173- newcutoffbutton = Button (frame00 , text = "new cutoff" , command = lambda : self .newcutoff ())
188+ newcutoffbutton = Button (
189+ frame00 , text = "new cutoff" , command = lambda : self .newcutoff ()
190+ )
174191 newcutoffbutton .grid (row = 10 , column = 4 )
175192 cutoffon = tk .Radiobutton (
176193 frame00 ,
@@ -225,33 +242,45 @@ def initUI(self):
225242 label = "slider" ,
226243 orient = tk .HORIZONTAL ,
227244 length = WIDTH // 2 , # resolution=-1,
228- command = lambda x : self .multiple_funcs (self .plot_plane (), self .intensity_upd_local ()),
245+ command = lambda x : self .multiple_funcs (
246+ self .plot_plane (), self .intensity_upd_local ()
247+ ),
229248 )
230249 # command=lambda p: self.plot_plane())
231- self .slider .grid (row = 0 , column = 0 , padx = 10 , pady = 10 , sticky = tk .N + tk .E + tk .S + tk .W )
250+ self .slider .grid (
251+ row = 0 , column = 0 , padx = 10 , pady = 10 , sticky = tk .N + tk .E + tk .S + tk .W
252+ )
232253
233254 self .frame01_plotcell = tk .Frame (self .frame01 )
234- self .frame01_plotcell .grid (row = 1 , column = 0 , padx = 10 , pady = 10 , sticky = tk .N + tk .E + tk .S + tk .W )
255+ self .frame01_plotcell .grid (
256+ row = 1 , column = 0 , padx = 10 , pady = 10 , sticky = tk .N + tk .E + tk .S + tk .W
257+ )
235258
236259 self .frame01_toolbar = tk .Frame (self .frame01 )
237260 self .frame01_toolbar .grid (row = 2 , column = 0 )
238261
239262 # 10 #
240263 # frame 10, lower left
241264 frame10 = tk .Frame (self )
242- frame10 .place (x = 5 , y = HEIGHT - 30 ) # , height=HEIGHT//2, width=WIDTH//2)
265+ frame10 .place (
266+ x = 5 , y = HEIGHT - 30
267+ ) # , height=HEIGHT//2, width=WIDTH//2)
243268 quit = Button (
244269 frame10 ,
245270 text = "exit" ,
246- command = lambda : self .multiple_funcs (print ("Session ended...\n " , self .quit ())),
271+ command = lambda : self .multiple_funcs (
272+ print ("Session ended...\n " , self .quit ())
273+ ),
247274 )
248275 quit .pack (side = tk .TOP )
249276
250277 # 11 #
251278 # frame 00, lower right
252279 # no functionality
253280 frame11 = tk .Frame (self )
254- frame11 .place (x = WIDTH // 2 , y = HEIGHT // 2 ) # , height=HEIGHT//2, width=WIDTH//2)
281+ frame11 .place (
282+ x = WIDTH // 2 , y = HEIGHT // 2
283+ ) # , height=HEIGHT//2, width=WIDTH//2)
255284
256285 def load_cube (self ):
257286 """Loads 3D array in h5py file format from the filename input panel 3D
@@ -285,9 +314,13 @@ def load_cube(self):
285314 label = "slider" ,
286315 orient = tk .HORIZONTAL ,
287316 length = WIDTH // 2 , # resolution=-1,
288- command = lambda x : self .multiple_funcs (self .plot_plane (), self .intensity_upd_local ()),
317+ command = lambda x : self .multiple_funcs (
318+ self .plot_plane (), self .intensity_upd_local ()
319+ ),
320+ )
321+ self .slider .grid (
322+ row = 0 , column = 0 , padx = 10 , pady = 10 , sticky = tk .N + tk .E + tk .S + tk .W
289323 )
290- self .slider .grid (row = 0 , column = 0 , padx = 10 , pady = 10 , sticky = tk .N + tk .E + tk .S + tk .W )
291324
292325 if not self .loaded :
293326 fig , ax = plt .subplots (figsize = (4.95 , 4.95 ))
@@ -307,13 +340,17 @@ def load_cube(self):
307340 ax .set_xlabel ("pixel" )
308341 ax .set_ylabel ("pixel" )
309342 self .canvas = FigureCanvasTkAgg (fig , master = self .frame01_plotcell )
310- self .toolbar = NavigationToolbar2Tk (self .canvas , self .frame01_toolbar )
343+ self .toolbar = NavigationToolbar2Tk (
344+ self .canvas , self .frame01_toolbar
345+ )
311346 self .toolbar .pack (side = tk .LEFT )
312347 # self.toolbar.children['!button6'].pack_forget()
313348 # self.toolbar.children['!button7'].pack_forget()
314349 self .toolbar .update ()
315350 self .canvas .draw ()
316- self .canvas .get_tk_widget ().pack (side = tk .LEFT , fill = tk .BOTH , expand = 1 )
351+ self .canvas .get_tk_widget ().pack (
352+ side = tk .LEFT , fill = tk .BOTH , expand = 1
353+ )
317354 self .loaded = True
318355 else :
319356 self .plot_plane ()
@@ -367,18 +404,30 @@ def intensity_upd_local(self):
367404 elif self .axis .get () == 2 :
368405 plane = self .cube [:, :, self .plane_num .get ()]
369406 nan_ratio = np .count_nonzero (np .isnan (plane )) / plane .size
370- self .localmax ["text" ] = f"{ np .format_float_scientific (np .nanmax (plane ), 1 )} "
371- self .localmin ["text" ] = f"{ np .format_float_scientific (np .nanmin (plane ), 1 )} "
372- self .localsum ["text" ] = f"{ np .format_float_scientific (np .nansum (plane ), 1 )} "
407+ self .localmax ["text" ] = (
408+ f"{ np .format_float_scientific (np .nanmax (plane ), 1 )} "
409+ )
410+ self .localmin ["text" ] = (
411+ f"{ np .format_float_scientific (np .nanmin (plane ), 1 )} "
412+ )
413+ self .localsum ["text" ] = (
414+ f"{ np .format_float_scientific (np .nansum (plane ), 1 )} "
415+ )
373416 self .localnanratio ["text" ] = f"{ round (nan_ratio , 2 )} "
374417
375418 def intensity_upd_global (self ):
376419 """Load global intensity minimum, maximum and sum of 3D array."""
377420 self .intensity_upd_local ()
378421 nan_ratio = np .count_nonzero (np .isnan (self .cube )) / self .cube .size
379- self .globalmax ["text" ] = f"{ np .format_float_scientific (np .nanmax (self .cube ), 1 )} "
380- self .globalmin ["text" ] = f"{ np .format_float_scientific (np .nanmin (self .cube ), 1 )} "
381- self .globalsum ["text" ] = f"{ np .format_float_scientific (np .nansum (self .cube ), 1 )} "
422+ self .globalmax ["text" ] = (
423+ f"{ np .format_float_scientific (np .nanmax (self .cube ), 1 )} "
424+ )
425+ self .globalmin ["text" ] = (
426+ f"{ np .format_float_scientific (np .nanmin (self .cube ), 1 )} "
427+ )
428+ self .globalsum ["text" ] = (
429+ f"{ np .format_float_scientific (np .nansum (self .cube ), 1 )} "
430+ )
382431 self .globalnanratio ["text" ] = "{}" .format (round (nan_ratio , 2 ))
383432
384433 def fft (self ):
@@ -475,9 +524,17 @@ def applycutoff(self):
475524 # convert qmax to pixels
476525 r2_inner = qmin ** 2
477526 r2_outer = qmax ** 2
478- i , j , k = np .meshgrid (np .arange (xdim ), np .arange (ydim ), np .arange (zdim ))
479- r2 = (i - xdim // 2 ) ** 2 + (j - ydim // 2 ) ** 2 + (k - zdim // 2 ) ** 2
480- mask = (r2 < r2_inner ) | (r2 > r2_outer ) # True if voxel is out of range
527+ i , j , k = np .meshgrid (
528+ np .arange (xdim ), np .arange (ydim ), np .arange (zdim )
529+ )
530+ r2 = (
531+ (i - xdim // 2 ) ** 2
532+ + (j - ydim // 2 ) ** 2
533+ + (k - zdim // 2 ) ** 2
534+ )
535+ mask = (r2 < r2_inner ) | (
536+ r2 > r2_outer
537+ ) # True if voxel is out of range
481538 sphere [mask ] = np .nan # therefore set to np.nan if out of range
482539
483540 if self .space .get ():
@@ -547,7 +604,9 @@ def animation(self):
547604 else :
548605 anispeed = self .anientry .get ()
549606 except ValueError :
550- print ("Oops... animation speed must be an integer > 0 or empty string." )
607+ print (
608+ "Oops... animation speed must be an integer > 0 or empty string."
609+ )
551610 n = self .plane_num .get () - 1
552611 while n is not self .plane_num .get ():
553612 self .slider .after (anispeed , self .plot_next_plane ())
0 commit comments