-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu_utils.py
835 lines (638 loc) · 27.7 KB
/
menu_utils.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
from tkinter import *
from tkinter import filedialog as tkFileDialog
#from tkFileDialog import askopenfilename
import numpy as np
from utils import *
def NewFile(root):
for k, ele in enumerate(root.winfo_children()):
if k>0: ele.destroy()
print ("New File!... (not implemented)")
return
Label(root, text="First Name").grid(row=0)
Label(root, text="Last Name").grid(row=1)
e1 = Entry(root)
e2 = Entry(root)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
print (e1.text())
def Defaults(root):
for k, ele in enumerate(root.winfo_children()):
if k>0: ele.destroy()
#******** Select CaImAn folder
def button00():
print ("...selecting caiman folder location...")
root.caiman_folder = tkFileDialog.askdirectory(initialdir=root.caiman_folder, title="Select CaImAn Root Directory")
print ("Changing caiman_folder to: ", root.caiman_folder)
np.savetxt('caiman_folder_location.txt',[root.caiman_folder], fmt="%s")
e0.delete(0, END)
e0.insert(0, root.caiman_folder)
b00 = Button(root, text="Set CaImAn Folder", anchor="w", command=button00) #Label(root, text="Filename: ").grid(row=0)
b00.place(x=0,y=0)
e0 = Entry(root, justify='left') #text entry for the filename
e0.delete(0, END)
e0.insert(0, root.caiman_folder)
e0.place(x=150,y=0, width=600)
#******** Filename Selector
def button0():
print ("...selecting data folder...")
root.data_folder = tkFileDialog.askdirectory(initialdir=root.data_folder, title="Select data directory")
np.savetxt('data_folder_location.txt',[root.data_folder], fmt="%s")
e.delete(0, END)
e.insert(0, root.data_folder)
#root.title(root.data_folder)
b0 = Button(root, text="Default data dir:", anchor="w", command=button0) #Label(root, text="Filename: ").grid(row=0)
b0.place(x=0, y=30)
e = Entry(root, justify='left') #text entry for the filename
e.delete(0, END)
e.insert(0, root.data_folder)
e.place(x=150,y=30, width=600)
def Tif_merge(root):
for k, ele in enumerate(root.winfo_children()):
if k>0: ele.destroy()
print ("Merging tifs from list of filenames")
root.minsize(width=800, height=500)
root.data = emptyObject()
#******** Select filename:
def button0():
print ("...selecting .txt containing list of .tif files...")
#root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data.root_dir)
root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data_folder, defaultextension=".txt", filetypes=(("txt", "*.txt"),("All Files", "*.*") ))
e1.delete(0, END)
e1.insert(0, root.data.file_name)
#root.title(os.path.split(root.data.file_name)[1])
b0 = Button(root, text="Filename: ", command=button0) #Label(root, text="Filename: ").grid(row=0)
b0.grid(row=0,column=0)
e1 = Entry(root, justify='left') #text entry for the filename
e1.delete(0, END)
e1.insert(0, '')
e1.grid(row=0, column=1)
e1.place(x=120,width=800)
def button1():
print ("...merging files from list: ", root.data.file_name)
merge_tifs(root.data.file_name)
#os.system("python ../CaImAn/demo_OnACID.py "+root.data.file_name)
print ("... done!")
#******** Run review ROIs function
b1 = Button(root, text="merge tifs", command=button1)
b1.grid(row=1, column=0)
def Louvain_modularity(root):
print ("...compute louvain modularity ...")
for k, ele in enumerate(root.winfo_children()):
if k>0: ele.destroy()
root.data = emptyObject()
root.data.file_name = ''
root.title("Louvain Modularity")
#******** Select filename:
def button0():
print ("...select threshold file from foopsi output...")
root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data_folder, defaultextension="*thr*.npz", filetypes=(("npz", "*.npz"),("All Files", "*.*") ))
e1.delete(0, END)
e1.insert(0, root.data.file_name)
root.title(os.path.split(root.data.file_name)[1])
b0 = Button(root, text="Foopsi filename: ", command=button0) #Label(root, text="Filename: ").grid(row=0)
b0.grid(row=0, column=0)
e1 = Entry(root) #text entry for the filename
e1.delete(0, END)
e1.insert(0, root.data.file_name)
#e1.grid(row=0, column=2)
e1.place(x=150, y=3,width=800)
#******** Correct ROIs
def button1():
#correct_ROIs(root.data.file_name, root.data.A, root.data.Cn, thr=0.95)
louvain_compute(root)
b1 = Button(root, text="Run Louvain", command=button1, justify='left')
b1.place(x=0, y=30)
#******** Select filename:
def button00():
print ("...select network file post louvain...")
root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data_folder, defaultextension="*network*.npy", filetypes=(("npy", "*.npy"),("All Files", "*.*") ))
e2.delete(0, END)
e2.insert(0, root.data.file_name)
root.title(os.path.split(root.data.file_name)[1])
b00 = Button(root, text="Louvain filename: ", command=button00) #Label(root, text="Filename: ").grid(row=0)
#b00.grid(row=140,column=100)
b00.place(x=0,y=70)
e2 = Entry(root) #text entry for the filename
e2.delete(0, END)
e2.insert(0, root.data.file_name)
#e2.grid(row=15, column=15)
e2.place(x=150, y=73,width=800)
#******** Visualize Results
def button2():
print ("...loading processed file: ", root.data.file_name)
visualize_louvain(root)
b2 = Button(root, text="Visualize Louvain", command=button2, justify='left')
b2.place(x=0, y=100)
pass
def Tif_convert(root):
for k, ele in enumerate(root.winfo_children()):
if k>0: ele.destroy()
print ("Converting tif to .npy")
root.minsize(width=800, height=500)
root.data = emptyObject()
#root.data.root_dir = '/media/cat/4TB/in_vivo/rafa/alejandro/G2M5/20170511/000/'
#root.data.file_name = '/media/cat/4TB/in_vivo/rafa/alejandro/G2M5/20170511/000/Registered.tif'
#******** Select filename:
def button0():
print ("...selecting file...")
#root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data.root_dir)
root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data_folder, defaultextension=".tif", filetypes=(("tif", "*.tif"),("All Files", "*.*") ))
e1.delete(0, END)
e1.insert(0, root.data.file_name)
#root.title(os.path.split(root.data.file_name)[1])
b0 = Button(root, text="Filename: ", command=button0) #Label(root, text="Filename: ").grid(row=0)
b0.grid(row=0,column=0)
e1 = Entry(root, justify='left') #text entry for the filename
e1.delete(0, END)
e1.insert(0, '')
e1.grid(row=0, column=1)
e1.place(x=120,width=800)
def button1():
print ("...converting: ", root.data.file_name)
convert_tif_npy(root.data.file_name)
#os.system("python ../CaImAn/demo_OnACID.py "+root.data.file_name)
print ("... done!")
#******** Run review ROIs function
b1 = Button(root, text="convert tif->npy", command=button1)
b1.grid(row=1, column=0)
def Tif_sequence_load(root):
for k, ele in enumerate(root.winfo_children()):
if k>0: ele.destroy()
print ("Loading .tif sequence")
print ("... buggy... not yet fixed...(tiffilfe seems to give errors...)")
return
root.minsize(width=1200, height=500)
root.data = emptyObject()
#******** Select filename:
def button0():
print ("...selecting file...")
#root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data.root_dir)
root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data_folder, defaultextension=".tif", filetypes=(("tif", "*.tif"),("All Files", "*.*") ))
e1.delete(0, END)
e1.insert(0, root.data.file_name)
#root.title(os.path.split(root.data.file_name)[1])
b0 = Button(root, text="Filename: ", command=button0) #Label(root, text="Filename: ").grid(row=0)
b0.grid(row=0,column=0)
e1 = Entry(root, justify='left') #text entry for the filename
e1.delete(0, END)
e1.insert(0, '')
e1.grid(row=0, column=1)
e1.place(x=120,width=1200)
def button1():
print (e1.get())
root.data.file_name = e1.get()
print ("...loading: ", root.data.file_name)
load_tif_sequence(e1.get())
print ("... done!")
#******** Run review ROIs function
b1 = Button(root, text="Load tif sequence", command=button1)
b1.grid(row=1, column=0)
def Crop_rectangle(root):
for k, ele in enumerate(root.winfo_children()):
if k>0: ele.destroy()
print ("Croping image")
root.minsize(width=800, height=500)
root.data = emptyObject()
#root.data.root_dir = '/media/cat/4TB/in_vivo/rafa/alejandro/G2M5/20170511/000/'
#root.data.file_name = '/media/cat/4TB/in_vivo/rafa/alejandro/G2M5/20170511/000/Registered.tif'
#******** Select filename:
def button0():
print ("...selecting file...")
#root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data.root_dir)
root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data_folder, defaultextension=".tif", filetypes=(("tif", "*.tif"),("All Files", "*.*") ))
e1.delete(0, END)
e1.insert(0, root.data.file_name)
#root.title(os.path.split(root.data.file_name)[1])
b0 = Button(root, text="Filename: ", command=button0) #Label(root, text="Filename: ").grid(row=0)
b0.grid(row=0,column=0)
e1 = Entry(root, justify='left') #text entry for the filename
e1.delete(0, END)
e1.insert(0, '')
e1.grid(row=0, column=1)
e1.place(x=120,width=800)
def button1():
print ("...croping: ", root.data.file_name)
crop_image(root.data.file_name)
#os.system("python ../CaImAn/demo_OnACID.py "+root.data.file_name)
print ("... done!")
#******** Run review ROIs function
b1 = Button(root, text="Crop tif (or .npy)", command=button1)
b1.grid(row=1, column=0)
def Crop_arbitrary(root):
print ("... arbitrary crop not yet implemented ...")
def Caiman_online(root):
for k, ele in enumerate(root.winfo_children()):
if k>0: ele.destroy()
#print '...text************'
root.minsize(width=1000, height=600)
root.data = emptyObject()
#root.data_folder root.data.root_dir = '/media/cat/4TB/in_vivo/rafa/alejandro/G2M5/20170511/000/'
root.data.file_name = ''
#root.caiman_folder = np.loadtxt('caiman_folder_location.txt',dtype=str)
#******** Filename Selector
def button0():
print ("...selecting file...")
root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data_folder, defaultextension=".tif", filetypes=(("tif", "*.tif"),("npy", "*.npy"),("All Files", "*.*") ))
print (root.data.file_name)
root.data_folder = os.path.split(root.data.file_name)[0]
np.savetxt('data_folder_location.txt',[root.data_folder], fmt="%s")
e.delete(0, END)
e.insert(0, root.data.file_name)
root.title(os.path.split(root.data.file_name)[1])
b0 = Button(root, text="Filename:", anchor="w", command=button0) #Label(root, text="Filename: ").grid(row=0)
b0.place(x=0, y=0)
e = Entry(root, justify='left') #text entry for the filename
e.delete(0, END)
e.insert(0, root.data.file_name)
e.place(x=110,y=4, width=600)
x_offset=0; y_offset=30
l00 = Label(root, text='_'*200)
l00.place(x=x_offset, y=y_offset, height=30, width=1000)
#******** CNMF Parameters ******************
#
x_offset = 0; y_offset=55
l0 = Label(root, text='CNMF Initialization Parameters', fg="red", justify='left')
l0.place(x=x_offset, y=y_offset, height=30, width=190)
#Param 1
x_offset=10; y_offset=+80
l1 = Label(root, text='Merge Threshold')
l1.place(x=x_offset,y=y_offset, height=30,width=100)
e1 = Entry(root, justify='left', width=4) #text entry for the filename
e1.delete(0, END)
e1.insert(0, 0.8)
e1.place(x=x_offset+103,y=y_offset+5)
x_offset+=140
##Param 2
#l2 = Label(root, text='Autoregress order')
#l2.place(x=x_offset,y=y_offset, height=30,width=130)
#e2 = Entry(root, justify='left', width=3) #text entry for the filename
#e2.delete(0, END)
#e2.insert(0, 1)
#e2.place(x=x_offset+120,y=y_offset+5)
#x_offset+=150
#Param 3
l3 = Label(root, text='Initial Batch')
l3.place(x=x_offset,y=y_offset, height=30,width=100)
e3 = Entry(root, justify='left', width=5) #text entry for the filename
e3.delete(0, END)
e3.insert(0, 20000)
e3.place(x=x_offset+88,y=y_offset+5)
x_offset+=145
#Param 4
l4 = Label(root, text='patch_size')
l4.place(x=x_offset,y=y_offset, height=30,width=100)
e4 = Entry(root, justify='left', width=3) #text entry for the filename
e4.delete(0, END)
e4.insert(0, 32)
e4.place(x=x_offset+85,y=y_offset+5)
x_offset+=160
#Param 5
l5 = Label(root, text='stride')
l5.place(x=x_offset,y=y_offset, height=30,width=40)
e5 = Entry(root, justify='left', width=3) #text entry for the filename
e5.delete(0, END)
e5.insert(0, 3)
e5.place(x=x_offset+38,y=y_offset+5)
x_offset+=100
#Param 6
l6 = Label(root, text='K')
l6.place(x=x_offset,y=y_offset, height=30,width=15)
e6 = Entry(root, justify='left', width=3) #text entry for the filename
e6.delete(0, END)
e6.insert(0, 4)
e6.place(x=x_offset+15,y=y_offset+5)
#***************************************************
#Recording Defaults
#NEW LINE
x_offset = 0; y_offset+=50
print (x_offset, y_offset)
l_1 = Label(root, text='Recording Defaults', fg="blue", justify='left')
l_1.place(x=x_offset, y=y_offset, height=30, width=120)
y_offset+=25
#Param 2
l7 = Label(root, text='frame_rate (hz)')
l7.place(x=x_offset,y=y_offset, height=30,width=110)
x_offset+=105
e7 = Entry(root, justify='left', width=4) #text entry for the filename
e7.delete(0, END)
e7.insert(0, 10)
e7.place(x=x_offset,y=y_offset+5)
#Param 3
x_offset+=30
l8 = Label(root, text='decay_time (s)')
l8.place(x=x_offset,y=y_offset, height=30,width=110)
x_offset+=100
e8 = Entry(root, justify='left', width=4) #text entry for the filename
e8.delete(0, END)
e8.insert(0, 0.5)
e8.place(x=x_offset,y=y_offset+5)
#Param 3
x_offset+=50
l9 = Label(root, text='neuron (pixels)')
l9.place(x=x_offset,y=y_offset, height=30,width=100)
x_offset+=100
e9 = Entry(root, justify='left', width=4) #text entry for the filename
e9.delete(0, END)
e9.insert(0, '6, 6')
e9.place(x=x_offset,y=y_offset+5)
#Param 3
x_offset+=40
l10 = Label(root, text='order AR dynamics')
l10.place(x=x_offset,y=y_offset, height=30,width=145)
x_offset+=135
e10 = Entry(root, justify='left', width=3) #text entry for the filename
e10.delete(0, END)
e10.insert(0, 1)
e10.place(x=x_offset,y=y_offset+5)
#Param
x_offset+=40
l11 = Label(root, text='min_SNR')
l11.place(x=x_offset,y=y_offset, height=30,width=65)
x_offset+=62
e11 = Entry(root, justify='left', width=4) #text entry for the filename
e11.delete(0, END)
e11.insert(0, 3.5)
e11.place(x=x_offset,y=y_offset+5)
#Param
x_offset+=40
l12 = Label(root, text='rval_thr')
l12.place(x=x_offset,y=y_offset, height=30,width=65)
x_offset+=60
e12 = Entry(root, justify='left', width=4) #text entry for the filename
e12.delete(0, END)
e12.insert(0, 0.90)
e12.place(x=x_offset,y=y_offset+5)
#Param
x_offset+=40
l13 = Label(root, text='# bkgr comp')
l13.place(x=x_offset,y=y_offset, height=30,width=105)
x_offset+=95
e13 = Entry(root, justify='left', width=4) #text entry for the filename
e13.delete(0, END)
e13.insert(0, 3)
e13.place(x=x_offset,y=y_offset+5)
#***************************************************
#Temporary Initalization Defaults
#NEW LINE
x_offset = 0; y_offset+=50
print (x_offset, y_offset)
l_1 = Label(root, text='Initialization Defaults', fg="green", justify='left')
l_1.place(x=x_offset, y=y_offset, height=30, width=140)
y_offset+=30
#Param
x_offset=0; x_width=120
l14 = Label(root, text='# updated shapes')
l14.place(x=x_offset,y=y_offset, height=30,width=x_width)
x_offset+=x_width
e14 = Entry(root, justify='left', width=4) #text entry for the filename
e14.delete(0, END)
e14.insert(0, 'inf')
e14.place(x=x_offset,y=y_offset+5)
#Param
x_offset+=45; x_width=125
l15 = Label(root, text='# expected shapes')
l15.place(x=x_offset,y=y_offset, height=30,width=x_width)
x_offset+=x_width
e15 = Entry(root, justify='left', width=4) #text entry for the filename
e15.delete(0, END)
e15.insert(0, 2000)
e15.place(x=x_offset,y=y_offset+5)
#Param
x_offset+=45; x_width=80
l16 = Label(root, text='# timesteps')
l16.place(x=x_offset,y=y_offset, height=30,width=x_width)
x_offset+=x_width
e16 = Entry(root, justify='left', width=4) #text entry for the filename
e16.delete(0, END)
N_samples = np.ceil(float(e7.get())*float(e8.get()))
e16.insert(0, N_samples)
e16.place(x=x_offset,y=y_offset+5)
#Param
from scipy.special import log_ndtr
x_offset+=45; x_width=140
l17 = Label(root, text='exceptionality thresh')
l17.place(x=x_offset,y=y_offset, height=30,width=x_width)
x_offset+=x_width
e17 = Entry(root, justify='left', width=5) #text entry for the filename
e17.delete(0, END)
e17.insert(0, log_ndtr(-float(e11.get()))*N_samples)
e17.place(x=x_offset,y=y_offset+5)
#Param
x_offset+=55; x_width=105
l18 = Label(root, text='total len of file')
l18.place(x=x_offset,y=y_offset, height=30,width=x_width)
x_offset+=x_width
e18 = Entry(root, justify='left', width=5) #text entry for the filename
e18.delete(0, END)
e18.insert(0, 'all')
e18.place(x=x_offset,y=y_offset+5)
y_offset+=30; x_offset=0
l000 = Label(root, text='_'*200)
l000.place(x=x_offset, y=y_offset, height=30, width=1000)
#********** COMMAND LINE OUTPUT BOX **********
tkinter_window = False #Redirect command line outputs to text box in tkinter;
if tkinter_window:
t = Text(root, wrap='word', height = 20, width=100)
t.place(x=10, y=250, in_=root)
#********* DEMO_ONACID BUTTON **********************
def button1(l):
l.config(foreground='red')
root.update()
#Save existing config file
np.savez(str(root.data.file_name)[:-4]+"_runtime_params", \
merge_thr=e1.get(), #merge threshold
initibatch = e3.get(), #Initial batch
patch_size=e4.get(), #patch size
stride=e5.get(), #stride
K=e6.get(), #K
frame_rate=e7.get(), #frame_rate
decay_time=e8.get(), #decay_time
neuron_size=e9.get(), #neuron size pixesl
AR_dynamics=e10.get(), #AR dynamics order
min_SNR=e11.get(), #min_SNR
rval_threshold = e12.get(), # rval_threshold
no_bkgr_components=e13.get(), # #bkground componenets
no_updated_shapes=e14.get(), # #udpated shapes
no_expected_shapes=e15.get(), # #expected shapes
no_timesteps=e16.get(), # #timesteps
exceptionality_threshold=e17.get(), # exceptionatliy threshold
total_len_file=e18.get(), # total len of file
caiman_location = str(root.caiman_folder)
)
print (type(str(root.caiman_folder)))
print (type(root.caiman_folder))
if tkinter_window:
import io, subprocess
#proc = subprocess.Popen(["python", "-u", "/home/cat/code/CaImAn/demo_OnACID.py", root.data.file_name], stdout=subprocess.PIPE)
proc = subprocess.Popen(["python", "-u", str(root.caiman_folder)+"/demo_OnACID_2.py", root.data.file_name], stdout=subprocess.PIPE)
while True:
line = proc.stdout.readline()
if line != '':
t.insert(END, '%s\n' % line.rstrip())
t.see(END)
t.update_idletasks()
sys.stdout.flush()
else:
break
else:
print ("python -u ")
print (root.caiman_folder)
#p = os.system("python -u "+str(root.caiman_folder)+"/demo_OnACID_2.py "+root.data.file_name)
print ("python -u "+str(root.caiman_folder)+"/demo_OnACID_2.py "+str(root.data.file_name))
p = os.system("python -u "+str(root.caiman_folder)+"/demo_OnACID_2.py "+str(root.data.file_name))
l = Label(root, textvariable='green', fg = 'red')
b1 = Button(root, text="demo_OnACID", foreground='blue', command=lambda: button1(l))
b1.place(x=0, y=y_offset+50, in_=root)
def Caiman_offline(root):
for k, ele in enumerate(root.winfo_children()):
if k>0: ele.destroy()
print ("...caiman offline...(not implemented)")
print ("...Note: caiman online is currently running in caiman offline mode... ")
def Image_registration(root):
for k, ele in enumerate(root.winfo_children()):
if k>0: ele.destroy()
print ("... image registration...")
root.minsize(width=800, height=500)
root.data = emptyObject()
#******** Select filename:
def button0():
print ("...selecting file...")
#root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data.root_dir)
root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data_folder, defaultextension=".tif", filetypes=(("tif", "*.tif"),("All Files", "*.*") ))
e1.delete(0, END)
e1.insert(0, root.data.file_name)
#root.title(os.path.split(root.data.file_name)[1])
b0 = Button(root, text="Filename: ", command=button0) #Label(root, text="Filename: ").grid(row=0)
b0.grid(row=0,column=0)
e1 = Entry(root, justify='left') #text entry for the filename
e1.delete(0, END)
e1.insert(0, '')
e1.grid(row=0, column=1)
e1.place(x=120,width=800)
def button1():
print ("...motion correcting: ", root.data.file_name)
motion_correct_caiman(root)
#******** Run review ROIs function
b1 = Button(root, text="motion correct", command=button1)
b1.grid(row=1, column=0)
class emptyObject():
def __init__(self):
pass
def Review_ROIs(root):
print ("...Review ROIs ...")
for k, ele in enumerate(root.winfo_children()):
if k>0: ele.destroy()
root.data = emptyObject()
root.data.file_name = ''
root.title("Review and Cleanup ROIs")
def load_data():
print ("...loading processed file: ", root.data.file_name)
#Update filename box
e1.delete(0, END)
e1.insert(0, root.data.file_name)
#Load data
data_in = np.load(root.data.file_name, encoding= 'latin1', mmap_mode='c')
print (data_in.keys())
A = data_in['A'] #Convert array from sparse to dense
#print (A.shape)
#print (A[()].shape)
root.data.A = A[()].toarray()
print (root.data.A.shape)
root.data.Cn = data_in['Cn']
print (root.data.Cn.shape)
root.data.YrA = data_in['YrA']
print (root.data.YrA.shape)
print (root.data.YrA)
# plt.imshow(root.data.Cn)
#plt.show(block=True)
#print (root.data.A.shape)
root.data.Yr = data_in['Yr']
print (root.data.Yr.shape)
root.data.C = data_in['C']
root.data.b = data_in['b']
root.data.f = data_in['f']
save_traces(root.data.file_name, root.data.Yr, root.data.A, root.data.C, root.data.b, root.data.f, 250, 250, YrA = root.data.YrA, thr = 0.8,
image_neurons=root.data.Cn, denoised_color='red')
#******** Select filename:
def button0():
print ("...selecting file...")
root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data_folder, defaultextension="*processed.npz", filetypes=(("npz", "*processed.npz"),("All Files", "*.*") ))
e1.delete(0, END)
e1.insert(0, root.data.file_name)
root.title(os.path.split(root.data.file_name)[1])
load_data()
b0 = Button(root, text="Filename: ", command=button0) #Label(root, text="Filename: ").grid(row=0)
b0.grid(row=0,column=0)
e1 = Entry(root) #text entry for the filename
e1.delete(0, END)
e1.insert(0, root.data.file_name)
e1.grid(row=0, column=1)
e1.place(x=120,width=800)
#******** Correct ROIs
def button1():
print ("... running correct ROIs...")
correct_ROIs(root.data.file_name, root.data.A, root.data.Cn, thr=0.95)
b1 = Button(root, text="Review ROIs", command=button1, justify='left')
b1.place(x=0, y=50)
def Review_spikes(root):
print ("...Review spikes ...")
for k, ele in enumerate(root.winfo_children()):
if k>0: ele.destroy()
root.title("Review Spikes")
root.data = emptyObject()
root.data.file_name = ''
#******** Select ROI filename
def button0():
print ("...selecting ROI file...")
root.data.file_name = tkFileDialog.askopenfilename(initialdir=root.data_folder, defaultextension="ROIs.npz", filetypes=(("ROI", "*ROIs.npz"),("All Files", "*.*") ))
e1.delete(0, END)
e1.insert(0, root.data.file_name)
#load_data()
b0 = Button(root, text="Filename: ", command=button0) #Label(root, text="Filename: ").grid(row=0)
b0.grid(row=0,column=0)
e1 = Entry(root) #text entry for the filename
e1.delete(0, END)
e1.insert(0, root.data.file_name)
e1.place(x=120,y=5, width=800)
#********* Run foopsi
#Param 1
x_offset = 0; y_offset=50
l1 = Label(root, text='Foopsi Threshold')
l1.place(x=x_offset,y=y_offset, height=30,width=110)
x_offset+=125; y_offset+=5
e2 = Entry(root, justify='left', width=4) #text entry for the filename
e2.delete(0, END)
e2.insert(0, 2.0)
e2.place(x=x_offset,y=y_offset)
def button1():
print ("...running foopsi...")
root.data.foopsi_threshold = e2.get()
run_foopsi(root)
x_offset=0; y_offset=80
b1 = Button(root, text="Run Foopsi", command=button1)
b1.place(x=x_offset,y=y_offset)
#********* View rasters
def button2():
print ("...viewing rasters...")
root.data.foopsi_threshold = e2.get()
view_rasters(root)
y_offset+=70
b2 = Button(root, text="View all rasters", command=button2)
b2.place(x=x_offset,y=y_offset)
#********* View single neuron
def button2():
print ("...viewing trace...")
root.data.foopsi_threshold = e2.get()
root.data.neuron_id = int(e3.get())
view_neuron(root)
y_offset+=70
b2 = Button(root, text="View neuron", command=button2)
b2.place(x=x_offset,y=y_offset)
#x_offset+=100
#l2 = Label(root, text='Neuron #:')
#l2.place(x=x_offset,y=y_offset, height=30,width=110)
x_offset+=125; y_offset+=5
e3 = Entry(root, justify='left', width=4) #text entry for the filename
e3.delete(0, END)
e3.insert(0, 0)
e3.place(x=x_offset,y=y_offset)