-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathswa_Explorer.m
1439 lines (1176 loc) · 48.5 KB
/
swa_Explorer.m
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
% GUI for Exploring Travelling Waves
function swa_Explorer(varargin)
DefineInterface
function DefineInterface
% Create Figure
% Dual monitors creates an issue in Linux environments whereby the two
% screens are seen as one long screen, so always use first one
sd = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment.getScreenDevices;
if length(sd) > 1
bounds = sd(2).getDefaultConfiguration.getBounds;
figPos = [bounds.x bounds.y bounds.width bounds.height];
else
bounds = sd(1).getDefaultConfiguration.getBounds;
figPos = [bounds.x bounds.y bounds.width bounds.height];
end
handles.fig = figure(...
'Name', 'Travelling Waves:',...
'NumberTitle', 'off',...
'Color', 'w',...
'MenuBar', 'none',...
'Units', 'pixels',...
'Outerposition',figPos);
set(handles.fig,...
'KeyPressFcn', {@cb_KeyPressed});
% Menus
% ^^^^^
handles.menu.File = uimenu(handles.fig, 'Label', 'File');
handles.menu.LoadData = uimenu(handles.menu.File,...
'Label', 'Load Data',...
'Accelerator', 'L');
set(handles.menu.LoadData, 'Callback', {@menu_LoadData});
handles.menu.SaveData = uimenu(handles.menu.File,...
'Label', 'Save Data',...
'Accelerator', 'S');
set(handles.menu.SaveData, 'Callback', {@menu_SaveData});
% view menu
handles.menu.View = uimenu(handles.fig, 'label', 'View');
handles.menu.filter_toggle = uimenu(handles.menu.View, ...
'label', 'filter toggle', ...
'checked', 'on', ...
'callback', {@fcn_options, 'filter_toggle'});
% Plot Titles and Export Button
% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
handles.Title_SWPlot = uicontrol(...
'Parent', handles.fig,...
'Style', 'text',...
'String', 'Individual Wave',...
'Units', 'normalized',...
'Position', [0.05 .68 0.4 0.02],...
'FontName', 'Century Gothic',...
'FontSize', 11);
handles.Ex_SWPlot = uicontrol(...
'Parent', handles.fig,...
'Style', 'pushbutton',...
'String', '+',...
'Units', 'normalized',...
'Position', [0.43 .68 0.02 0.02],...
'FontName', 'Century Gothic',...
'FontSize', 11);
set(handles.Ex_SWPlot, 'Callback', @edit_SWPlot)
handles.Title_Delay = uicontrol(...
'Parent', handles.fig,...
'value', 1 ,...
'Style', 'text',...
'Units', 'normalized',...
'Position', [0.5 .73 0.45 0.02],...
'FontName', 'Century Gothic',...
'FontSize', 11);
handles.Ex_Delay = uicontrol(...
'Parent', handles.fig,...
'Style', 'pushbutton',...
'String', '+',...
'Units', 'normalized',...
'Position', [0.93 .73 0.02 0.02],...
'FontName', 'Century Gothic',...
'FontSize', 11);
set(handles.Ex_Delay, 'Callback', @pb_XDelay_Callback)
% csc plotter pushbutton
handles.Ex_Channel_Plot = uicontrol(...
'Parent', handles.fig,...
'Style', 'pushbutton',...
'String', 'csc',...
'Units', 'normalized',...
'Position', [0.93 0.925 0.02 0.02],...
'FontName', 'Century Gothic',...
'FontSize', 11,...
'enable', 'off');
if exist('csc_eeg_plotter', 'file')
set(handles.Ex_Channel_Plot, 'enable', 'on');
set(handles.Ex_Channel_Plot, 'Callback', @pb_XChannel_Callback)
end
% Checkboxes for Delay
% ^^^^^^^^^^^^^^^^^^^^
% TODO: make single drop-down menu with checkboxes
handles.Surface_Delay = uicontrol(...
'Parent', handles.fig,...
'Style', 'checkbox',...
'BackgroundColor', 'w',...
'String', 'Surface',...
'Value', 1,...
'Units', 'normalized',...
'Position', [0.5 0.08 0.1 0.02],...
'FontName', 'Century Gothic',...
'FontSize', 11);
set(handles.Surface_Delay, 'Callback', @UpdateDelay2);
handles.Channels_Delay = uicontrol(...
'Parent', handles.fig,...
'Style', 'checkbox',...
'BackgroundColor', 'w',...
'String', 'Channels',...
'Value', 1,...
'Units', 'normalized',...
'Position', [0.6 0.08 0.1 0.02],...
'FontName', 'Century Gothic',...
'FontSize', 11);
set(handles.Channels_Delay, 'Callback', @UpdateDelay2);
handles.Origins_Delay = uicontrol(...
'Parent', handles.fig,...
'Style', 'checkbox',...
'BackgroundColor', 'w',...
'String', 'Origins',...
'Value', 1,...
'Units', 'normalized',...
'Position', [0.7 0.08 0.1 0.02],...
'FontName', 'Century Gothic',...
'FontSize', 11);
set(handles.Origins_Delay, 'Callback', @UpdateDelay2);
handles.Streams_Delay = uicontrol(...
'Parent', handles.fig,...
'Style', 'checkbox',...
'BackgroundColor', 'w',...
'String', 'Streams',...
'Value', 1,...
'Units', 'normalized',...
'Position', [0.8 0.08 0.1 0.02],...
'FontName', 'Century Gothic',...
'FontSize', 11);
set(handles.Streams_Delay, 'Callback', @UpdateDelay2);
% Checkboxes for wave plot
handles.cb_waveplot(1) = uicontrol(...
'Parent', handles.fig,...
'Style', 'checkbox',...
'BackgroundColor', 'w',...
'String', '<html>θ</html>',...
'Value', 1,...
'Units', 'normalized',...
'Position', [0.052 0.66 0.1 0.02],...
'FontName', 'Century Gothic',...
'FontSize', 11);
handles.cb_waveplot(2) = uicontrol(...
'Parent', handles.fig,...
'Style', 'checkbox',...
'BackgroundColor', 'w',...
'String', '<html>α</html>',...
'Value', 1,...
'Units', 'normalized',...
'Position', [0.052 0.63 0.1 0.02],...
'FontName', 'Century Gothic',...
'FontSize', 11);
% Create Axes
% ^^^^^^^^^^^
handles.axes_eeg_channel(1) = axes(...
'Parent', handles.fig,...
'Position', [0.05 0.875 0.9 0.075],...
'NextPlot', 'add',...
'FontName', 'Century Gothic',...
'FontSize', 8,...
'box', 'off',...
'Xtick', [],...
'Ytick', []);
handles.axes_eeg_channel(2) = axes(...
'Parent', handles.fig,...
'Position', [0.05 0.8 0.9 0.075],...
'NextPlot', 'add',...
'FontName', 'Century Gothic',...
'FontSize', 8,...
'box', 'off',...
'Ytick', []);
% button down function for both channel axes
set(handles.axes_eeg_channel, 'buttonDownFcn', {@btf_add_wave});
handles.axes_individual_wave = axes(...
'Parent', handles.fig,...
'Position', [0.05 0.4 0.4 0.3],...
'FontName', 'Century Gothic',...
'NextPlot', 'add',...
'FontSize', 8,...
'box', 'off',...
'Xtick', []);
handles.ax_Delay = axes(...
'Parent', handles.fig,...
'Position', [0.5 0.1 0.45 0.65],...
'NextPlot', 'add',...
'FontName', 'Century Gothic',...
'FontSize', 8,...
'box', 'off',...
'Xtick', [],...
'Ytick', []);
% Two Wave Summary Plots
% ^^^^^^^^^^^^^^^^^^^^^^
% create the two axes
% ~~~~~~~~~~~~~~~~~~~
handles.ax_option(1) = axes(...
'Parent', handles.fig,...
'Position', [0.05 0.05 0.2 0.3],...
'FontName', 'Century Gothic',...
'FontSize', 8,...
'box', 'off',...
'Xtick', [],...
'Ytick', []);
handles.ax_option(2) = axes(...
'Parent', handles.fig,...
'Position', [0.25 0.05 0.2 0.3],...
'FontName', 'Century Gothic',...
'FontSize', 8,...
'box', 'off',...
'Xtick', [],...
'Ytick', []);
% export buttons
% ~~~~~~~~~~~~~~
handles.Ex_options(1) = uicontrol(...
'Parent', handles.fig ,...
'Style', 'pushbutton' ,...
'backgroundColor', [0.9, 0.9, 0.9] ,...
'foregroundColor', [0.1, 0.1, 0.1] ,...
'String', '+' ,...
'Units', 'normalized' ,...
'Position', [0.23 .35 0.02 0.02],...
'FontName', 'Century Gothic' ,...
'FontSize', 11 );
set(handles.Ex_options(1), 'callback', {@pb_export_options, 1});
handles.Ex_options(2) = uicontrol(...
'Parent', handles.fig ,...
'Style', 'pushbutton' ,...
'backgroundColor', [0.9, 0.9, 0.9] ,...
'foregroundColor', [0.1, 0.1, 0.1] ,...
'String', '+' ,...
'Units', 'normalized' ,...
'Position', [0.43 .35 0.02 0.02],...
'FontName', 'Century Gothic' ,...
'FontSize', 11 );
set(handles.Ex_options(2), 'callback', {@pb_export_options, 2});
% Context Menus
% ^^^^^^^^^^^^^
handles.menu.ButterflyContext = uicontextmenu;
handles.menu.UIContext_YReverse = uimenu(handles.menu.ButterflyContext,...
'Label', 'Negative Down',...
'Callback', {@fcn_context_axes_channel, 'normal'});
handles.menu.UIContext_YReverse = uimenu(handles.menu.ButterflyContext,...
'Label', 'Negative Up',...
'Callback', {@fcn_context_axes_channel, 'reverse'});
set(handles.axes_eeg_channel, 'uicontextmenu', handles.menu.ButterflyContext);
set(handles.axes_individual_wave, 'uicontextmenu', handles.menu.ButterflyContext);
% create the drop down menus
% ~~~~~~~~~~~~~~~~~~~~~~~~~~
% make the drop-down menus as java objects
[handles.java.options_list(1), handles.options_list(1)] = javacomponent(javax.swing.JComboBox);
set(handles.options_list(1),...
'parent', handles.fig,...
'units', 'normalized',...
'position', [0.05 0.35 0.18 0.02],...
'backgroundColor', [0.9, 0.9, 0.9]);
set(handles.java.options_list(1),...
'ActionPerformedCallback', {@fcn_select_options, handles.fig, 1});
[handles.java.options_list(2), handles.options_list(2)] = javacomponent(javax.swing.JComboBox);
set(handles.options_list(2),...
'parent', handles.fig,...
'units', 'normalized',...
'position', [0.25 0.35 0.18 0.02],...
'backgroundColor', [0.9, 0.9, 0.9]);
set(handles.java.options_list(2),...
'ActionPerformedCallback', {@fcn_select_options, handles.fig, 2});
% Status Bar
% ^^^^^^^^^^
handles.StatusBar = uicontrol(...
'Parent', handles.fig,...
'Style', 'text',...
'String', 'Status Updates',...
'Units', 'normalized',...
'Position', [0 0 1 0.03],...
'FontName', 'Century Gothic',...
'FontSize', 10);
handles.java.StatusBar = findjobj(handles.StatusBar);
% set the alignment of the status bar
pause(0.5); drawnow % pause to let java objects load (reduces random java error)
handles.java.StatusBar.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
handles.java.StatusBar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
% Slider Spinner and Delete Button
[handles.java.Slider,handles.Slider] = javacomponent(javax.swing.JSlider);
set(handles.Slider,...
'Parent', handles.fig,...
'Units', 'normalized',...
'Position', [0.05 0.72 0.32 0.05]);
% >> handles.java.Slider.set [then tab complete to find available methods]
handles.java.Slider.setBackground(javax.swing.plaf.ColorUIResource(1,1,1))
set(handles.java.Slider, 'MouseReleasedCallback',{@SliderUpdate, handles.fig});
[handles.java.Spinner,handles.Spinner] = javacomponent(javax.swing.JSpinner);
set(handles.Spinner,...
'Parent', handles.fig,...
'Units', 'normalized',...
'Position', [0.38 0.72 0.05 0.05]);
% Set the font and size (Found through >>handles.java.Slider.Font)
handles.java.Spinner.setFont(javax.swing.plaf.FontUIResource('Century Gothic', 0, 25))
handles.java.Spinner.getEditor().getTextField().setHorizontalAlignment(javax.swing.SwingConstants.CENTER)
set(handles.java.Spinner, 'StateChangedCallback', {@SpinnerUpdate, handles.fig});
handles.pb_Delete = uicontrol(...
'Parent', handles.fig,...
'Style', 'pushbutton',...
'String', 'X',...
'Units', 'normalized',...
'Position', [0.43 .72 0.02 0.05],...
'FontName', 'Century Gothic',...
'FontSize', 11);
set(handles.pb_Delete, 'Callback', {@pb_Delete_Callback});
% Channel Set ComboBoxes
% ^^^^^^^^^^^^^^^^^^^^^^
[handles.java.ChannelBox(1),handles.ChannelBox(1)] = javacomponent(javax.swing.JComboBox);
set(handles.ChannelBox(1),...
'Parent', handles.fig,...
'Units', 'normalized',...
'Position', [0.02 0.90 0.03 0.02]);
set(handles.java.ChannelBox(1), 'ActionPerformedCallback', {@SpinnerUpdate, handles.fig});
[handles.java.ChannelBox(2),handles.ChannelBox(2)] = javacomponent(javax.swing.JComboBox);
set(handles.ChannelBox(2),...
'Parent', handles.fig,...
'Units', 'normalized',...
'Position', [0.02 0.825 0.03 0.02]);
set(handles.java.ChannelBox(2), 'ActionPerformedCallback', {@SpinnerUpdate, handles.fig});
% set java properties of Delay Combo box
[handles.java.PlotBox,handles.PlotBox] = javacomponent(javax.swing.JComboBox);
set(handles.PlotBox,...
'Parent', handles.fig,...
'Units', 'normalized',...
'Position', [0.65 0.73 0.15 0.02]);
handles.java.PlotBox.setModel(javax.swing.DefaultComboBoxModel({'Delay Map', 'Involvement Map'}));
handles.java.PlotBox.setFont(javax.swing.plaf.FontUIResource('Century Gothic', 0, 14));
set(handles.java.PlotBox, 'ActionPerformedCallback', {@SliderUpdate, handles.fig});
% Make Figure Visible and Maximise
% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
jFrame = get(handle(handles.fig),'JavaFrame');
jFrame.setMaximized(true); % to maximize the figure
% update the handles structure
guidata(handles.fig, handles);
function menu_LoadData(object, ~)
handles = guidata(object);
[swaFile, swaPath] = uigetfile('*.mat', 'Please Select the Results File');
if swaFile == 0
set(handles.StatusBar, 'String', 'Information: No File Selected');
return;
end
% Quick Check for right structures in file before loading
varnames = whos('-file', [swaPath,swaFile]);
if ~ismember('Data', {varnames.name}) || ~ismember('Info', {varnames.name})
set(handles.StatusBar, 'String', 'Information: No Data or Info structure in file');
return;
end
% Load the data
loaded_file = load ([swaPath,swaFile]);
% Check for data present or external file
if ischar(loaded_file.Data.Raw)
% check for changed reference
if isfield (loaded_file.Info.Recording, 'new_reference')
loaded_file.Info.Recording.dataDim(1) = ...
loaded_file.Info.Recording.dataDim(1) ...
+ numel(loaded_file.Info.Recording.new_reference);
end
% default memory map data
% TODO: make settable parameter
flag_memory_map = true;
% memory map or actually load the data
if flag_memory_map
data_file = loaded_file.Info.Recording.dataFile;
temp_data = memmapfile(fullfile(swaPath, data_file), ...
'format', {'single', loaded_file.Info.Recording.dataDim, 'eegData'});
loaded_file.Data.Raw = temp_data.Data.eegData;
else
set(handles.StatusBar, 'String', 'Busy: Loading Data');
fid = fopen(fullfile(swaPath, loaded_file.Data.Raw));
loaded_file.Data.Raw = fread(fid, loaded_file.Info.Recording.dataDim, 'single');
fclose(fid);
end
end
% change data if reference was changed
if isfield (loaded_file.Info.Recording, 'new_reference')
% get the new reference
new_reference = loaded_file.Info.Recording.new_reference;
% calculate the average mastoid activity
reference_data = mean(loaded_file.Data.Raw(new_reference, :), 1);
% rereference the data
loaded_file.Data.Raw = loaded_file.Data.Raw ...
- repmat(reference_data, [size(loaded_file.Data.Raw, 1), 1]);
% remove the mastoid channels for the data set
loaded_file.Data.Raw(new_reference, :) = [];
end
% Adjust settings dependent on wave types
if isfield(loaded_file, 'SW')
handles.SW = loaded_file.SW;
handles.SW_Type = 'SW';
elseif isfield(loaded_file, 'ST')
handles.SW = loaded_file.ST;
handles.SW_Type = 'ST';
elseif isfield(loaded_file, 'SS')
handles.SW = loaded_file.SS;
handles.SW_Type = 'SS';
% no delay maps for spindles
handles.java.PlotBox.setSelectedIndex(1);
% checkboxes for power and reference
set(handles.cb_waveplot(1),...
'String', 'canonical');
set(handles.cb_waveplot(2),...
'String', 'power');
else
set(handles.StatusBar, 'String', 'Information: No SW/ST/SS structure in file');
return;
end
% place the Info struct in the GUI handles
handles.Info = loaded_file.Info;
% set the figure title to match the file name
set(handles.fig, 'Name', ['Travelling Waves: ', swaFile]);
% Set the ComboBoxes
% ``````````````````
channel_list = [{handles.Info.Electrodes.labels}, {'All', 'Ref'}];
% create java models using swing
java_model1 = javax.swing.DefaultComboBoxModel(channel_list);
java_model2 = javax.swing.DefaultComboBoxModel(channel_list);
handles.java.ChannelBox(1).setModel(java_model1);
handles.java.ChannelBox(1).setEditable(true);
handles.java.ChannelBox(2).setModel(java_model2);
handles.java.ChannelBox(2).setEditable(true);
% handles.java.ChannelBox(1).getSelectedIndex() % Gets the value (setSele...)
% Set Slider and Spinner Values
% `````````````````````````````
handles.java.Slider.setValue(1);
handles.java.Slider.setMinimum(1);
handles.java.Slider.setMaximum(length(handles.SW));
handles.java.Slider.setMinorTickSpacing(5);
handles.java.Slider.setMajorTickSpacing(20);
handles.java.Slider.setPaintTicks(true);
% prepare filter for later
handles.filter_design = designfilt('lowpassiir', 'DesignMethod', 'cheby2', ...
'StopbandFrequency', 20, 'PassbandFrequency', 16, ...
'SampleRate', handles.Info.Recording.sRate);
% Update handles structure
guidata(handles.fig, handles);
setappdata(handles.fig, 'Data', loaded_file.Data);
% Set the output boxes
% ~~~~~~~~~~~~~~~~~~~~
% get the currently available options
options_list = swa_wave_summary('return options');
% check for wavetype since no travelling parameters are created for SS
if strcmp(handles.SW_Type, 'SS')
bad_options = ismember(options_list,...
{'distances', 'anglemap', 'topo_origins', ...
'topo_streams', 'topo_meandelay', 'topo_streamorigins'});
options_list(bad_options) = [];
end
% create and set the java models for the options list
model1 = javax.swing.DefaultComboBoxModel(options_list);
model2 = javax.swing.DefaultComboBoxModel(options_list);
handles.java.options_list(1).setModel(model1);
handles.java.options_list(2).setModel(model2);
% set the second option box to the second value (0-index value 1)
handles.java.options_list(2).setSelectedIndex(1)
% plot the first two output parameters in the list
fcn_select_options([],[], handles.fig, 1);
fcn_select_options([],[], handles.fig, 2);
% set the spinner value which initiates other plot updates
handles.java.Spinner.setValue(1);
set(handles.StatusBar, 'String', 'Idle');
function menu_SaveData(hObject, ~)
% get the GUI handles
handles = guidata(hObject);
% get the data
Data = getappdata(handles.fig, 'Data');
% get user input for the save name and path
[saveName,savePath] = uiputfile('*.mat');
% check if the cancel button was selected
if saveName == 0; return; end
% get the Info alone to save as is
Info = handles.Info;
% get the correct SW type before saving specifically
switch handles.SW_Type
case 'SW'
SW = handles.SW;
case 'SS'
SS = handles.SW;
case 'ST'
ST = handles.SW;
end
% save the data
switch handles.SW_Type
case 'SW'
swa_saveOutput(Data, Info, SW, fullfile(savePath, saveName), 1, 0);
case 'ST'
swa_saveOutput(Data, Info, ST, fullfile(savePath, saveName), 1, 0);
otherwise
% TODO: use swa_saveOutput for SS and ST as well
save(fullfile(savePath, saveName), 'Data', 'Info', handles.SW_Type, '-mat');
end
set(handles.fig, 'Name', ['Traveling Waves: ', saveName]);
% Update Controls
function SpinnerUpdate(~, ~, hObject)
handles = guidata(hObject); % Needs to be like this because slider is a java object
% check if function called with loaded data
if ~isfield(handles, 'SW')
return;
end
if handles.java.Spinner.getValue() == 0
handles.java.Spinner.setValue(1);
return;
elseif handles.java.Spinner.getValue() > length(handles.SW)
handles.java.Spinner.setValue(length(handles.SW));
return;
end
handles.java.Slider.setValue(handles.java.Spinner.getValue())
% update the plots
handles = update_SWPlot(handles);
handles = update_axes_channels(handles);
handles = update_SWDelay(handles, 0);
guidata(hObject, handles);
function SliderUpdate(~,~,Figure)
handles = guidata(Figure); % Needs to be like this because slider is a java object
% check if function called with loaded data
if ~isfield(handles, 'SW')
return;
end
handles.java.Spinner.setValue(handles.java.Slider.getValue())
% Update the plots (except origins and density since they are global)
handles = update_axes_channels(handles);
handles = update_SWPlot(handles);
handles = update_SWDelay(handles, 0);
guidata(handles.fig, handles);
function cb_KeyPressed(object, eventdata)
% get the GUI figure handles
handles = guidata(object);
% initial plot then update the yData in a loop (faster than replot)
nSW = handles.java.Spinner.getValue();
% movement keys
switch eventdata.Key
case 'rightarrow'
% move to the next wave if not at the end
if nSW < handles.java.Slider.getMaximum
handles.java.Spinner.setValue(nSW+1);
end
case 'leftarrow'
if nSW > 1
handles.java.Spinner.setValue(nSW-1);
end
end
% Plot Controls
function handles = update_axes_channels(handles)
% get the data structure
Data = getappdata(handles.fig, 'Data');
% get current wave
nSW = handles.java.Spinner.getValue();
% Calculate the range / wave peaks and start points
switch handles.SW_Type
case {'SW', 'ST'}
winLength = floor(15 * handles.Info.Recording.sRate);
range = handles.SW(nSW).Ref_PeakInd - winLength ...
: handles.SW(nSW).Ref_PeakInd + winLength;
% calculate points for arrows and zoom lines
wave_peaks = [handles.SW.Ref_PeakInd]./ handles.Info.Recording.sRate;
start_point = handles.SW(nSW).Ref_PeakInd / handles.Info.Recording.sRate;
end_point = handles.SW(nSW).Ref_PeakInd / handles.Info.Recording.sRate;
case 'SS'
winLength = floor((30 * handles.Info.Recording.sRate - handles.SW(nSW).Ref_Length) / 2);
range = handles.SW(nSW).Ref_Start - winLength : handles.SW(nSW).Ref_End + winLength;
wave_peaks = ([handles.SW.Ref_Start] + [handles.SW.Ref_Length]./ ...
2) / handles.Info.Recording.sRate;
start_point = handles.SW(nSW).Ref_Start / handles.Info.Recording.sRate;
end_point = handles.SW(nSW).Ref_End / handles.Info.Recording.sRate;
end
% check that the range is within data limits (set to sample 1 if not)
range(range < 1 | range > size(Data.Raw, 2)) = 1;
xaxis = range./handles.Info.Recording.sRate;
% check for special selected channels
data_to_plot = cell(2, 1);
for n = 1:2
selected_label = handles.java.ChannelBox(n).getSelectedItem;
if strcmp(selected_label, 'All')
data_to_plot{n} = Data.Raw(:, range);
elseif strcmp(selected_label, 'Ref')
% check which reference wave to plot
switch handles.SW_Type
case 'SW'
data_to_plot{n} = mean(Data.SWRef(:, range), 1);
case 'SS'
data_to_plot{n} = mean(Data.SSRef(:, range), 1);
case 'ST'
data_to_plot{n} = mean(Data.STRef(:, range), 1);
end
else
% - channel selected (most cases) - %
Ch = handles.java.ChannelBox(n).getSelectedIndex() + 1;
data_to_plot{n} = Data.Raw(Ch, range);
end
end
% check for filter toggle
if strcmp(get(handles.menu.filter_toggle, 'checked'), 'on')
for n = 1 : 2
data_to_plot{n} = filtfilt(...
handles.filter_design, double(data_to_plot{n})')';
end
end
% define plot_method
if ~isfield(handles, 'lines_eeg_channel')
plot_method = 'initial';
else
if length(handles.lines_eeg_channel{1}) == size(data_to_plot{1}, 1) ...
&& length(handles.lines_eeg_channel{2}) == size(data_to_plot{2}, 1)
plot_method = 'replot';
else
delete(handles.lines_eeg_channel{1});
delete(handles.lines_eeg_channel{2});
handles = rmfield(handles, 'lines_eeg_channel');
plot_method = 'initial';
end
end
switch plot_method
case 'initial'
% -- initial Plot (50 times takes 1.67s) -- %
% plot the top raw eeg
handles.lines_eeg_channel{1} = plot(handles.axes_eeg_channel(1), xaxis, data_to_plot{1}', 'k');
handles.lines_eeg_channel{2} = plot(handles.axes_eeg_channel(2), xaxis, data_to_plot{2}', 'k');
% set the top axes limits
deviation = double(std(data_to_plot{1}));
set(handles.axes_eeg_channel,...
'yLim', [-5 * deviation, 5 * deviation],...
'xLim', [xaxis(1), xaxis(end)]);
% plot the two zoom lines
handles.zoomline(1) = line([start_point - 0.5, start_point - 0.5], [-200, 200]);
handles.zoomline(2) = line([end_point + 0.5, end_point + 0.5], [-200, 200]);
% set common zoomline parameters
set(handles.zoomline,...
'color', [0.4 0.4 0.4] ,...
'linewidth', 2 ,...
'Parent', handles.axes_eeg_channel(1));
% Just plot all the arrows already
handles.arrows_Butterfly = text(wave_peaks, ones(1, length(wave_peaks)) * 5 * deviation ,...
'\downarrow',...
'FontSize', 20 ,...
'HorizontalAlignment', 'center' ,...
'Clipping', 'on',...
'Parent', handles.axes_eeg_channel(1));
case 'replot'
% -- re-plotting (50 times takes 0.3s) -- %
% loop each axes
for a = 1:2
set(handles.lines_eeg_channel{a}, 'xData', xaxis);
% loop for each channel (only more than 1 for All or Ref)
for n = 1:size(data_to_plot{a}, 1)
set(handles.lines_eeg_channel{a}(n), 'yData', data_to_plot{a}(n,:)');
end
end
% change the x limits for the channels
set(handles.axes_eeg_channel,...
'XLim', [xaxis(1), xaxis(end)]);
% shift the zoom lines
set(handles.zoomline(1), 'xData',...
[start_point - 0.5, start_point - 0.5]);
set(handles.zoomline(2), 'xData',...
[end_point + 0.5, end_point + 0.5]);
end
function handles = update_SWPlot(handles)
% get the data structure
Data = getappdata(handles.fig, 'Data');
% get the current wave number
nSW = handles.java.Spinner.getValue();
% Calculate the range
switch handles.SW_Type
case 'SW'
winLength = floor(2 * handles.Info.Recording.sRate);
range = handles.SW(nSW).Ref_PeakInd - winLength : handles.SW(nSW).Ref_PeakInd + winLength;
case 'SS'
winLength = floor((2 * handles.Info.Recording.sRate - handles.SW(nSW).Ref_Length) / 2);
range = handles.SW(nSW).Ref_Start - winLength : handles.SW(nSW).Ref_End + winLength;
case 'ST'
winLength = floor(1 * handles.Info.Recording.sRate);
range = handles.SW(nSW).Ref_PeakInd - winLength : handles.SW(nSW).Ref_PeakInd + winLength;
end
% check that the range is within data limits (set to sample 1 if not)
range(range < 1 | range > size(Data.Raw, 2)) = 1;
% check for filter toggle
if strcmp(get(handles.menu.filter_toggle, 'checked'), 'off')
data_to_plot = Data.Raw(:, range);
else
data_to_plot = filtfilt(...
handles.filter_design, double(Data.Raw(:, range))')';
end
% initial plot
% ^^^^^^^^^^^^
% check if the plot already exists
if ~isfield(handles, 'SWPlot')
cla(handles.axes_individual_wave);
% plot all the channels but hide them
handles.SWPlot.All = plot(handles.axes_individual_wave, data_to_plot',...
'color', [0.6 0.6 0.6],...
'linewidth', 1,...
'visible', 'off');
% plot the reference wave
handles.SWPlot.Ref = plot(handles.axes_individual_wave, Data.([handles.SW_Type, 'Ref'])(handles.SW(nSW).Ref_Region(1), range)',...
'color', 'r',...
'linewidth', 3);
% plot wavelets
switch handles.SW_Type
case 'SS'
% find the maximum point in the actual data to scale the wavelet power
data_max = ceil(abs(max(max(...
Data.Raw(handles.SW(nSW).Channels_Active, range))))...
/ 10) * 10 + 10;
data = Data.CWT(handles.SW(nSW).Ref_Region(1), range);
handles.SWPlot.CWT(1) = plot(handles.axes_individual_wave,...
(data./max(data) * data_max) - data_max,...
'color', 'b',...
'linewidth', 1);
case 'ST'
% check if the wave plot check boxes are active
if get(handles.cb_waveplot(1), 'value')
handles.SWPlot.CWT(1) = plot(handles.axes_individual_wave,...
Data.CWT{1}(handles.SW(nSW).Ref_Region(1), range)',...
'color', 'b',...
'linewidth', 1);
handles.SWPlot.CWT(2) = plot(handles.axes_individual_wave,...
Data.CWT{2}(handles.SW(nSW).Ref_Region(1), range)',...
'color', 'g',...
'linewidth', 1);
end
end
% set only the active channels to visible
set(handles.SWPlot.All(handles.SW(nSW).Channels_Active),...
'visible', 'on');
% adjust the x-axes to match range length
set(handles.axes_individual_wave, 'xLim', [1, length(range)])
% update plot
% ^^^^^^^^^^^^
else
for n = 1:size(Data.Raw,1)
set(handles.SWPlot.All(n),...
'yData', data_to_plot(n, :),...
'color', [0.6 0.6 0.6],...
'linewidth', 1,...
'visible', 'off');
end
set(handles.SWPlot.All(handles.SW(nSW).Channels_Active),...
'visible', 'on');
set(handles.SWPlot.Ref,...
'yData', Data.([handles.SW_Type, 'Ref'])(handles.SW(nSW).Ref_Region(1), range));
% Find the absolute maximum value and round to higher 10, then add 10 for space
data_max = ceil(abs(max(max(Data.Raw(handles.SW(nSW).Channels_Active, range))))/10)*10+10;
set(handles.axes_individual_wave, 'yLim', [-data_max, data_max])
% update the cwt data...
switch handles.SW_Type
case 'SS'
data = Data.CWT(handles.SW(nSW).Ref_Region(1),range);
set(handles.SWPlot.CWT(1),...
'yData', (data./max(data) * data_max) - data_max);
case 'ST'
% check if the wave plot check boxes are active
if get(handles.cb_waveplot(1), 'value')
set(handles.SWPlot.CWT(1),...
'yData', Data.CWT{1}(handles.SW(nSW).Ref_Region(1), range));
set(handles.SWPlot.CWT(2),...
'yData', Data.CWT{2}(handles.SW(nSW).Ref_Region(1), range));
end
end
end
function handles = update_SWDelay(handles, nFigure)
% plot the delay/involvement map
% get the current wave number
nSW = handles.java.Spinner.getValue();
% clear the axes for a new plot
if nFigure ~= 1;
cla(handles.ax_Delay);
end
% check for grid size parameter to create maps
if ~isfield(handles.Info.Parameters, 'Travelling_GS')
handles.Info.Parameters.Travelling_GS = 40;
end
% plot the Delay Map...
if handles.java.PlotBox.getSelectedIndex() + 1 == 1
% take the delay map from the SW structure if possible
if ~isempty(handles.SW(nSW).Travelling_DelayMap)
H = swa_Topoplot...
(handles.SW(nSW).Travelling_DelayMap, handles.Info.Electrodes,...
'NewFigure', nFigure ,...
'Axes', handles.ax_Delay ,...
'NumContours', 10 ,...
'PlotContour', 1 ,...
'PlotSurface', get(handles.Surface_Delay, 'value'),...
'PlotChannels', get(handles.Channels_Delay, 'value'),...
'PlotStreams', get(handles.Streams_Delay, 'value'),...
'Streams', handles.SW(nSW).Travelling_Streams);
% if there is no delay map make one
else
H = swa_Topoplot...
([], handles.Info.Electrodes, ...
'Data', handles.SW(nSW).Travelling_Delays ,...
'GS', handles.Info.Parameters.Travelling_GS,...
'NewFigure', nFigure ,...
'Axes', handles.ax_Delay ,...
'NumContours', 10 ,...
'PlotContour', 1 ,...
'PlotSurface', get(handles.Surface_Delay, 'value'),...
'PlotChannels', get(handles.Channels_Delay, 'value'),...
'PlotStreams', get(handles.Streams_Delay, 'value'),...
'Streams', handles.SW(nSW).Travelling_Streams);
end
if get(handles.Origins_Delay, 'Value') == 1 && exist('H', 'var')
if isfield(H, 'Channels')
set(H.Channels(handles.SW(nSW).Travelling_Delays<2),...
'String', 'o' ,...
'FontSize', 12 );
end
end
% Or plot the involvement map (peak 2 peak amplitudes for active channels
elseif handles.java.PlotBox.getSelectedIndex() + 1 == 2;
% plot different data for various wavetypes
switch handles.SW_Type
case 'SW'
data_to_plot = handles.SW(nSW).Channels_NegAmp;
case {'SS', 'ST'}
data_to_plot = handles.SW(nSW).Channels_Power;
handles.SW(nSW).Travelling_Streams = [];
end
swa_Topoplot...
([], handles.Info.Electrodes ,...
'Data', data_to_plot ,...
'GS', handles.Info.Parameters.Travelling_GS,...
'NewFigure', nFigure ,...
'Axes', handles.ax_Delay ,...
'NumContours', 10 ,...
'PlotContour', 1 ,...
'PlotSurface', get(handles.Surface_Delay, 'value'),...
'PlotChannels', get(handles.Channels_Delay, 'value'),...
'PlotStreams', get(handles.Streams_Delay, 'value'),...
'Streams', handles.SW(nSW).Travelling_Streams);
end