-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUITAR.py
6857 lines (5669 loc) · 306 KB
/
GUITAR.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# FR EXTRACTION GUI #
#importing relevant packages
from tkinter import *
from tkinter.ttk import *
import tkinter as tki
import tkinter.font
from tkinter.filedialog import askopenfilenames
import time
import numpy as np
import glob
import sys
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import pyvista as pv
import diplib as dip
from skimage import measure
import cv2
from matplotlib.animation import FuncAnimation
from PIL import ImageTk, Image
import os
# TO DO:
# add bbox_inches = tight to all savefig functions!
# add skip button to skip MM gradient and tracking?
# add analyse mode/function
# add merge points - mode
# add ability to select file type for saving plots (eps, png, pdf, ...)
# allow oblique twist/extraction planes - medium prio
# include stepsize for analysis?? - low prio
# show error messages (e.g., when nothing loaded in) - low prio
# allow different shapes for MM algs - low prio
# show pre-view of plot customization? - low prio
# visualize sampling - low prio
Name = 'GUITAR'
### Flashing Logo ###
wslogo = Tk()
#wslogo.geometry('496x388')
wslogo.overrideredirect(True)
wslogo.attributes("-topmost", True)
logo = ImageTk.PhotoImage(Image.open("GUITAR_LOGO.png"))
screen_width = wslogo.winfo_screenwidth()
screen_height = wslogo.winfo_screenheight()
logo_width = 496
logo_height = 388
x_logo = int((screen_width/2) - (logo_width/2))
y_logo = int((screen_height/2) - (logo_height/2))
wslogo.geometry("{}x{}+{}+{}".format(logo_width, logo_height, x_logo, y_logo))
panel = Label(wslogo, image = logo)
panel.pack(side = "bottom", fill = "both", expand = "yes")
def destroy_wslogo():
wslogo.destroy()
wslogo.after(3000, destroy_wslogo)
wslogo.mainloop()
### Window for asking operation mode ###
ws2 = Tk()
ws2.attributes("-topmost", True)
col2_px = 500
col3_px = 800
basecol1_px = 170
basecol2_px = 945
if sys.platform.startswith('linux'):
horsz = 1250
horsz_ws2 = 320
horsz_plotws = 340
saved_px = 1175
upload_px = 355
else:
horsz = 1200
horsz_ws2 = 260
saved_px = 1145
upload_px = 325
horsz_plotws = 300
ws2.geometry(str(horsz_ws2)+'x175')
default_font = tki.font.nametofont("TkDefaultFont")
default_font2 = tki.font.nametofont("TkTextFont")
default_font3 = tki.font.nametofont("TkFixedFont")
default_font.configure(size=9)
default_font2.configure(size=9)
default_font3.configure(size=9)
ws2.title("What Operation Mode?")
Style().configure("TButton", padding=1)
spacing = 1.05
wi = 9
#mode options
Modes = ('Full Extraction', 'Post-Processing', 'Get Source Points', 'Get Difference Map Points')
mode_var = tki.StringVar(value='')
mode_var.set(Modes)
#mode listbox
Label(ws2, text="Please indicate the mode you want to use: ").place(x = 20, y = 10)
listbox1 = tki.Listbox(ws2, listvariable = mode_var, width = 35, height=4, selectmode=tki.SINGLE)
listbox1.place(x = 20, y = 40)
#variable that controls which "main" window to open
selected_index = -1
#plotting variables:
#colormap strings
global cmaps
cmaps = []
for cmap_id in plt.colormaps():
cmaps.append(cmap_id)
global color_val
color_val = tki.StringVar(value='') #for colormap
color_val.set(tuple(cmaps))
#function to kill a window
def destroy_widget(widget):
widget.destroy()
#change listbox variable to the selected mode
def items_selected(event):
global selected_index
selected_index = listbox1.curselection()[0]
listbox1.bind('<<ListboxSelect>>', items_selected)
#destroy window if a mode is selected
def destroy_ws2(selected_index):
if selected_index != -1:
ws2.destroy()
def destroy_varws(varws, x_str, y_str, z_str, proxy_str):
testvar = 4
strings = [x_str, y_str, z_str, proxy_str]
for j in range(4):
if strings[j] == '':
testvar -= 1
if testvar == 4:
varws.destroy()
def destroy_varws2(varws, proxy_str):
if proxy_str != '':
varws.destroy()
#confirm-button which destroys the window if a mode has been selected
conf_btn = Button(ws2, text='Confirm', command = lambda:destroy_ws2(selected_index))
conf_btn.place(x = 85, y = 120)
ws2.mainloop()
####### main window ########
#open main window if corresponding mode is selected
if selected_index == 0:
ws = Tk()
ws.title(Name)
ws.geometry(str(horsz)+'x670')
default_font = tki.font.nametofont("TkDefaultFont")
default_font2 = tki.font.nametofont("TkTextFont")
default_font3 = tki.font.nametofont("TkFixedFont")
default_font.configure(size=9)
default_font2.configure(size=9)
default_font3.configure(size=9)
Style().configure("TButton", padding=1)
# create default values/pre-define variables
file_path = []
twist1 = []
num = 0
canv_num = 0
basename = tki.StringVar(value='')
x_str = tki.StringVar(value = '')
y_str = tki.StringVar(value = '')
z_str = tki.StringVar(value = '')
proxy_str = tki.StringVar(value = '')
spin_val = tki.StringVar(value=0)
spin2_val = tki.StringVar(value=0)
spin3_val = tki.StringVar(value=0)
spin4_val = tki.StringVar(value=0)
spin5_val = tki.StringVar(value=0)
spin6_val = tki.StringVar(value=0)
spin7_val = tki.StringVar(value=0)
spin8_val = tki.StringVar(value=0)
spin9_val = tki.StringVar(value=0)
x1_in = tki.StringVar(value = 0)
x2_in = tki.StringVar(value = 0)
y1_in = tki.StringVar(value = 0)
y2_in = tki.StringVar(value = 0)
x11_in = tki.StringVar(value = 0)
x22_in = tki.StringVar(value = 0)
y11_in = tki.StringVar(value = 0)
y22_in = tki.StringVar(value = 0)
xsteps = tki.StringVar(value = 0)
lower = tki.StringVar(value = 1)
upper = tki.StringVar(value = 2)
overlap = tki.StringVar(value = 0.1)
ope = tki.StringVar(value = 0)
ope2 = tki.StringVar(value = 0)
Thr = tki.StringVar(value = 0.8)
Thr2 = tki.StringVar(value = 1)
TwistPolarity = tki.StringVar(value=1)
#cX variables tell if a function has been called for the first time
#this has the purpose to create the widgets only once, to not overload the GUI with hidden widgets
c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
c11, c12, c13, c14, c15, c16, c17, c18, c19, c20 = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
c21 = 0
#file-types that can be read in
Allowed_Types = ('npz', 'npz+vtr', 'vtr (not recommended - slow!)')
type_var = tki.StringVar(value='')
type_var.set(Allowed_Types)
#listbox for selecting which file type to read in
type_lbl = Label(ws, text="Please indicate the type of files you want to load: ")
type_lbl.place(x = 20, y = 10)
listbox2 = tki.Listbox(ws, listvariable = type_var, height=3, width = 50, selectmode=tki.SINGLE)
listbox2.place(x = 20, y = 35)
#variable that controls what file type has been selected
selected_type = -1
# selection function
def type_selected(event):
global selected_type
selected_type = listbox2.curselection()[0]
listbox2.bind('<<ListboxSelect>>', type_selected)
#function that destroys selection and opens read-in process
def TypeDestroy():
if selected_type != -1:
destroy_widget(type_lbl)
destroy_widget(listbox2)
destroy_widget(conf_btn2)
#read in buttons for npz
if (selected_type == 0):
ws.wm_title(Name+" <Full Extraction Mode> npz")
addat = Label(ws, text='Load Proxy Maps as .npz:')
addat.place(x = 20, y = 10)
addatbtn = Button(ws, text ='Choose Files', command = lambda:open_file_npz())
addatbtn.place(in_ = addat, y = 0, relx = spacing)
varws = tki.Toplevel(ws)
varws.title("Variable Specifications")
varws.geometry(str(horsz_plotws)+'x200')
varws.attributes("-topmost", True)
varws.grab_set()
default_font = tki.font.nametofont("TkDefaultFont")
default_font2 = tki.font.nametofont("TkTextFont")
default_font3 = tki.font.nametofont("TkFixedFont")
default_font.configure(size=9)
default_font2.configure(size=9)
default_font3.configure(size=9)
xlabel = Label(varws, text = 'Insert Coordinate 1:')
xlabel.place(x = 20, y = 10)
xcoord = Entry(varws, textvariable = x_str, width = 10)
xcoord.place(in_ = xlabel, y = 0, relx = spacing)
ylabel = Label(varws, text = 'Insert Coordinate 2:')
ylabel.place(x = 20, y = 40)
ycoord = Entry(varws, textvariable = y_str, width = 10)
ycoord.place(in_ = ylabel, y = 0, relx = spacing)
zlabel = Label(varws, text = 'Insert Coordinate 3:')
zlabel.place(x = 20, y = 70)
zcoord = Entry(varws, textvariable = z_str, width = 10)
zcoord.place(in_ = zlabel, y = 0, relx = spacing)
proxy_label = Label(varws, text = 'Insert Proxy:')
proxy_label.place(x = 20, y = 100)
proxy_coord = Entry(varws, textvariable = proxy_str, width = 10)
proxy_coord.place(in_ = proxy_label, y = 0, relx = spacing)
conf_btn3 = Button(varws, text='Confirm', command = lambda:destroy_varws(varws, x_str.get(), y_str.get(), z_str.get(), proxy_str.get()))
conf_btn3.place(x = 110, y = 150)
upld = Button(ws, text='Load Files', command = lambda:uploadFiles_npz_only(file_path_npz, x_str.get(), y_str.get(), z_str.get(), proxy_str.get(), c1))
upld.place(in_ = addatbtn, y = 0, relx = spacing)
#read in buttons for vtr+npz
elif (selected_type == 1):
ws.wm_title(Name+" <Full Extraction Mode> vtr+npz")
addat = Label(ws, text='Load Proxy Maps as .vtr:')
addat.place(x = 20, y = 10)
addatbtn = Button(ws, text ='Choose Files', command = lambda:open_file())
addatbtn.place(in_ = addat, y = 0, relx = spacing)
upld = Button(ws, text='Load Files', command = lambda:uploadFiles(file_path))
upld.place(in_ = addatbtn, y = 0, relx = spacing)
varws = tki.Toplevel(ws)
varws.title("Variable Specifications")
varws.geometry(str(horsz_plotws)+'x100')
varws.grab_set()
default_font = tki.font.nametofont("TkDefaultFont")
default_font2 = tki.font.nametofont("TkTextFont")
default_font3 = tki.font.nametofont("TkFixedFont")
default_font.configure(size=9)
default_font2.configure(size=9)
default_font3.configure(size=9)
proxy_label = Label(varws, text = 'Insert Proxy:')
proxy_label.place(x = 20, y = 10)
proxy_coord = Entry(varws, textvariable = proxy_str, width = 10)
proxy_coord.place(in_ = proxy_label, y = 0, relx = spacing)
conf_btn3 = Button(varws, text='Confirm', command = lambda:destroy_varws2(varws, proxy_str.get()))
conf_btn3.place(x = 110, y = 60)
#read in buttons for vtr
elif (selected_type == 2):
ws.wm_title(Name+" <Full Extraction Mode> vtr")
addat = Label(ws, text='Load Proxy Maps as .vtr:')
addat.place(x = 20, y = 10)
addatbtn = Button(ws, text ='Choose Files', command = lambda:open_file())
addatbtn.place(in_ = addat, y = 0, relx = spacing)
upld = Button(ws, text='Load Files', command = lambda:uploadFiles_vtr(file_path, proxy_str.get(), c3))
upld.place(in_ = addatbtn, y = 0, relx = spacing)
varws = tki.Toplevel(ws)
varws.title("Variable Specifications")
varws.geometry(str(horsz_plotws)+'x100')
varws.grab_set()
default_font = tki.font.nametofont("TkDefaultFont")
default_font2 = tki.font.nametofont("TkTextFont")
default_font3 = tki.font.nametofont("TkFixedFont")
default_font.configure(size=9)
default_font2.configure(size=9)
default_font3.configure(size=9)
proxy_label = Label(varws, text = 'Insert Proxy:')
proxy_label.place(x = 20, y = 10)
proxy_coord = Entry(varws, textvariable = proxy_str, width = 10)
proxy_coord.place(in_ = proxy_label, y = 0, relx = spacing)
conf_btn3 = Button(varws, text='Confirm', command = lambda:destroy_varws2(varws, proxy_str.get()))
conf_btn3.place(x = 110, y = 60)
#confirm button to destroy the selection widget
conf_btn2 = Button(ws, text='Confirm', command = lambda:TypeDestroy())
conf_btn2.place(x = 110, y = 95)
#opens selected vtr files
def open_file():
global file_path
file_path = askopenfilenames(initialdir='./', filetypes=[('VTR Files', '*vtr')])
#opens selected npz files
def open_file_npz():
global file_path_npz
file_path_npz = askopenfilenames(initialdir='./', filetypes=[('NPZ Files', '*npz')])
#function for saving plots
def savefunc(Plotstr, contr, twist, filenames):
#invoke window to customize plotting options
plotws = tki.Toplevel(ws)
plotws.title("Plot Specifications")
plotws.geometry(str(horsz_plotws)+'x670')
plotws.grab_set()
default_font = tki.font.nametofont("TkDefaultFont")
default_font2 = tki.font.nametofont("TkTextFont")
default_font3 = tki.font.nametofont("TkFixedFont")
default_font.configure(size=9)
default_font2.configure(size=9)
default_font3.configure(size=9)
#Set colormap:
global cmap_to_use
cmap_to_use = "RdBu_r"
#enable listbox if customize option is on
def set_colormap(boxon):
if boxon % 2 == 1:
listbox3.config(state = "normal")
else:
listbox3.config(state = "disabled")
#customization checkbox
def_colormap = tki.IntVar(value = 0)
check_default_colormap = Checkbutton(plotws, text = "Customize", variable = def_colormap, command = lambda:set_colormap(def_colormap.get()))
check_default_colormap.place(x = 10, y = 90)
listbox3 = tki.Listbox(plotws, height=7, width = 25, selectmode=tki.SINGLE, exportselection=False)
#listbox for colormaps
for j in range(len(cmaps)):
listbox3.insert(tki.END, cmaps[j])
listbox3.place(x = 120, y = 35)
listbox3.config(state = "disabled")
colormap_lbl = Label(plotws, text = 'Choose Colormap:')
colormap_lbl.place(x = 120, y = 10)
#get selected colormap
def color_selected(event):
global cmap_to_use
cmap_to_use = cmaps[int(listbox3.curselection()[0])]
listbox3.bind('<<ListboxSelect>>', color_selected)
#Set figure size checkbox:
def_figsize = tki.IntVar(value = 0)
check_default_figsize = Checkbutton(plotws, text = "Customize", variable = def_figsize, command = lambda:set_figsize(def_figsize.get()))
check_default_figsize.place(x = 10, y = 180)
Label(plotws, text='Choose Figure Size:').place(x = 120, y = 180)
#default figure sizes
figure_x = tki.StringVar(value = "12")
figure_y = tki.StringVar(value = "12")
#entry boxes for figuresizes
xfig = Label(plotws, text = 'x =')
xfig.place(x = 120, y = 210)
Enter_figx = Entry(plotws, textvariable = figure_x, width = 4)
Enter_figx.place(in_ = xfig, y = 0, relx = spacing)
yfig = Label(plotws, text = 'y =')
yfig.place(in_ = Enter_figx, y = 0, relx = spacing)
Enter_figy = Entry(plotws, textvariable = figure_y, width = 4)
Enter_figy.place(in_ = yfig, y = 0, relx = spacing)
Enter_figx.config(state = "disabled")
Enter_figy.config(state = "disabled")
#enable/disable figure entry boxes
def set_figsize(boxon):
if boxon % 2 == 1:
Enter_figx.config(state = "normal")
Enter_figy.config(state = "normal")
else:
Enter_figx.config(state = "disabled")
Enter_figy.config(state = "disabled")
#same thing with the plot title:
def_title = tki.IntVar(value = 0)
check_default_title = Checkbutton(plotws, text = "Customize", variable = def_title, command = lambda:set_plottitle(def_title.get()))
check_default_title.place(x = 10, y = 240)
Label(plotws, text='Choose Figure Title:').place(x = 120, y = 240)
figure_title = tki.StringVar(value = "")
text_title = Text(plotws, height = 1, width = 20)
text_title.place(x = 120, y = 270)
text_title.config(state = "disabled")
def set_plottitle(boxon):
if boxon % 2 == 1:
text_title.config(state = "normal")
else:
text_title.config(state = "disabled")
#same thing with the titlesize
def_titlesize = tki.IntVar(value = 0)
check_default_titlesize = Checkbutton(plotws, text = "Customize", variable = def_titlesize, command = lambda:set_titlesize(def_titlesize.get()))
check_default_titlesize.place(x = 10, y = 300)
Label(plotws, text='Choose Title Size:').place(x = 120, y = 300)
titlesize = tki.StringVar(value = "14")
Enter_titlesize = Entry(plotws, textvariable = titlesize, width = 6)
Enter_titlesize.place(x = 120, y = 330)
Enter_titlesize.config(state = "disabled")
def set_titlesize(boxon):
if boxon % 2 == 1:
Enter_titlesize.config(state = "normal")
else:
Enter_titlesize.config(state = "disabled")
#Same thing with the ticksizes
def_ticksize = tki.IntVar(value = 0)
check_default_ticksize = Checkbutton(plotws, text = "Customize", variable = def_ticksize, command = lambda:set_ticksize(def_ticksize.get()))
check_default_ticksize.place(x = 10, y = 360)
Label(plotws, text='Choose Ticksize:').place(x = 120, y = 360)
ticksize = tki.StringVar(value = "14")
Enter_ticksize = Entry(plotws, textvariable = ticksize, width = 6)
Enter_ticksize.place(x = 120, y = 390)
Enter_ticksize.config(state = "disabled")
def set_ticksize(boxon):
if boxon % 2 == 1:
Enter_ticksize.config(state = "normal")
else:
Enter_ticksize.config(state = "disabled")
#Same thing with the axis labels
def_label = tki.IntVar(value = 0)
check_default_label = Checkbutton(plotws, text = "Customize", variable = def_label, command = lambda:set_label(def_label.get()))
check_default_label.place(x = 10, y = 420)
Label(plotws, text='Choose Labels:').place(x = 120, y = 420)
label_x = tki.StringVar(value = "")
label_y = tki.StringVar(value = "")
axx_lbl = Label(plotws, text = 'x =')
axx_lbl.place(x = 120, y = 450)
Enter_labelx = Entry(plotws, textvariable = label_x, width = 6)
Enter_labelx.place(in_ = axx_lbl, y = 0, relx = spacing)
axy_lbl = Label(plotws, text = 'y =')
axy_lbl.place(in_ = Enter_labelx, y = 0, relx = spacing)
Enter_labely = Entry(plotws, textvariable = label_y, width = 6)
Enter_labely.place(in_ = axy_lbl, y = 0, relx = spacing)
Enter_labelx.config(state = "disabled")
Enter_labely.config(state = "disabled")
def set_label(boxon):
if boxon % 2 == 1:
Enter_labelx.config(state = "normal")
Enter_labely.config(state = "normal")
else:
Enter_labelx.config(state = "disabled")
Enter_labely.config(state = "disabled")
#same thing with the axis labelsize
def_labelsize = tki.IntVar(value = 0)
check_default_labelsize = Checkbutton(plotws, text = "Customize", variable = def_labelsize, command = lambda:set_labelsize(def_labelsize.get()))
check_default_labelsize.place(x = 10, y = 480)
Label(plotws, text='Choose Labelsize:').place(x = 120, y = 480)
labelsize = tki.StringVar(value = "14")
Enter_labelsize = Entry(plotws, textvariable = labelsize, width = 6)
Enter_labelsize.place(x = 120, y = 510)
Enter_labelsize.config(state = "disabled")
def set_labelsize(boxon):
if boxon % 2 == 1:
Enter_labelsize.config(state = "normal")
else:
Enter_labelsize.config(state = "disabled")
#Setting vmin/vmax values for the colormap
def_minmax = tki.IntVar(value = 0)
check_default_minmax = Checkbutton(plotws, text = "Customize", variable = def_minmax, command = lambda:set_minmax(def_minmax.get()))
check_default_minmax.place(x = 10, y = 540)
Label(plotws, text='Choose Colormap Limits:').place(x = 120, y = 540)
vmin = tki.IntVar(value = -5)
vmax = tki.IntVar(value = 5)
vmin_lbl = Label(plotws, text = 'vmin =')
vmin_lbl.place(x = 120, y = 570)
Enter_vmin = Entry(plotws, textvariable = vmin, width = 4)
Enter_vmin.place(in_ = vmin_lbl, y = 0, relx = spacing)
vmax_lbl = Label(plotws, text = 'vmax =')
vmax_lbl.place(in_ = Enter_vmin, y = 0, relx = spacing)
Enter_vmax = Entry(plotws, textvariable = vmax, width = 4)
Enter_vmax.place(in_ = vmax_lbl, y = 0, relx = spacing)
Enter_vmin.config(state = "disabled")
Enter_vmax.config(state = "disabled")
def set_minmax(boxon):
if boxon % 2 == 1:
Enter_vmin.config(state = "normal")
Enter_vmax.config(state = "normal")
else:
Enter_vmin.config(state = "disabled")
Enter_vmax.config(state = "disabled")
format_lbl = Label(plotws, text = 'Choose Image Format: ')
format_lbl.place(x = 10, y = 600)
formatlist = ["png", "eps", "pdf"]
current_format = tki.StringVar()
current_format.set(formatlist[0])
FormatBox = Combobox(plotws, textvariable = current_format, values = formatlist, state = 'readonly', width = 4)
FormatBox.place(in_ = format_lbl, y = 0, relx = spacing)
#confirm button to grab all variables from customization window and to destroy this window
conf_btn3 = Button(plotws, text='Confirm', command = lambda:destroy_widget_2(plotws, def_colormap.get(), def_figsize.get(), def_title.get(), \
def_titlesize.get(), def_ticksize.get(), def_label.get(), def_labelsize.get(), def_minmax.get(), figure_x.get(), figure_y.get(), text_title.get('1.0','end-1c'), titlesize.get(), \
ticksize.get(), label_x.get(), label_y.get(), labelsize.get(), vmin.get(), vmax.get(), cmap_to_use, current_format.get()))
conf_btn3.place(x = 120, y = 635)
#plotting+saving function, which saves the plot and destroys the customization window
#boxonX are the variables communicating to the plotting function if the customization checkbox was on or off
def destroy_widget_2(widget, boxon1, boxon2, boxon3, boxon4, boxon5, boxon6, boxon7, boxon8, figx, figy, title_name, titlesize, ticksize, labelx, labely,\
labelsize, vmin, vmax, cmap_to_use, format_):
L = len(twist)
#if not customized, use default values/settings:
if boxon1 % 2 == 0:
cmap_to_use = "RdBu_r"
if boxon2 % 2 == 0:
figx = dim[1]/50
figy = dim[0]/50
else:
figx = int(figx)
figy = int(figy)
if boxon4 % 2 == 0:
titlesize = 14
else:
titlesize = int(titlesize)
if boxon5 % 2 == 0:
ticksize = 14
else:
ticksize = int(ticksize)
if boxon7 % 2 == 0:
labelsize = 14
else:
labelsize = int(labelsize)
#plotting and saving the figuresizes
#Plotstr controls which array to plot
#contr tells which dimensions (for cartesian: x, y, z) to use
for j in range(L):
fig = Figure(figsize=(figx, figy))
plot1 = fig.add_subplot(111)
if Plotstr == 'Tw':
if contr == 'X':
if boxon8 % 2 == 0:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = -5, vmax = 5, extent = [MinX, MaxX, MinZ, MaxZ])
else:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = vmin, vmax = vmax, extent = [MinX, MaxX, MinZ, MaxZ])
if boxon3 % 2 == 0:
plot1.set_title("Proxy map no. "+str(j), fontsize = titlesize)
else:
plot1.set_title(title_name, fontsize = titlesize)
if boxon6 % 2 == 0:
plot1.set_ylabel("y", fontsize = labelsize)
plot1.set_xlabel("x", fontsize = labelsize)
else:
plot1.set_ylabel(labely, fontsize = labelsize)
plot1.set_xlabel(labelx, fontsize = labelsize)
plot1.tick_params(labelsize = ticksize)
fig.savefig(filenames+str(j)+'.'+ format_, bbox_inches = "tight")
elif contr == 'Y':
if boxon8 % 2 == 0:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = -5, vmax = 5, extent = [MinY, MaxY, MinZ, MaxZ])
else:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = vmin, vmax = vmax, extent = [MinY, MaxY, MinZ, MaxZ])
if boxon3 % 2 == 0:
plot1.set_title("Proxy map no. "+str(j), fontsize = titlesize)
else:
plot1.set_title(title_name, fontsize = titlesize)
if boxon6 % 2 == 0:
plot1.set_ylabel("y", fontsize = labelsize)
plot1.set_xlabel("x", fontsize = labelsize)
else:
plot1.set_ylabel(labely, fontsize = labelsize)
plot1.set_xlabel(labelx, fontsize = labelsize)
plot1.tick_params(labelsize = ticksize)
fig.savefig(filenames+str(j)+'.'+ format_, bbox_inches = "tight")
elif contr == 'Z':
if boxon8 % 2 == 0:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = -5, vmax = 5, extent = [MinX, MaxX, MinY, MaxY])
else:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = vmin, vmax = vmax, extent = [MinX, MaxX, MinY, MaxY])
if boxon3 % 2 == 0:
plot1.set_title("Proxy map no. "+str(j), fontsize = titlesize)
else:
plot1.set_title(title_name, fontsize = titlesize)
if boxon6 % 2 == 0:
plot1.set_ylabel("y", fontsize = labelsize)
plot1.set_xlabel("x", fontsize = labelsize)
else:
plot1.set_ylabel(labely, fontsize = labelsize)
plot1.set_xlabel(labelx, fontsize = labelsize)
plot1.tick_params(labelsize = ticksize)
fig.savefig(filenames+str(j)+'.'+ format_, bbox_inches = "tight")
elif Plotstr == 'GrdTw':
if contr == 'X':
if boxon8 % 2 == 0:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = -5, vmax = 5, extent = [MinX, MaxX, MinZ, MaxZ])
else:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = vmin, vmax = vmax, extent = [MinX, MaxX, MinZ, MaxZ])
if boxon3 % 2 == 0:
plot1.set_title("Gradient+Twist no. "+str(j), fontsize = titlesize)
else:
plot1.set_title(title_name, fontsize = titlesize)
if boxon6 % 2 == 0:
plot1.set_ylabel("y", fontsize = labelsize)
plot1.set_xlabel("x", fontsize = labelsize)
else:
plot1.set_ylabel(labely, fontsize = labelsize)
plot1.set_xlabel(labelx, fontsize = labelsize)
plot1.tick_params(labelsize = ticksize)
fig.savefig(filenames+str(j)+'.'+ format_, bbox_inches = "tight")
elif contr == 'Y':
if boxon8 % 2 == 0:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = -5, vmax = 5, extent = [MinY, MaxY, MinZ, MaxZ])
else:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = vmin, vmax = vmax, extent = [MinY, MaxY, MinZ, MaxZ])
if boxon3 % 2 == 0:
plot1.set_title("Gradient+Twist no. "+str(j), fontsize = titlesize)
else:
plot1.set_title(title_name, fontsize = titlesize)
if boxon6 % 2 == 0:
plot1.set_ylabel("y", fontsize = labelsize)
plot1.set_xlabel("x", fontsize = labelsize)
else:
plot1.set_ylabel(labely, fontsize = labelsize)
plot1.set_xlabel(labelx, fontsize = labelsize)
plot1.tick_params(labelsize = ticksize)
fig.savefig(filenames+str(j)+'.'+ format_, bbox_inches = "tight")
elif contr == 'Z':
if boxon8 % 2 == 0:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = -5, vmax = 5, extent = [MinX, MaxX, MinY, MaxY])
else:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = vmin, vmax = vmax, extent = [MinX, MaxX, MinY, MaxY])
if boxon3 % 2 == 0:
plot1.set_title("Gradient+Twist no. "+str(j), fontsize = titlesize)
else:
plot1.set_title(title_name, fontsize = titlesize)
if boxon6 % 2 == 0:
plot1.set_ylabel("y", fontsize = labelsize)
plot1.set_xlabel("x", fontsize = labelsize)
else:
plot1.set_ylabel(labely, fontsize = labelsize)
plot1.set_xlabel(labelx, fontsize = labelsize)
plot1.tick_params(labelsize = ticksize)
fig.savefig(filenames+str(j)+'.'+ format_, bbox_inches = "tight")
elif Plotstr == 'track':
if contr == 'X':
if boxon8 % 2 == 0:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = 0, vmax = 1.5, extent = [MinX, MaxX, MinZ, MaxZ])
else:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = vmin, vmax = vmax, extent = [MinX, MaxX, MinZ, MaxZ])
if boxon3 % 2 == 0:
plot1.set_title("Tracked Shape, Frame "+str(j), fontsize = titlesize)
else:
plot1.set_title(title_name, fontsize = titlesize)
if boxon6 % 2 == 0:
plot1.set_ylabel("y", fontsize = labelsize)
plot1.set_xlabel("x", fontsize = labelsize)
else:
plot1.set_ylabel(labely, fontsize = labelsize)
plot1.set_xlabel(labelx, fontsize = labelsize)
plot1.tick_params(labelsize = ticksize)
fig.savefig(filenames+str(j)+'.'+ format_, bbox_inches = "tight")
elif contr == 'Y':
if boxon8 % 2 == 0:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = 0, vmax = 1.5, extent = [MinY, MaxY, MinZ, MaxZ])
else:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = vmin, vmax = vmax, extent = [MinY, MaxY, MinZ, MaxZ])
if boxon3 % 2 == 0:
plot1.set_title("Tracked Shape, Frame "+str(j), fontsize = titlesize)
else:
plot1.set_title(title_name, fontsize = titlesize)
if boxon6 % 2 == 0:
plot1.set_ylabel("y", fontsize = labelsize)
plot1.set_xlabel("x", fontsize = labelsize)
else:
plot1.set_ylabel(labely, fontsize = labelsize)
plot1.set_xlabel(labelx, fontsize = labelsize)
plot1.tick_params(labelsize = ticksize)
fig.savefig(filenames+str(j)+'.'+ format_, bbox_inches = "tight")
if contr == 'Z':
if boxon8 % 2 == 0:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = 0, vmax = 1.5, extent = [MinX, MaxX, MinY, MaxY])
else:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = vmin, vmax = vmax, extent = [MinX, MaxX, MinY, MaxY])
if boxon3 % 2 == 0:
plot1.set_title("Tracked Shape, Frame "+str(j), fontsize = titlesize)
else:
plot1.set_title(title_name, fontsize = titlesize)
if boxon6 % 2 == 0:
plot1.set_ylabel("y", fontsize = labelsize)
plot1.set_xlabel("x", fontsize = labelsize)
else:
plot1.set_ylabel(labely, fontsize = labelsize)
plot1.set_xlabel(labelx, fontsize = labelsize)
plot1.tick_params(labelsize = ticksize)
fig.savefig(filenames+str(j)+'.'+ format_, bbox_inches = "tight")
elif Plotstr == 'processed':
if contr == 'X':
if boxon8 % 2 == 0:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = 0, vmax = 1.5, extent = [MinX, MaxX, MinZ, MaxZ])
else:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = vmin, vmax = vmax, extent = [MinX, MaxX, MinZ, MaxZ])
if boxon3 % 2 == 0:
plot1.set_title("Tracked Shape, Frame "+str(j), fontsize = titlesize)
else:
plot1.set_title(title_name, fontsize = titlesize)
if boxon6 % 2 == 0:
plot1.set_ylabel("y", fontsize = labelsize)
plot1.set_xlabel("x", fontsize = labelsize)
else:
plot1.set_ylabel(labely, fontsize = labelsize)
plot1.set_xlabel(labelx, fontsize = labelsize)
plot1.tick_params(axis='both', which='major', labelsize = ticksize)
fig.savefig(filenames+str(j)+'.'+ format_, bbox_inches = "tight")
elif contr == 'Y':
if boxon8 % 2 == 0:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = 0, vmax = 1.5, extent = [MinY, MaxY, MinZ, MaxZ])
else:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = vmin, vmax = vmax, extent = [MinY, MaxY, MinZ, MaxZ])
if boxon3 % 2 == 0:
plot1.set_title("Tracked Shape, Frame "+str(j), fontsize = titlesize)
else:
plot1.set_title(title_name, fontsize = titlesize)
if boxon6 % 2 == 0:
plot1.set_ylabel("y", fontsize = labelsize)
plot1.set_xlabel("x", fontsize = labelsize)
else:
plot1.set_ylabel(labely, fontsize = labelsize)
plot1.set_xlabel(labelx, fontsize = labelsize)
plot1.tick_params(axis='both', which='major', labelsize = ticksize)
fig.savefig(filenames+str(j)+'.'+ format_, bbox_inches = "tight")
elif contr == 'Z':
if boxon8 % 2 == 0:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = 0, vmax = 1.5, extent = [MinX, MaxX, MinY, MaxY])
else:
plot1.imshow(twist[j], origin = "lower", cmap = cmap_to_use, vmin = vmin, vmax = vmax, extent = [MinX, MaxX, MinY, MaxY])
if boxon3 % 2 == 0:
plot1.set_title("Tracked Shape, Frame "+str(j), fontsize = titlesize)
else:
plot1.set_title(title_name, fontsize = titlesize)
if boxon6 % 2 == 0:
plot1.set_ylabel("y", fontsize = labelsize)
plot1.set_xlabel("x", fontsize = labelsize)
else:
plot1.set_ylabel(labely, fontsize = labelsize)
plot1.set_xlabel(labelx, fontsize = labelsize)
plot1.tick_params(axis='both', which='major', labelsize = ticksize)
fig.savefig(filenames+str(j)+'.'+ format_, bbox_inches = "tight")
#correctly place label to indicate that the plot was indeed saved
save_lbl = Label(ws, text = 'Saved!', foreground = 'green')
if Plotstr == 'Tw':
save_lbl.place(x = 420, y = 500)
elif Plotstr == 'GrdTw':
save_lbl.place(x = 420, y = 560)
elif (Plotstr == 'processed'):
save_lbl.place(x = saved_px, y = 280)
elif (Plotstr == 'Open'):
save_lbl.place(x = saved_px, y = 280)
elif (Plotstr == 'track'):
save_lbl.place(x = saved_px, y = 280)
#destroy the "saved" label
ws.after(2000, destroy_widget, save_lbl)
plotws.destroy()
def savearr(arr, filename, Plotstr):
L = len(arr)
if contr == 'X':
x_vec = np.linspace(MinX, MaxX, dim[1])
z_vec = np.linspace(MinZ, MaxZ, dim[0])
np.savez(filename+".npz", data = arr, x = x_vec, y = [yy], z = z_vec)
elif contr == 'Y':
y_vec = np.linspace(MinY, MaxY, dim[1])
z_vec = np.linspace(MinZ, MaxZ, dim[0])
np.savez(filename+".npz", data = arr, x = [xx], y = y_vec, z = z_vec)
elif contr == 'Z':
y_vec = np.linspace(MinY, MaxY, dim[0])
x_vec = np.linspace(MinX, MaxX, dim[1])
np.savez(filename+".npz", data = arr, x = x_vec, y = y_vec, z = [zz])
save_lbl = Label(ws, text = 'Saved!', foreground = 'green')
if Plotstr == 'GrdTw':
save_lbl.place(x = 420, y = 590)
elif (Plotstr == 'processed'):
save_lbl.place(x = saved_px, y = 310)
elif (Plotstr == 'Tw'):
save_lbl.place(x = 420, y = 500)
ws.after(2000, destroy_widget, save_lbl)
def uploadFiles_npz_only(file_path_npz, x_str, y_str, z_str, proxy_str, c):
Test = []
global twist1
twist1 = []
for j in range(0, len(file_path_npz)):
Test.append(np.load(file_path_npz[j], allow_pickle = True))
twist1.append(np.transpose(Test[int(j)][proxy_str]))
global dim, MinX, MaxX, MinY, MaxY, MinZ, MaxZ, dx, dy, dz, contr
#keylist = list(Test.keys())
if ((len(Test[0][x_str]) > 1) & (len(Test[0][y_str]) > 1)):
global zz
zz = Test[0][z_str]
#print(np.shape(Test[0]['z']))
dim = [len(Test[0][y_str]), len(Test[0][x_str])]
MinX = min(Test[0][x_str])
MaxX = max(Test[0][x_str])
MX = (MaxX-MinX)
dx = MX/(dim[1]-1)
MinY = min(Test[0][y_str])
MaxY = max(Test[0][y_str])
MY = (MaxY-MinY)
dy = MY/(dim[0]-1)
contr = 'Z'
elif (len(Test[0][x_str]) > 1):
global yy
yy = Test[0][y_str]
#print(np.shape(Test[0]['x']))
dim = [len(Test[0][z_str]), len(Test[0][x_str])]
MinX = min(Test[0][x_str])
MaxX = max(Test[0][x_str])
MX = (MaxX-MinX)
dx = MX/(dim[1]-1)
MinZ = min(Test[0][z_str])
MaxZ = max(Test[0][z_str])
MZ = (MaxZ-MinZ)
dz = MZ/(dim[0]-1)
contr = 'X'
elif (len(Test[0][y_str]) > 1):
global xx
xx = Test[0][x_str]
dim = [len(Test[0][z_str]), len(Test[0][y_str])]
MinY = min(Test[0][y_str])
MaxY = max(Test[0][y_str])
MY = (MaxY-MinY)
dy = MY/(dim[1]-1)
MinZ = min(Test[0][z_str])
MaxZ = max(Test[0][z_str])
MZ = (MaxZ-MinZ)
dz = MZ/(dim[0]-1)
contr = 'Y'
Uploadnpz_lbl = Label(ws, text='Files Loaded Successfully!', foreground='green')
Uploadnpz_lbl.place(x = 165, y = 40)
ws.after(2000, destroy_widget, Uploadnpz_lbl)
if c == 0:
global Im_lbl
Im_lbl = Label(ws, text = 'Choose Image Frame no.:')
Im_lbl.place(x = 20, y = 70)
global spin
spin = Spinbox(ws, from_ = 0, to = len(file_path_npz)-1, textvariable = spin_val, wrap = True, width = wi)
spin.place(in_ = Im_lbl, y = 0, relx = spacing)
global vis_btn
vis_btn = Button(ws, text='Visualize Proxy', command = lambda:Vis(contr, twist1, spin_val.get(), canv_num, c4, c5))
vis_btn.place(in_ = spin, y = 0, relx = spacing)
else:
spin.destroy()
spin = Spinbox(ws, from_ = 0, to = len(file_path_npz)-1, textvariable = spin_val, wrap = True, width = wi)
spin.place(in_ = Im_lbl, y = 0, relx = spacing)
vis_btn.destroy()
vis_btn = Button(ws, text='Visualize Proxy', command = lambda:Vis(contr, twist1, spin_val.get(), canv_num, c4, c5))
vis_btn.place(in_ = spin, y = 0, relx = spacing)
global c1
c1 = 1
def uploadFiles_npz(file_path_npz, proxy_str, c):
Test = []
global twist1
twist1 = []
for j in range(0, len(file_path_npz)):
Test.append(np.load(file_path_npz[j], allow_pickle = True))
twist1.append(np.transpose(Test[int(j)][proxy_str]))
Uploadnpz_lbl = Label(ws, text='Files Loaded Successfully!', foreground='green')
Uploadnpz_lbl.place(x = upload_px, y = 40)
ws.after(2000, destroy_widget, Uploadnpz_lbl)
if c == 0:
global Im_lbl
Im_lbl = Label(ws, text = 'Choose Image Frame no.:')
Im_lbl.place(x = 20, y = 70)
global spin
spin = Spinbox(ws, from_ = 0, to = len(file_path_npz)-1, textvariable = spin_val, wrap = True, width = wi)