-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbatch_run.m
More file actions
1271 lines (1041 loc) · 54.9 KB
/
Copy pathbatch_run.m
File metadata and controls
1271 lines (1041 loc) · 54.9 KB
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
function varargout = batch_run(varargin)
%batch_run(varargin)
%batch mode portion of the Stanford EDF Viewer
%Written by Hyatt Moore IV
%modified September 18, 2012
% added channel_config component to event_settings struct to help audit
% synthetic channels used for events. These are inserted into database
% when applicable now due to changes in CLASS_events_container.
%last edit: 18 July, 2012
% Edit the above text to modify the response to help batch_run
% Last Modified by GUIDE v2.5 05-May-2015 11:12:09
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @batch_run_OpeningFcn, ...
'gui_OutputFcn', @batch_run_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
end
% --- Executes just before batch_run is made visible.
function batch_run_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to batch_run (see VARARGIN)
global MARKING;
global GUI_TEMPLATE;
%if MARKING is not initialized, then call sev.m with 'batch' argument in
%order to initialize the MARKING global before returning here.
if(isempty(MARKING))
sev('batch'); %runs the sev first, and then goes to the default batch run...?
else
%have to assign user data to the button that handles multiple channel
%sourcing
maxSourceChannelsAllowed = 14;
userdata.nReqdIndices = maxSourceChannelsAllowed;
userdata.selectedIndices = 1:maxSourceChannelsAllowed;
set(handles.buttonEventSelectSources,'userdata',userdata,'value',0);
%still using a global here; not great...
createGlobalTemplate(handles);
loadDetectionMethods();
set(handles.push_synth_CHANNEL_settings,...
'callback',{@synthesize_CHANNEL_configuration_callback,...
handles.menu_synth_CHANNEL_channel1,handles.edit_synth_CHANNEL_name});
set(handles.menu_event_method,'string',GUI_TEMPLATE.detection.labels,'callback',...
{@menu_event_callback,[handles.menu_event_channel1,handles.menu_event_channel2],handles.push_event_settings,handles.buttonEventSelectSources});
userdata.channel_h = handles.menu_psd_channel;
userdata.settings_h = handles.push_psd_settings;
set(handles.pop_spectral_method,'userdata',userdata,'callback',{@pop_spectral_method_Callback,handles.menu_psd_channel,handles.push_psd_settings},...
'enable','off','string',GUI_TEMPLATE.spectrum_labels);
set(handles.menu_artifact_method,'string',GUI_TEMPLATE.detection.labels,'callback',...
{@menu_event_callback,[handles.menu_artifact_channel1,handles.menu_artifact_channel2],handles.push_artifact_settings,handles.buttonArtifactSelectSources});
set(handles.push_psd_settings,'enable','off','userdata',MARKING.SETTINGS.PSD);
if(isfield(MARKING.SETTINGS.BATCH_PROCESS,'edf_folder'))
if(~isdir(MARKING.SETTINGS.BATCH_PROCESS.edf_folder) || strcmp(MARKING.SETTINGS.BATCH_PROCESS.edf_folder,'.'))
MARKING.SETTINGS.BATCH_PROCESS.edf_folder = pwd;
end;
set(handles.edit_edf_directory,'string',MARKING.SETTINGS.BATCH_PROCESS.edf_folder);
else
set(handles.edit_edf_directory,'string',pwd);
end
% set( [
% handles.text_event_export_img;
% handles.check_event_export_images;
% handles.text_artifact_export_img;
% handles.check_artifact_export_images],'enable','off');
checkPathForEDFs(handles); %Internally, this calls getPlayList since no argument is given.
set([handles.menu_artifact_channel1
handles.menu_event_channel1],'enable','off','string','Channel 1');
set([handles.menu_artifact_channel2
handles.menu_event_channel2],'enable','off','string','Channel 2');
set([handles.push_event_settings
handles.push_artifact_settings],'enable','off');
handles.user.BATCH_PROCESS = MARKING.SETTINGS.BATCH_PROCESS;
handles.user.PSD = MARKING.SETTINGS.PSD;
handles.user.PSD = MARKING.SETTINGS.PSD;
% Choose default command line output for batch_run
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
end
end
function addCHANNELRow(handles)
resizeForAddedRow(handles,handles.panel_synth_CHANNEL);
end
function addEventRow(handles)
%adds an event selection/detection row to the specified panel
%make room for the event row
resizeForAddedRow(handles,handles.panel_events);
end
function addArtifactRow(handles)
resizeForAddedRow(handles,handles.panel_artifact);
end
function addPSDRow(handles)
resizeForAddedRow(handles,handles.panel_psd);
end
function resizeForAddedRow(handles,resized_panel_h)
global GUI_TEMPLATE;
%move all of the children up to account for the change in size and location
%of the panel being resized.
pan_children = allchild(resized_panel_h);
children_pos = cell2mat(get(pan_children,'position'));
children_pos(:,2)=children_pos(:,2)+GUI_TEMPLATE.row_separation;
for k =1:numel(pan_children), set(pan_children(k),'position',children_pos(k,:));end;
resized_panel_pos = get(resized_panel_h,'position');
h = [handles.panel_directory
handles.panel_synth_CHANNEL
handles.panel_events
handles.panel_artifact
handles.panel_psd
handles.push_run
handles.figure1];
for k=1:numel(h)
pos = get(h(k),'position');
if(h(k) == handles.figure1)
pos(2) = pos(2)-GUI_TEMPLATE.row_separation;
pos(4) = pos(4)+GUI_TEMPLATE.row_separation;
elseif(h(k)==resized_panel_h)
pos(4) = pos(4)+GUI_TEMPLATE.row_separation;
elseif(pos(2)>resized_panel_pos(2))
pos(2) = pos(2)+GUI_TEMPLATE.row_separation;
end;
set(h(k),'position',pos);
end
%add the additional controls depending on the panel being adjusted.
if(resized_panel_h==handles.panel_psd)
hc1 = uicontrol(GUI_TEMPLATE.channel1,'parent',resized_panel_h,'string',GUI_TEMPLATE.EDF.labels);
h_params = uicontrol(GUI_TEMPLATE.push_parameter_settings,'parent',resized_panel_h,'userdata',handles.user.PSD);
userdata.channel_h = hc1;
userdata.settings_h = h_params;
uicontrol(GUI_TEMPLATE.spectrum,'parent',resized_panel_h,'enable','on',...
'callback',{@pop_spectral_method_Callback,hc1,h_params},'userdata',userdata);
elseif(resized_panel_h==handles.panel_synth_CHANNEL)
%add a source channel - channel1
hc1 = uicontrol(GUI_TEMPLATE.channel1,'parent',resized_panel_h,'string',GUI_TEMPLATE.EDF.labels,'enable','on');
%add the edit output channel name
he1 = uicontrol(GUI_TEMPLATE.edit_synth_CHANNEL,'parent',resized_panel_h);
%add the configuration/settings button
h_params = uicontrol(GUI_TEMPLATE.push_CHANNEL_configuration,'parent',resized_panel_h,'enable','on',...
'callback',{@synthesize_CHANNEL_configuration_callback,hc1,he1});
else
hc1=uicontrol(GUI_TEMPLATE.channel1,'parent',resized_panel_h);
hc2=uicontrol(GUI_TEMPLATE.channel2,'parent',resized_panel_h);
buttonEventSelectSources = uicontrol(GUI_TEMPLATE.buttonEventSelectSources,'parent',resized_panel_h);
h_check_save_img = uicontrol(GUI_TEMPLATE.check_save_image,'parent',resized_panel_h);
h_params=uicontrol(GUI_TEMPLATE.push_parameter_settings,'parent',resized_panel_h);
uicontrol(GUI_TEMPLATE.evt_method,'parent',resized_panel_h,'callback',{@menu_event_callback,[hc1,hc2],h_params,buttonEventSelectSources});
end;
end
% --- Outputs from this function are returned to the command line.
function varargout = batch_run_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
try
varargout{1} = handles.output;
catch me
varargout{1} = [];
end
end
% --- Executes on button press in push_directory.
function push_directory_Callback(hObject, eventdata, handles)
% hObject handle to push_directory (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
path = get(handles.edit_edf_directory,'string');
if(~exist(path,'file'))
path = handles.user.BATCH_PROCESS.edf_folder;
end
pathname = uigetdir(path,'Select the directory containing EDF files to process');
if(isempty(pathname)||(isnumeric(pathname)&&pathname==0))
pathname = path;
end
handles.user.BATCH_PROCESS.edf_folder = pathname;
guidata(hObject,handles);
set(handles.edit_edf_directory,'string',pathname);
checkPathForEDFs(handles);
end
function playlist = getPlaylist(handles,ply_filename)
if(nargin==2)
if(strcmpi(ply_filename,'-gui'))
%make an educated guess regarding the file to be loaded
fileGuess = get(handles.edit_selectPlaylist,'string');
if(~exist(fileGuess,'file'))
fileGuess = get(handles.edit_edf_directory,'string');
end
[ply_filename, pathname, ~] = uigetfile({'*.ply','.EDF play list (*.ply)'},'Select batch mode play list',fileGuess,'MultiSelect','off');
%did the user press cancel
if(isnumeric(ply_filename) && ~ply_filename)
ply_filename = [];
else
ply_filename = fullfile(pathname,ply_filename);
end
end
else
if(strcmpi('on',get(handles.radio_processList,'enable')) && get(handles.radio_processList,'value'))
ply_filename = get(handles.edit_selectPlaylist,'string');
else
ply_filename = []; %just in case this is called unwantedly
end
end
if(exist(ply_filename,'file'))
fid = fopen(ply_filename);
data = textscan(fid,'%[^\r\n]');
playlist = data{1};
fclose(fid);
else
playlist = [];
end
%update the gui
if(isempty(playlist))
set(handles.radio_processAll,'value',1);
set(handles.edit_selectPlaylist,'string','<click to select play list>');
else
set(handles.radio_processList,'value',1);
set(handles.edit_selectPlaylist,'string',ply_filename);
end
end
function filtered_file_struct = filterPlaylist(file_struct,file_filter_list)
if(~isempty(file_filter_list))
filename_cell = cell(numel(file_struct),1);
[filename_cell{:}] = file_struct.name;
[~,~,intersect_indices] = intersect(file_filter_list,filename_cell); %need to handle case sensitivity
filtered_file_struct = file_struct(intersect_indices);
else
filtered_file_struct = file_struct; %i.e. nothing to filter
end
end
function checkPathForEDFs(handles,playlist)
%looks in the path for EDFs
global GUI_TEMPLATE;
if(nargin<2)
playlist = getPlaylist(handles);
end
path = get(handles.edit_edf_directory,'string');
if(~exist(path,'file'))
EDF_message = 'Directory does not exist. ';
num_edfs = 0;
else
%pc's do not have a problem with case; unfortunately the other side
%does in prior versions...
% if(ispc)
% edf_file_list = dir(fullfile(path,'*.EDF'));
% else
% edf_file_list = [dir(fullfile(path, '*.EDF'));dir(fullfile(path, '*.edf'))]; %dir(fullfile(path, '*.EDF'))];
% end
edf_file_list = dir(fullfile(path,'*.EDF'));
num_edfs_all = numel(edf_file_list);
if(~isempty(playlist))
edf_file_list = filterPlaylist(edf_file_list,playlist);
end
num_edfs = numel(edf_file_list);
bytes_cell = cell(num_edfs,1);
[bytes_cell{:}]=edf_file_list.bytes;
total_bytes = sum(cell2mat(bytes_cell))/1E6;
if(~isempty(playlist))
EDF_message = [num2str(num_edfs),' EDF files (',num2str(total_bytes,'%0.2f'),' MB) found in the current play list. '];
else
EDF_message = [num2str(num_edfs),' EDF files (',num2str(total_bytes,'%0.2f'),' MB) found in the current directory. '];
end
end;
if(num_edfs==0)
if(num_edfs_all==0)
EDF_message = [EDF_message, 'Please choose a different directory'];
set(get(handles.bg_panel_playlist,'children'),'enable','off');
else
EDF_message = [EDF_message, 'Please select a different play list or use ''All'''];
end
set(handles.push_run,'enable','off');
EDF_labels = 'No Channels Available';
set(get(handles.panel_synth_CHANNEL,'children'),'enable','off');
set(get(handles.panel_events,'children'),'enable','off');
set(get(handles.panel_psd,'children'),'enable','off');
set(get(handles.panel_artifact,'children'),'enable','off');
updateSave2ImageOptions(handles);
else
set(get(handles.panel_synth_CHANNEL,'children'),'enable','on');
set(handles.edit_synth_CHANNEL_name,'enable','off');
set(handles.push_run,'enable','on');
set(get(handles.panel_events,'children'),'enable','on');
% set(get(handles.panel_psd,'children'),'enable','on');
set(handles.pop_spectral_method,'enable','on');
set(handles.push_add_psd,'enable','on');
set(get(handles.panel_artifact,'children'),'enable','on');
set(get(handles.bg_panel_playlist,'children'),'enable','on');
set(handles.edit_selectPlaylist,'enable','inactive');
first_edf_filename = edf_file_list(1).name;
HDR = loadEDF(fullfile(path,first_edf_filename));
EDF_labels = HDR.label;
end;
GUI_TEMPLATE.EDF.labels = EDF_labels;
set(handles.text_edfs_to_process,'string',EDF_message);
%adjust all popupmenu selection data/strings for changed EDF labels
set(...
findobj(handles.figure1,'-regexp','tag','.*channel.*'),...
'string',EDF_labels);
end
function edit_edf_directory_Callback(hObject, eventdata, handles)
% hObject handle to edit_edf_directory (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
checkPathForEDFs(handles);
end
% --- Executes during object creation, after setting all properties.
function edit_edf_directory_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_edf_directory (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
% --- Executes on button press in push_run.
function push_run_Callback(hObject, eventdata, handles)
% hObject handle to push_run (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%
%This function can only be called when there a valid directory (one which
%contains EDF files) has been selected.
%This function grabs the entries from the GUI and puts them into the global
%variable BATCH_PROCESS which will be referenced during the batch
%processing.
global GUI_TEMPLATE;
global MARKING;
BATCH_PROCESS = handles.user.BATCH_PROCESS;
% BATCH_PROCESS.output_files.MUSIC_filename = 'MUSIC'; %already set in the
% _sev.parameters.txt
EDF_labels = GUI_TEMPLATE.EDF.labels;
detection_inf = GUI_TEMPLATE.detection;
%% grab the synthesize channel configurations
%flip handles up and down to put in more correct order as seen by the user from top to bottom
synth_channel_settings_h = flipud(findobj(handles.panel_synth_CHANNEL,'-regexp','tag','push_synth_CHANNEL_settings'));
synth_channel_names_h = flipud(findobj(handles.panel_synth_CHANNEL,'-regexp','tag','edit_synth_CHANNEL_name'));
synth_channel_structs = get(synth_channel_settings_h,'userdata');
synth_channel_names = get(synth_channel_names_h,'string');
if(~iscell(synth_channel_names))
synth_channel_names = {synth_channel_names};
synth_channel_structs = {synth_channel_structs};
end
synth_indices = false(numel(synth_channel_structs),1);
for k=1:numel(synth_indices)
if(~isempty(synth_channel_names{k})&&~isempty(synth_channel_structs{k}))
synth_indices(k)= true;
%for the case where the synthetic channel has multiple
%configurations for it (e.g. adaptive noise cancel followed by
%wavelet denoising
for p=1:numel(synth_channel_structs{k})
if(isempty(synth_channel_structs{k}(p).params))
pfile = fullfile(MARKING.SETTINGS.rootpathname,MARKING.SETTINGS.VIEW.filter_path,strcat(synth_channel_structs{k}(p).m_file,'.plist'));
matfile = fullfile(MARKING.SETTINGS.rootpathname,MARKING.SETTINGS.VIEW.filter_path,strcat(synth_channel_structs{k}(p).m_file,'.mat'));
if(exist(pfile,'file'))
try
synth_channel_structs{k}(p).params = plist.loadXMLPlist(pfile);
catch me
fprintf(1,'Could not load parameters from %s directly.\n',pfile);
showME(me);
end
elseif(exist(matfile,'file'))
try
matfileStruct = load(matfile);
synth_channel_structs{k}(p).params = matfileStruct.params;
catch me
fprintf(1,'Could not load parameters from %s directly.\n',matfile);
showME(me);
end
end
end
end
end
end
synth_channel_structs = synth_channel_structs(synth_indices);
synth_channel_names = synth_channel_names(synth_indices);
BATCH_PROCESS.synth_CHANNEL.names = synth_channel_names;
BATCH_PROCESS.synth_CHANNEL.structs = synth_channel_structs;
%this is for the source channels found in the .EDF which need to be loaded
%in order to subsequently synthesize the channels in BATCH_PROCESS.synth_CHANNEL
synth_channel_settings_lite = cell(numel(synth_channel_names),1);
for k = 1:numel(synth_channel_structs)
labels = {synth_channel_structs{k}.src_channel_label}; %keep it as a cell for loading later in batch.load_file subfunction getChannelIndices
for j=1:numel(synth_channel_structs{k})
labels = [labels, synth_channel_structs{k}(j).ref_channel_label];
end
synth_channel_settings_lite{k}.channel_labels = labels;
end
BATCH_PROCESS.synth_CHANNEL.settings_lite = synth_channel_settings_lite; %necessary for loading the channels with batch.load_file
%% grab the PSD parameters
psd_spectral_methods_h = findobj(handles.panel_psd,'-regexp','tag','pop_spectral_method');
selected_PSD_channels = [];
psd_channel_settings = {};
selected_MUSIC_channels = [];
MUSIC_channel_settings = {};
selected_coherence_channels = [];
coherence_channel_settings = {};
for k=1:numel(psd_spectral_methods_h)
method = GUI_TEMPLATE.spectrum_labels{get(psd_spectral_methods_h(k),'value')}; %labels defined in opening function at {'None','PSD','MUSIC'}
userdata = get(psd_spectral_methods_h(k),'userdata');
switch(lower(method))
case 'none'
case 'psd'
selected_PSD_channels(end+1) = get(userdata.channel_h,'value');
psd_channel_settings{end+1} = get(userdata.settings_h,'userdata');
case 'music'
selected_MUSIC_channels(end+1) = get(userdata.channel_h,'value');
MUSIC_channel_settings{end+1} = get(userdata.settings_h,'userdata');
case 'coherence'
selected_coherence_channels(end+1) = get(userdata.channel_h,'value');
coherence_channel_settings{end+1} = get(userdata.settings_h,'userdata');
otherwise
disp(['unhandled selection ',lower(method)]);
end
end
%PSD
num_selected_PSD_channels = numel(selected_PSD_channels);
PSD_settings = cell(num_selected_PSD_channels,1);
for k = 1:num_selected_PSD_channels
PSDstruct = psd_channel_settings{k};
PSDstruct.channel_labels = EDF_labels(selected_PSD_channels(k));
PSD_settings{k} = PSDstruct;
end
BATCH_PROCESS.PSD_settings = PSD_settings;
%MUSIC
num_selected_MUSIC_channels = numel(selected_MUSIC_channels);
MUSIC_settings = cell(num_selected_MUSIC_channels,1);
for k = 1:num_selected_MUSIC_channels
MUSICstruct = MUSIC_channel_settings{k};
MUSICstruct.channel_labels = EDF_labels(selected_MUSIC_channels(k));
MUSIC_settings{k} = MUSICstruct;
end
BATCH_PROCESS.MUSIC_settings = MUSIC_settings;
BATCH_PROCESS.standard_epoch_sec = MARKING.SETTINGS.VIEW.standard_epoch_sec;
BATCH_PROCESS.base_samplerate = MARKING.SETTINGS.VIEW.samplerate;
%The following snippet was an alternative, but I found it easier to keep
%the same cell of structures format as the events and artifact settings
%below, when dealing with processing functions such as batch.load_file and
%such;
% BATCH_PROCESS.PSD_settings.channel_labels= EDF_labels(psd_menu_values);
%grab the event detection paramaters
% This is the indices of the event method(s) selected from the event method
% drop down widget. One value per event
event_method_values = get(flipud(findobj(handles.panel_events,'-regexp','tag','method')),'value');
event_channel1_values = get(flipud(findobj(handles.panel_events,'-regexp','tag','channel1')),'value');
event_channel2_values = get(flipud(findobj(handles.panel_events,'-regexp','tag','channel2')),'value');
%obtain the userdata and value fields of the multichannel source button.
event_multichannel_data = get(flipud(findobj(handles.panel_events,'tag','buttonEventSelectSources')),'userdata');
event_multichannel_value = get(flipud(findobj(handles.panel_events,'tag','buttonEventSelectSources')),'value');
event_settings_handles = flipud(findobj(handles.panel_events,'-regexp','tag','settings'));
event_save_image_choices = get(flipud(findobj(handles.panel_events,'-regexp','tag','images')),'value');
% convert from cell structures where needed.
if(iscell(event_settings_handles))
event_settings_handles = cell2mat(event_settings_handles);
end
if(iscell(event_method_values))
event_method_values = cell2mat(event_method_values);
event_channel1_values = cell2mat(event_channel1_values);
event_channel2_values = cell2mat(event_channel2_values);
event_multichannel_data = cell2mat(event_multichannel_data);
event_multichannel_value = cell2mat(event_multichannel_value);
event_save_image_choices = cell2mat(event_save_image_choices);
end
% The user can select 'none' for an event. We want to remove these.
selected_events = event_method_values>1;
event_method_values = event_method_values(selected_events);
event_settings_handles = event_settings_handles(selected_events);
event_channel_values = [event_channel1_values(selected_events),event_channel2_values(selected_events)];
event_save_image_choices = event_save_image_choices(selected_events);
event_multichannel_data = event_multichannel_data(selected_events);
event_multichannel_value = event_multichannel_value(selected_events);
num_selected_events = sum(selected_events);
event_settings = cell(num_selected_events,1);
for k = 1:num_selected_events
selected_method = event_method_values(k);
num_reqd_channels = detection_inf.reqd_indices(selected_method);
eventStruct.numConfigurations = 1;
eventStruct.save2img = event_save_image_choices(k);
%if we are using a multiple channel sourced event method
if(event_multichannel_value(k))
eventStruct.channel_labels = EDF_labels(event_multichannel_data(k).selectedIndices);
else
eventStruct.channel_labels = EDF_labels(event_channel_values(k,1:num_reqd_channels));
end
eventStruct.channel_configs = cell(size(eventStruct.channel_labels));
%check to see if we are using a synthesized channel so we can audit it
if(~isempty(BATCH_PROCESS.synth_CHANNEL.names))
for ch=1:numel(eventStruct.channel_labels)
eventStruct.channel_configs{ch} = BATCH_PROCESS.synth_CHANNEL.structs(strcmp(eventStruct.channel_labels{ch},BATCH_PROCESS.synth_CHANNEL.names)); %insert the corresponding synthetic channel where applicable
% This was commented out on 7/12/2014->
% channel_config = BATCH_PROCESS.synth_CHANNEL.structs(strcmp(eventStruct.channel_labels{ch},BATCH_PROCESS.synth_CHANNEL.names)); %insert the corresponding synthetic channel where applicable
% This was found commented out on 7/12/2014->
% if(~isempty(channel_config))
% channel_config = channel_config{1};
% channel_config.channel_label = eventStruct.channel_labels{ch};
% eventStruct.channel_configs{ch} = channel_config;
% end
end
end
eventStruct.method_label = detection_inf.labels{selected_method};
eventStruct.method_function = detection_inf.mfile{selected_method};
eventStruct.batch_mode_label = char(detection_inf.batch_mode_label{selected_method});
settings_userdata = get(event_settings_handles(k),'userdata');
eventStruct.pBatchStruct = settings_userdata.pBatchStruct;
eventStruct.rocStruct = settings_userdata.rocStruct;
params = [];
% may not work on windows platform....
% if there is a change to the settings in the batch mode, then make sure
% that the change occurs here as well
if(~isempty(eventStruct.pBatchStruct))
for p=1:numel(eventStruct.pBatchStruct)
params.(eventStruct.pBatchStruct{p}.key) = eventStruct.pBatchStruct{p}.start;
end
else
pfile = ['+detection/',eventStruct.method_function,'.plist'];
if(exist(pfile,'file'))
params =plist.loadXMLPlist(pfile);
else
mfile = ['detection.',eventStruct.method_function];
params = feval(mfile);
end
end
eventStruct.detectorID = [];
eventStruct.params = params;
if(BATCH_PROCESS.database.auto_config==0 && BATCH_PROCESS.database.config_start>=0)
eventStruct.configID = BATCH_PROCESS.database.config_start;
else
eventStruct.configID = 0; %0 represents autoconfiguration required
end
event_settings{k} = eventStruct;
end
BATCH_PROCESS.event_settings = event_settings;
%grab the artifact detection paramaters
artifact_method_values = get(flipud(findobj(handles.panel_artifact,'-regexp','tag','method')),'value');
artifact_channel1_values = get(flipud(findobj(handles.panel_artifact,'-regexp','tag','channel1')),'value');
artifact_channel2_values = get(flipud(findobj(handles.panel_artifact,'-regexp','tag','channel2')),'value');
if(iscell(artifact_method_values))
artifact_method_values = cell2mat(artifact_method_values);
artifact_channel1_values = cell2mat(artifact_channel1_values);
artifact_channel2_values = cell2mat(artifact_channel2_values);
end
artifact_settings_handles = flipud(findobj(handles.panel_artifact,'-regexp','tag','settings'));
if(iscell(artifact_settings_handles))
artifact_settings_handles = cell2mat(artifact_settings_handles);
end
artifact_save_image_choices = get(flipud(findobj(handles.panel_artifact,'-regexp','tag','images')),'value');
if(iscell(artifact_save_image_choices))
artifact_save_image_choices = cell2mat(artifact_save_image_choices);
end
selected_artifacts = artifact_method_values>1;
artifact_save_image_choices = artifact_save_image_choices(selected_artifacts);
artifact_settings_handles = artifact_settings_handles(selected_artifacts);
artifact_method_values = artifact_method_values(selected_artifacts);
artifact_channel_values = [artifact_channel1_values(selected_artifacts),artifact_channel2_values(selected_artifacts)];
num_selected_artifacts = sum(selected_artifacts);
artifact_settings = batch.getArtifactStruct(num_selected_artifacts);
%if num_selected_artifacts>0
% artifact_settings = cell(num_selected_events,1);
% else
% artifact_settings = {};
% end
for k = 1:num_selected_artifacts
selected_method = artifact_method_values(k);
num_reqd_channels = detection_inf.reqd_indices(selected_method);
artifactStruct.save2img = artifact_save_image_choices(k);
artifactStruct.channel_labels = EDF_labels(artifact_channel_values(k,1:num_reqd_channels));
artifactStruct.method_label = detection_inf.labels{selected_method};
artifactStruct.method_function = detection_inf.mfile{selected_method};
artifactStruct.batch_mode_label = char(detection_inf.batch_mode_label{selected_method});
settings_userdata = get(artifact_settings_handles(k),'userdata');
pBatchStruct = settings_userdata.pBatchStruct;
params = [];
%for artifacts, only apply the first step in each case, that is the
%start value given
if(~isempty(pBatchStruct))
for key_ind=1:numel(pBatchStruct)
params.(pBatchStruct{key_ind}.key)=pBatchStruct{key_ind}.start;
end
else
pfile = ['+detection/',artifactStruct.method_function,'.plist'];
if(exist(pfile,'file'))
params =plist.loadXMLPlist(pfile);
else
mfile = ['detection.',artifactStruct.method_function];
params = feval(mfile);
end
end
%left overs fromn April 9, 2012 - which may not be necessary anymore...
% params = [];
% %may not work on windows platform....
% pfile = ['+detection/',artifactStruct.method_function,'.plist'];
% if(exist(pfile,'file'))
% params =plist.loadXMLPlist(pfile);
% end
% else
% params = [];
artifactStruct.params = params;
artifact_settings(k) = artifactStruct;
end
BATCH_PROCESS.artifact_settings = artifact_settings;
pathname = get(handles.edit_edf_directory,'string');
playlist = getPlaylist(handles);
MARKING = batch.batch_process(pathname, BATCH_PROCESS, playlist, MARKING);
% warndlg({'you are starting the batch mode with the following channels',BATCH_PROCESS.PSD_settings});
%goal two - run the batch mode with knowledge of the PSD channel only...
end
% --- Executes on button press in push_add_event.
function push_add_event_Callback(hObject, eventdata, handles)
% hObject handle to push_add_event (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
addEventRow(handles);
end
% --- Executes on button press in push_add_psd.
function push_add_psd_Callback(hObject, eventdata, handles)
% hObject handle to push_add_psd (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
addPSDRow(handles);
end
% --- Executes on button press in push_add_artifact.
function push_add_artifact_Callback(hObject, eventdata, handles)
% hObject handle to push_add_artifact (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
addArtifactRow(handles);
end
function createGlobalTemplate(handles)
%uses the intial panel entries created with GUIDE to serve as templates for
%adding more entries later.
global GUI_TEMPLATE;
edit_synth_CHANNEL = get(handles.edit_synth_CHANNEL_name);
push_CHANNEL_configuration = get(handles.push_synth_CHANNEL_settings);
channel1 = get(handles.menu_event_channel1);
channel2 = get(handles.menu_event_channel2);
check_save_image = get(handles.check_event_export_images);
push_parameter_settings = get(handles.push_event_settings);
buttonEventSelectSources = get(handles.buttonEventSelectSources);
buttonArtifactSelectSources = get(handles.buttonEventSelectSources);
evt_method = get(handles.menu_event_method);
spectrum = get(handles.pop_spectral_method);
%I should really consider implementing a for loop at this point....
%the added Position and removal is to bypass a warning that pops because
%Matalb does not like the units field to follow the position field when
%initializing a uicontrol- notice that the copy is a lower case and thus
%different than the upper-cased Position name
edit_synth_CHANNEL = rmfield(edit_synth_CHANNEL,'Type');
edit_synth_CHANNEL = rmfield(edit_synth_CHANNEL,'Extent');
edit_synth_CHANNEL = rmfield(edit_synth_CHANNEL,'BeingDeleted');
edit_synth_CHANNEL.position = edit_synth_CHANNEL.Position;
edit_synth_CHANNEL = rmfield(edit_synth_CHANNEL,'Position');
push_CHANNEL_configuration = rmfield(push_CHANNEL_configuration,'Type');
push_CHANNEL_configuration = rmfield(push_CHANNEL_configuration,'Extent');
push_CHANNEL_configuration = rmfield(push_CHANNEL_configuration,'BeingDeleted');
push_CHANNEL_configuration.position = push_CHANNEL_configuration.Position;
push_CHANNEL_configuration = rmfield(push_CHANNEL_configuration,'Position');
check_save_image = rmfield(check_save_image,'Type');
check_save_image = rmfield(check_save_image,'Extent');
check_save_image = rmfield(check_save_image,'BeingDeleted');
check_save_image.position = check_save_image.Position;
check_save_image = rmfield(check_save_image,'Position');
spectrum = rmfield(spectrum,'Type');
spectrum = rmfield(spectrum,'Extent');
spectrum = rmfield(spectrum,'BeingDeleted');
spectrum.position = spectrum.Position;
spectrum = rmfield(spectrum,'Position');
channel1 = rmfield(channel1,'Type');
channel1 = rmfield(channel1,'Extent');
channel1 = rmfield(channel1,'BeingDeleted');
channel1.position = channel1.Position;
channel1 = rmfield(channel1,'Position');
channel2 = rmfield(channel2,'Type');
channel2 = rmfield(channel2,'Extent');
channel2 = rmfield(channel2,'BeingDeleted');
channel2.position = channel2.Position;
channel2 = rmfield(channel2,'Position');
buttonEventSelectSources = rmfield(buttonEventSelectSources,'Type');
buttonEventSelectSources = rmfield(buttonEventSelectSources,'Extent');
buttonEventSelectSources = rmfield(buttonEventSelectSources,'BeingDeleted');
buttonEventSelectSources.position = buttonEventSelectSources.Position;
buttonEventSelectSources = rmfield(buttonEventSelectSources,'Position');
buttonArtifactSelectSources = rmfield(buttonArtifactSelectSources,'Type');
buttonArtifactSelectSources = rmfield(buttonArtifactSelectSources,'Extent');
buttonArtifactSelectSources = rmfield(buttonArtifactSelectSources,'BeingDeleted');
buttonArtifactSelectSources.position = buttonArtifactSelectSources.Position;
buttonArtifactSelectSources = rmfield(buttonArtifactSelectSources,'Position');
push_parameter_settings = rmfield(push_parameter_settings,'Type');
push_parameter_settings = rmfield(push_parameter_settings,'Extent');
push_parameter_settings = rmfield(push_parameter_settings,'BeingDeleted');
push_parameter_settings.position = push_parameter_settings.Position;
push_parameter_settings = rmfield(push_parameter_settings,'Position');
evt_method = rmfield(evt_method,'Type');
evt_method = rmfield(evt_method,'Extent');
evt_method = rmfield(evt_method,'BeingDeleted');
evt_method.position = evt_method.Position;
evt_method = rmfield(evt_method,'Position');
GUI_TEMPLATE.edit_synth_CHANNEL = edit_synth_CHANNEL;
GUI_TEMPLATE.push_CHANNEL_configuration = push_CHANNEL_configuration;
GUI_TEMPLATE.check_save_image = check_save_image;
GUI_TEMPLATE.spectrum = spectrum;
GUI_TEMPLATE.channel1 = channel1;
GUI_TEMPLATE.channel2 = channel2;
GUI_TEMPLATE.evt_method = evt_method;
GUI_TEMPLATE.push_parameter_settings = push_parameter_settings;
GUI_TEMPLATE.num_synth_channels = 0; %number of synthesized channels is zero at first
GUI_TEMPLATE.buttonEventSelectSources = buttonEventSelectSources;
GUI_TEMPLATE.buttonArtifactSelectSources = buttonArtifactSelectSources;
add_button_pos = get(handles.push_add_event,'position');
%I liked the distance between these two on the GUIDE display of the figure
%and would like to keep the same spacing for additional rows that are added
GUI_TEMPLATE.row_separation = add_button_pos(2)-evt_method.position(2);
GUI_TEMPLATE.spectrum_labels = {'None','PSD','MUSIC'};
% GUI_TEMPLATE.spectrum_labels = {'None','PSD','MUSIC','Coherence'};
end
function loadDetectionMethods()
%load up any available detection methods found in the detection_path
%(initially this was labeled '+detection' from the working path
global MARKING;
global GUI_TEMPLATE;
if(isfield(MARKING.SETTINGS.VIEW,'detection_path'))
detection_inf = fullfile(MARKING.SETTINGS.VIEW.detection_path,'detection.inf');
else
detection_inf = fullfile('+detection','detection.inf');
end
%this part is initialized for the first choice, which is 'none' - no
%artifact or event selected...
evt_label = 'none';
mfile = 'Error';
num_reqd_indices = 0;
param_gui = 'none';
batch_mode_label = '_';
if(exist(detection_inf,'file'))
[loaded_mfile, loaded_evt_label, loaded_num_reqd_indices, loaded_param_gui, loaded_batch_mode_label] = textread(detection_inf,'%s%s%n%s%s','commentstyle','shell');
evt_label = [{evt_label};loaded_evt_label];
mfile = [{mfile};loaded_mfile];
num_reqd_indices = [num_reqd_indices;loaded_num_reqd_indices];
param_gui = [{param_gui};loaded_param_gui];
batch_mode_label = [batch_mode_label; loaded_batch_mode_label];
end;
GUI_TEMPLATE.detection.labels = evt_label;
GUI_TEMPLATE.detection.mfile = mfile;
GUI_TEMPLATE.detection.reqd_indices = num_reqd_indices;
GUI_TEMPLATE.detection.param_gui = param_gui;
GUI_TEMPLATE.detection.batch_mode_label = batch_mode_label;
GUI_TEMPLATE.evt_method.String = evt_label; %need this here so that newly created rows have these detection options available.
end
%%%%%%%%%%%%%%%%%%%%%%%%%%
function settings_callback(hObject,~,~)
global GUI_TEMPLATE;
global MARKING;
% choice = userdata.choice;
% userdata = get(hObject,'userdata');
% userdata.choice = choice;
% userdata.pBatchStruct = [];
% userdata.rocStruct = [];
userdata = get(hObject,'userdata');
if(~isempty(userdata) && isfield(userdata,'pBatchStruct'))
paramStruct = userdata.pBatchStruct;
end
if(~isempty(userdata) && isfield(userdata,'rocStruct'))
rocStruct = userdata.rocStruct;
end
detectionPath = fullfile(MARKING.SETTINGS.rootpathname,MARKING.SETTINGS.VIEW.detection_path);
% detectionFilename = MARKING.SETTINGS.VIEW.detection_inf_file;
rocPath = fullfile(MARKING.SETTINGS.BATCH_PROCESS.output_path.parent,MARKING.SETTINGS.BATCH_PROCESS.output_path.roc);
detectionLabels = GUI_TEMPLATE.detection.labels{userdata.choice};
[pBatchStruct,rocStruct] = plist_batch_editor_dlg(detectionLabels,detectionPath,rocPath,paramStruct,rocStruct);
if(~isempty(pBatchStruct))
userdata.pBatchStruct =pBatchStruct;
userdata.rocStruct = rocStruct;
set(hObject,'userdata',userdata);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%
function menu_event_callback(hObject,event_data,h_pop_channels,h_push_settings,h_buttonSelectSource)
global GUI_TEMPLATE;
choice = get(hObject,'value');
settings_gui = GUI_TEMPLATE.detection.param_gui{choice};
userdata.choice = choice;
userdata.pBatchStruct = [];
userdata.rocStruct = [];
set(h_push_settings,'userdata',userdata);
if(strcmp(settings_gui,'none'))
set(h_push_settings,'enable','off','callback',[]);
else
%want to avoid calling plist_editor, and rather call plist_batch_editor
%here so that the appropriate settings can be made.
if(strcmp(settings_gui,'plist_editor_dlg'))
set(h_push_settings,'userdata',userdata,'enable','on','callback',{@settings_callback,guidata(hObject)});
else
set(h_push_settings,'enable','on','callback',settings_gui);
end
end
%turn off all channels first.
set(h_pop_channels,'visible','off');
nReqdIndices = GUI_TEMPLATE.detection.reqd_indices(choice);
if(nReqdIndices<=2)
set(h_buttonSelectSource,'visible','off','enable','off','value',0);
for k=1:nReqdIndices
set(h_pop_channels(k),'visible','on','enable','on','string',GUI_TEMPLATE.EDF.labels);
end