5
5
import matplotlib
6
6
import numpy as np
7
7
from 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
+ )
9
12
10
13
matplotlib .use ("tkagg" )
11
14
@@ -24,15 +27,21 @@ def initUI(self):
24
27
"""Initialize the GUI for fourigui."""
25
28
26
29
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
+ )
29
36
self .transcutted = False # denotes whether cutoff frequencies are applied and Fourier transformed
30
37
31
38
self .master .title ("FouriGUI" )
32
39
self .pack (fill = tk .BOTH , expand = True )
33
40
34
41
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
+ )
36
45
37
46
# 4 frames:
38
47
# frame 00: all buttons
@@ -54,7 +63,9 @@ def initUI(self):
54
63
self .filename_entry .grid (row = 0 , column = 1 , columnspan = 3 )
55
64
self .filename_entry .insert (0 , "/path/data.h5" )
56
65
57
- loadbutton = Button (frame00 , text = "load" , command = lambda : self .load_cube ())
66
+ loadbutton = Button (
67
+ frame00 , text = "load" , command = lambda : self .load_cube ()
68
+ )
58
69
loadbutton .grid (row = 0 , column = 4 )
59
70
60
71
# row 1: change axis area
@@ -125,7 +136,9 @@ def initUI(self):
125
136
self .colorbarmax .grid (row = 3 , column = 3 )
126
137
self .colorbarmin = tk .Entry (frame00 , width = 7 )
127
138
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
+ )
129
142
set_range .grid (row = 2 , column = 4 )
130
143
toglobalmax = Button (
131
144
frame00 ,
@@ -151,7 +164,9 @@ def initUI(self):
151
164
anilabel .grid (row = 7 , column = 3 , columnspan = 2 , sticky = tk .W )
152
165
self .anientry = tk .Entry (frame00 , width = 7 )
153
166
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
+ )
155
170
anibutton .grid (row = 8 , column = 4 )
156
171
157
172
# row 10-12 Fourier transformation
@@ -170,7 +185,9 @@ def initUI(self):
170
185
self .qmaxentry = tk .Entry (frame00 , width = 7 )
171
186
self .qmaxentry .grid (row = 12 , column = 3 )
172
187
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
+ )
174
191
newcutoffbutton .grid (row = 10 , column = 4 )
175
192
cutoffon = tk .Radiobutton (
176
193
frame00 ,
@@ -225,33 +242,45 @@ def initUI(self):
225
242
label = "slider" ,
226
243
orient = tk .HORIZONTAL ,
227
244
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
+ ),
229
248
)
230
249
# 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
+ )
232
253
233
254
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
+ )
235
258
236
259
self .frame01_toolbar = tk .Frame (self .frame01 )
237
260
self .frame01_toolbar .grid (row = 2 , column = 0 )
238
261
239
262
# 10 #
240
263
# frame 10, lower left
241
264
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)
243
268
quit = Button (
244
269
frame10 ,
245
270
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
+ ),
247
274
)
248
275
quit .pack (side = tk .TOP )
249
276
250
277
# 11 #
251
278
# frame 00, lower right
252
279
# no functionality
253
280
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)
255
284
256
285
def load_cube (self ):
257
286
"""Loads 3D array in h5py file format from the filename input panel 3D
@@ -285,9 +314,13 @@ def load_cube(self):
285
314
label = "slider" ,
286
315
orient = tk .HORIZONTAL ,
287
316
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
289
323
)
290
- self .slider .grid (row = 0 , column = 0 , padx = 10 , pady = 10 , sticky = tk .N + tk .E + tk .S + tk .W )
291
324
292
325
if not self .loaded :
293
326
fig , ax = plt .subplots (figsize = (4.95 , 4.95 ))
@@ -307,13 +340,17 @@ def load_cube(self):
307
340
ax .set_xlabel ("pixel" )
308
341
ax .set_ylabel ("pixel" )
309
342
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
+ )
311
346
self .toolbar .pack (side = tk .LEFT )
312
347
# self.toolbar.children['!button6'].pack_forget()
313
348
# self.toolbar.children['!button7'].pack_forget()
314
349
self .toolbar .update ()
315
350
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
+ )
317
354
self .loaded = True
318
355
else :
319
356
self .plot_plane ()
@@ -367,18 +404,30 @@ def intensity_upd_local(self):
367
404
elif self .axis .get () == 2 :
368
405
plane = self .cube [:, :, self .plane_num .get ()]
369
406
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
+ )
373
416
self .localnanratio ["text" ] = f"{ round (nan_ratio , 2 )} "
374
417
375
418
def intensity_upd_global (self ):
376
419
"""Load global intensity minimum, maximum and sum of 3D array."""
377
420
self .intensity_upd_local ()
378
421
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
+ )
382
431
self .globalnanratio ["text" ] = "{}" .format (round (nan_ratio , 2 ))
383
432
384
433
def fft (self ):
@@ -475,9 +524,17 @@ def applycutoff(self):
475
524
# convert qmax to pixels
476
525
r2_inner = qmin ** 2
477
526
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
481
538
sphere [mask ] = np .nan # therefore set to np.nan if out of range
482
539
483
540
if self .space .get ():
@@ -547,7 +604,9 @@ def animation(self):
547
604
else :
548
605
anispeed = self .anientry .get ()
549
606
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
+ )
551
610
n = self .plane_num .get () - 1
552
611
while n is not self .plane_num .get ():
553
612
self .slider .after (anispeed , self .plot_next_plane ())
0 commit comments