|
|
[[_TOC_]]
|
|
|
# Creating Marks by Using Scripts
|
|
|
Marks can also be generated from a flag structure based on any criteria you would like. Cretaing functions that test the data for particular features is most easily done by generating a script.
|
|
|
:b: The following code snippets are from the BUCANL *eeglab_pipe_asr_amica* pipeline: *scalpart.htb* script.
|
|
|
The example below calls the function *chan_neighbour_r* which creates an array based on the statistical difference between channels. If these channels are to ?????similar ?????different than they will be assigned a value value of 1 while the good channels remain at 0. This information is then stored in the EEG.marks.chan_info(???).flags array. This way all of the bad channels can be isolated using the marks structure and then dealt with accordingly.
|
|
|
# Creating Marks by Using Scripts
|
|
|
Marks can also be generated from a flag structure based on any criteria you would like. Cretaing functions that test the data for particular features is most easily done by generating a script.
|
|
|
:b: The following code snippets are from the BUCANL *eeglab_pipe_asr_amica* pipeline: *scalpart.htb* script.
|
|
|
|
|
|
The example below calls the function *chan_neighbour_r* which creates an array based on the statistical difference between channels. If these channels are to ?????similar ?????different than they will be assigned a value value of 1 while the good channels remain at 0. This information is then stored in the EEG.marks.chan_info(???).flags arrays. All of the bad channels can be isolated using this marks structure and then dealt with accordingly.
|
|
|
|
|
|
```matlab
|
|
|
% Edit chanflaginfo structure
|
|
|
lowr_chan_flags=zeros(EEG.nbchan,1);
|
|
|
lowr_chan_flags(chan_inds(flag_r_chan_inds))=1;
|
|
|
EEG.marks=marks_add_label(EEG.marks,'chan_info', {'low_r',[1,.7,.7],[1,.2,.2],-1,lowr_chan_flags});
|
|
|
```
|
|
|
|
|
|
This is the calculation that determines our criteria for the marks.
|
|
|
Preforming the calculation on the data and sorting it by the result criteria:
|
|
|
```matlab
|
|
|
% Calculating Nearest Neighbour R array for window criteria
|
|
|
chan_inds=marks_label2index(EEG.marks.chan_info,{'manual'},'indexes','invert','on');
|
|
|
epoch_inds=marks_label2index(EEG.marks.time_info,{'manual'},'indexes','invert','on');
|
|
|
[EEG,EEG.m_neigbr_r_lat,chandist,y,chan_win_sd]=chan_neighbour_r(EEG,[n_neighb_epoch],'max','chan_inds',chan_inds, ...
|
|
|
'epoch_inds',epoch_inds,'plotfigs','off');
|
|
|
%% IDENTIFY BRIDGED CHANNELS...
|
|
|
%Does a calculation based on the EEG.data
|
|
|
mr=mean(fisherz(EEG.m_neigbr_r_ch),2);
|
|
|
sr=std(fisherz(EEG.m_neigbr_r_ch),[],2);
|
|
|
msr=mr./sr;
|
|
|
% If a channel fits the criteria specified its index is added to an array
|
|
|
flag_b_chan_inds=find(msr>ve_trimmean(msr,[bridge_trim])+ve_trimstd(msr,[bridge_trim])*[bridge_z]);
|
|
|
```
|
|
|
Any ????? are merged into a mark called ????? low_r????
|
|
|
?????
|
|
|
This code creates a new channel mark label called *lnkflags* and fill it with the data array gathered above. It then copies the mark locations into the *manual* label, as *manual* in the end will be the only label that is removed.
|
|
|
```matlab
|
|
|
% Merging low_r in 'Manual' Marks
|
|
|
EEG=pop_marks_merge_labels(EEG,'time_info',{'manual','low_r'},'target_label','manual');
|
|
|
%% EDIT CHANFLAGINFO STRUCT...
|
|
|
% Create a new array to store the results
|
|
|
lnkflags=zeros(EEG.nbchan,1);
|
|
|
lnkflags(chan_inds(flag_b_chan_inds))=1;
|
|
|
% Creates a new marks label, sets its color, and list which array contains the marks it is using.
|
|
|
EEG.marks=marks_add_label(EEG.marks,'chan_info', {'bridge',[.7,1,.7],[.2,1,.2],-1,lnkflags});
|
|
|
|
|
|
%%COMBINE MARKS STRUCTURE INTO MANUAL FLAGS...
|
|
|
% Adds the marks label into the *manual* label which will be rejected by default
|
|
|
EEG=pop_marks_merge_labels(EEG,'chan_info',{'manual','low_r','bridge'},'target_label','manual');
|
|
|
|
|
|
%REMOVE FLAGGED channels...
|
|
|
%Removes the *manual* channel mark label
|
|
|
EEG=pop_marks_select_data(EEG,'channel marks',[],'labels',{'manual'},'remove','on');
|
|
|
```
|
|
|
??????
|
|
|
In the *scalpart.htb* script there are many mark labels merged into *manual* before it is eventually removed. If you want to remove a single mark label you can simplify the code to the following, directly rejecting the marks.
|
|
|
```matlab
|
|
|
% Purging 'Manual' Marks
|
|
|
EEG=pop_marks_select_data(EEG,'channel marks',[],'labels',{'manual', 'rank'},'remove','on');
|
|
|
EEG=pop_marks_select_data(EEG,'time marks',[],'labels',{'manual'},'remove','on');
|
|
|
EEG=eeg_checkset(EEG);
|
|
|
%% EDIT CHANFLAGINFO STRUCT...
|
|
|
lnkflags=zeros(EEG.nbchan,1);
|
|
|
lnkflags(chan_inds(flag_b_chan_inds))=1;
|
|
|
EEG.marks=marks_add_label(EEG.marks,'chan_info', {'bridge',[.7,1,.7],[.2,1,.2],-1,lnkflags});
|
|
|
|
|
|
%REMOVE FLAGGED channels...
|
|
|
%Direct removal, no merge to *manual* first.
|
|
|
EEG=pop_marks_select_data(EEG,'channel marks',[],'labels',{'lnkflags'},'remove','on');
|
|
|
```
|
|
|
|
|
|
|
... | ... | |