Skip to content

Commit

Permalink
substantial edit to epoch marking in proc_interp; minor edits to proc…
Browse files Browse the repository at this point in the history
…_artifact and artifact_channels; updates on alcstress scripts
  • Loading branch information
sjburwell committed Mar 8, 2019
1 parent 1e863ec commit b4fd56b
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 41 deletions.
28 changes: 16 additions & 12 deletions example_scripts/alcstress/cfg_export_alcstress_eeg.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

% -- ICA-spatial-temporal filter
config(3).subcomp.spatial( 1).icwinv = 'blink_ICWINV30Curry.mat';
config(3).subcomp.temporal(1).chans = {{'VEOG'}; {'FP1'}; {'FP2'}};
config(3).subcomp.temporal(1).chans = {{'VEOG'}; {'FP1'}; {'FP2'}; {'HEOG'}};
config(3).subcomp.spatial( 2).icwinv = 'hem_ICWINV30Curry.mat';
config(3).subcomp.temporal(2).chans = {{'HEOG'}; {'FT8'}; {'FT7'}};
config(3).subcomp.temporal(2).chans = {{'HEOG'}; {'FT8'}; {'FT7'}; {'VEOG'}};
config(3).subcomp.threshold(1).stat = 'EM';
config(3).subcomp.threshold(1).crit = 1 ;

% -- filter
config(4).userinput = [ ...
'EEG = pop_firws(EEG, ''fcutoff'', 55, ''ftype'', ''lowpass'', ''wtype'', ''kaiser'', ''warg'', 7.85726, ''forder'',88);';
'tmpdata = EEG.data./mean(mad(EEG.data(ismember({EEG.chanlocs.type},''EEG''),:)'',1)); ' ...
'if ~isempty(find((sum(tmpdata(ismember({EEG.chanlocs.labels},{''FP1'',''FP2'',''F3'',''F4'',''FZ''}),:)''>3)./EEG.pnts)>.10)), ' ...
' pop_topoplot(EEG,0,1:size(EEG.icawinv,2)); pop_eegplot(EEG,1,0,0); pop_eegplot(EEG,0,0,0); EEG = pop_subcomp(EEG); close all; ' ...
'end; ' ...
'EEG = pop_firws(EEG, ''fcutoff'', 55, ''ftype'', ''lowpass'', ''wtype'', ''kaiser'', ''warg'', 7.85726, ''forder'',88);' ...
];

% -- epoch
Expand Down Expand Up @@ -49,15 +53,15 @@
config(8).artifact.pthreshchan = .75 ;
config(8).artifact.minchans = 15 ;
config(8).artifact.rejchan = 1 ;
config(8).artifact.rejtrial = 0 ; %usually 1, but shock screwed up this
config(8).artifact.opts(1).meas = {'Vdist-nearest' 'var'}; % large deviation
config(8).artifact.opts(1).stat = { 'EM' 'EM'};
config(8).artifact.opts(1).crit = { [1] [1]};
config(8).artifact.opts(1).joint= 1 ;
config(8).artifact.opts(2).meas = { 'fqvar' 'range'}; % muscle
config(8).artifact.opts(2).stat = { 'EM' 'EM'};
config(8).artifact.opts(2).crit = { [1] [1]};
config(8).artifact.opts(2).joint= 1 ;
config(8).artifact.rejtrial = 0 ; %usually 1, but shock or startle probe screwed up this
config(8).artifact.opts(1).meas = { 'Vdist-nearest' 'var'}; % large deviation
config(8).artifact.opts(1).stat = { 'nMAD' 'nMAD'};
config(8).artifact.opts(1).crit = { [4] [4]};
config(8).artifact.opts(1).joint= 1 ;
config(8).artifact.opts(2).meas = { 'range' 'fqvar'}; % muscle
config(8).artifact.opts(2).stat = { 'nMAD' 'nMAD'};
config(8).artifact.opts(2).crit = { [4] [4]};
config(8).artifact.opts(2).joint= 1 ;

%config(10).userinput = '%compute_ica_multidipfit; %tmprly interp,convt avg-ref,ICA (#ICs=rank(data),in EEG.etc.newica*),dipfit,revert to orig dims & refs';

Expand Down
12 changes: 6 additions & 6 deletions example_scripts/alcstress/cfg_export_alcstress_emg.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
config(5).artifact.type = 'matrix'; % see artifact_channels, thresholder
config(5).artifact.datafilt = 0 ; % use only non-tagged epochs/channels
config(5).artifact.pthreshchan = .75 ;
config(5).artifact.minchans = 15 ;
config(5).artifact.minchans = 1 ;
config(5).artifact.rejchan = 1 ;
config(5).artifact.rejtrial = 1 ;
config(5).artifact.opts(1).meas = { 'var'}; % large deviation
config(5).artifact.opts(1).stat = {'zscore'};
config(5).artifact.opts(1).crit = { [3]};
config(5).artifact.opts(1).joint= 0 ;
config(5).artifact.rejtrial = 0 ;
config(5).artifact.opts(1).meas = { 'range' 'Vmedian'}; % large deviation
config(5).artifact.opts(1).stat = { 'nMAD' 'nMAD'};
config(5).artifact.opts(1).crit = { [2] [2]};
config(5).artifact.opts(1).joint= 1 ;
61 changes: 60 additions & 1 deletion example_scripts/alcstress/recode_npu.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
clear REC

photodiode = '16';
photodiode = {'16','1200001'};
diodecritpt = round(.100 * EEG.srate); % "photodiode" must precede "visualcues" by ~100 milliseconds
visualcues = {'40','41','42','43','50','51','52','53','60','61','62','63', ...
'44','45','46','47','48','49','50','51', ...
'10','11','12','13','14','15','17','18', ...
'20','21','22','23','24','25','26','27', ...
'30','31','32','33','34','35','36','37'};
Expand All @@ -21,6 +22,9 @@

bndrysamples = [EEG.event(strmatch('boundary',{EEG.event.type})).latency];

%version of npu task (i.e., before or after Feb 1, 2019)
if contains(EEG.filename,{'A1','B1','C1','D1','E1','F1'}), %before Feb 1, 2019

%basic recode
REC(1).label = {'boundary'}; REC(1).template = { '800001'}; REC(1).position = 1;
REC(2).label = { '40'}; REC(2).template = {'16' '40'}; REC(2).position = 1; %visual cues
Expand Down Expand Up @@ -72,6 +76,61 @@
REC(48).label = { '736'}; REC(48).template = {'16' '36' '128'}; REC(48).position = 3;
REC(49).label = { '737'}; REC(49).template = {'16' '37' '128'}; REC(49).position = 3;

else,

%basic recode
REC(1).label = {'boundary'}; REC(1).template = { '800001'}; REC(1).position = 1;
REC(2).label = { '40'}; REC(2).template = {'1200001' '40'}; REC(2).position = 1; %visual cues
REC(3).label = { '41'}; REC(3).template = {'1200001' '41'}; REC(3).position = 1;
REC(4).label = { '42'}; REC(4).template = {'1200001' '42'}; REC(4).position = 1;
REC(5).label = { '43'}; REC(5).template = {'1200001' '43'}; REC(5).position = 1;
REC(6).label = { '50'}; REC(6).template = {'1200001' '44'}; REC(6).position = 1;
REC(7).label = { '51'}; REC(7).template = {'1200001' '45'}; REC(7).position = 1;
REC(8).label = { '52'}; REC(8).template = {'1200001' '46'}; REC(8).position = 1;
REC(9).label = { '53'}; REC(9).template = {'1200001' '47'}; REC(9).position = 1;
REC(10).label = { '60'}; REC(10).template = {'1200001' '48'}; REC(10).position = 1;
REC(11).label = { '61'}; REC(11).template = {'1200001' '49'}; REC(11).position = 1;
REC(12).label = { '62'}; REC(12).template = {'1200001' '50'}; REC(12).position = 1;
REC(13).label = { '63'}; REC(13).template = {'1200001' '51'}; REC(13).position = 1;
REC(14).label = { '840'}; REC(14).template = {'1200001' '40' '1000001'}; REC(14).position = 3; %auditory probes during cue
REC(15).label = { '841'}; REC(15).template = {'1200001' '41' '1000001'}; REC(15).position = 3;
REC(16).label = { '842'}; REC(16).template = {'1200001' '42' '1000001'}; REC(16).position = 3;
REC(17).label = { '843'}; REC(17).template = {'1200001' '43' '1000001'}; REC(17).position = 3;
REC(18).label = { '850'}; REC(18).template = {'1200001' '44' '1000001'}; REC(18).position = 3;
REC(19).label = { '851'}; REC(19).template = {'1200001' '45' '1000001'}; REC(19).position = 3;
REC(20).label = { '852'}; REC(20).template = {'1200001' '46' '1000001'}; REC(20).position = 3;
REC(21).label = { '853'}; REC(21).template = {'1200001' '47' '1000001'}; REC(21).position = 3;
REC(22).label = { '860'}; REC(22).template = {'1200001' '48' '1000001'}; REC(22).position = 3;
REC(23).label = { '861'}; REC(23).template = {'1200001' '49' '1000001'}; REC(23).position = 3;
REC(24).label = { '862'}; REC(24).template = {'1200001' '50' '1000001'}; REC(24).position = 3;
REC(25).label = { '863'}; REC(25).template = {'1200001' '51' '1000001'}; REC(25).position = 3;
REC(26).label = { '710'}; REC(26).template = {'1200001' '10' '1000001'}; REC(26).position = 3; %auditory probes during iti
REC(27).label = { '711'}; REC(27).template = {'1200001' '11' '1000001'}; REC(27).position = 3;
REC(28).label = { '712'}; REC(28).template = {'1200001' '12' '1000001'}; REC(28).position = 3;
REC(29).label = { '713'}; REC(29).template = {'1200001' '13' '1000001'}; REC(29).position = 3;
REC(30).label = { '714'}; REC(30).template = {'1200001' '14' '1000001'}; REC(30).position = 3;
REC(31).label = { '715'}; REC(31).template = {'1200001' '15' '1000001'}; REC(31).position = 3;
REC(32).label = { '716'}; REC(32).template = {'1200001' '17' '1000001'}; REC(32).position = 3; %<-purposefully mismatched
REC(33).label = { '717'}; REC(33).template = {'1200001' '18' '1000001'}; REC(33).position = 3; %<-purposefully mismatched
REC(34).label = { '720'}; REC(34).template = {'1200001' '20' '1000001'}; REC(34).position = 3;
REC(35).label = { '721'}; REC(35).template = {'1200001' '21' '1000001'}; REC(35).position = 3;
REC(36).label = { '722'}; REC(36).template = {'1200001' '22' '1000001'}; REC(36).position = 3;
REC(37).label = { '723'}; REC(37).template = {'1200001' '23' '1000001'}; REC(37).position = 3;
REC(38).label = { '724'}; REC(38).template = {'1200001' '24' '1000001'}; REC(38).position = 3;
REC(39).label = { '725'}; REC(39).template = {'1200001' '25' '1000001'}; REC(39).position = 3;
REC(40).label = { '726'}; REC(40).template = {'1200001' '26' '1000001'}; REC(40).position = 3;
REC(41).label = { '727'}; REC(41).template = {'1200001' '27' '1000001'}; REC(41).position = 3;
REC(42).label = { '730'}; REC(42).template = {'1200001' '30' '1000001'}; REC(42).position = 3;
REC(43).label = { '731'}; REC(43).template = {'1200001' '31' '1000001'}; REC(43).position = 3;
REC(44).label = { '732'}; REC(44).template = {'1200001' '32' '1000001'}; REC(44).position = 3;
REC(45).label = { '733'}; REC(45).template = {'1200001' '33' '1000001'}; REC(45).position = 3;
REC(46).label = { '734'}; REC(46).template = {'1200001' '34' '1000001'}; REC(46).position = 3;
REC(47).label = { '735'}; REC(47).template = {'1200001' '35' '1000001'}; REC(47).position = 3;
REC(48).label = { '736'}; REC(48).template = {'1200001' '36' '1000001'}; REC(48).position = 3;
REC(49).label = { '737'}; REC(49).template = {'1200001' '37' '1000001'}; REC(49).position = 3;

end

EEG = eeg_recode(EEG, REC, 1);
clear REC

Expand Down
15 changes: 6 additions & 9 deletions example_scripts/alcstress/run_export_alcstress_npueeg.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@

% process/CRIT VARS
process.name = mfilename;
process.loaddir = '/labs/burwellstudy/projects/testing-eeg-toolbox/output_data/';
process.loaddir = '/labs/ankerlab/projects/k01/npu/data_cache/';
process.loadflt = '*cnt.set';
process.loadpop = 1;
process.logfile = 1;
process.abortif = ['chanlocs = readlocs(''curry_sphrad1_n28.ced''); ' ...
'length(find(ismember({chanlocs.labels},{EEG.chanlocs.labels})))<15;'];
process.savedir = process.loaddir;
process.savesfx = '_epoch_npueeg';
process.savesfx = '_epoch_npu-probeerp';

% config file (or struct variable)
cfg_export_alcstress_eeg;
config(1).userinput = 'recode_npu; PNSlabels= {''EKG'',''EMG'',''SCL''}; EEG = proc_select(EEG,''nochannel'',PNSlabels); ';
config(5).epoch.events = {'40' '41' '42' '43' '50' '51' '52' '53' '60' '61' '62' '63'}; % ('all','ALL',[]) or cellstr, or 'task_default'
config(5).epoch.winsec = [-0.5 4.5]; % in sec
config(9).interp.type = 'artifact'; % 'full' or 'artifact'
config(9).interp.montage = 'curry_sphrad1_n28.ced'; % see readlocs
config(9).interp.interpmaj = 0 ; % if >50% bad, interp all
config(9).interp.rejthresh = 100 ; % lower-bound (pct)
config(9).interp.rejreject = 1 ; % reject non-interpolated
config(5).epoch.events =[{'840' '841' '842' '843' '850' '851' '852' '853' '860' '861' '862' '863'} cellstr(num2str([700:740]'))']; % ('all','ALL',[]) or cellstr
config(5).epoch.winsec = [-0.5 0.5]; % in sec
%config(5).epoch.events = {'40' '41' '42' '43' '50' '51' '52' '53' '60' '61' '62' '63'}; % ('all','ALL',[]) or cellstr, or 'task_default'
%config(5).epoch.winsec = [-0.5 4.5]; % in sec

% run!
EEG = proc_commander(process, config);
Expand Down
10 changes: 6 additions & 4 deletions example_scripts/alcstress/run_export_alcstress_npuemg.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

% process/CRIT VARS
process.name = mfilename;
process.loaddir = '/labs/burwellstudy/projects/testing-eeg-toolbox/output_data/';
process.loaddir = '/labs/ankerlab/projects/k01/npu/data_cache/';
process.loadflt = '*cnt.set';
process.loadpop = 1;
process.logfile = 1;
process.abortif ='';
process.savedir = process.loaddir;
process.savesfx = '_epoch_npuemg';
process.savesfx = '_epoch_npu-probeemg';

% config file (or struct variable)
cfg_export_alcstress_emg;
config(1).userinput = 'recode_npu; EEG = proc_select(EEG,''channel'',{''EMG''}); ';
config(4).epoch.events = {'40' '41' '42' '43' '50' '51' '52' '53' '60' '61' '62' '63'}; % ('all','ALL',[]) or cellstr, or 'task_default'
config(4).epoch.winsec = [-0.5 4.5]; % in sec
config(4).epoch.events =[{'840' '841' '842' '843' '850' '851' '852' '853' '860' '861' '862' '863'} cellstr(num2str([700:740]'))']; % ('all','ALL',[]) or cellstr
config(4).epoch.winsec = [-0.5 0.5]; % in sec
%config(4).epoch.events = {'40' '41' '42' '43' '50' '51' '52' '53' '60' '61' '62' '63'}; % ('all','ALL',[]) or cellstr, or 'task_default'
%config(4).epoch.winsec = [-0.5 4.5]; % in sec

% run!
EEG = proc_commander(process, config);
Expand Down
4 changes: 2 additions & 2 deletions example_scripts/alcstress/run_import_alcstress_general.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

% process/CRIT VARS
process.name = mfilename;
process.loaddir = '/labs/burwellstudy/data/anker_k01_tmp/';
process.loaddir = '/labs/ankerlab/data/k01/npu/';
process.loadflt = '*.cdt';
process.loadpop = 1;
process.logfile = 1;
process.abortif = ['chanlocs = readlocs(''curry_sphrad1_n28.ced''); ' ...
'length(find(ismember({chanlocs.labels},{EEG.chanlocs.labels})))<15;'];
process.savedir = '/labs/burwellstudy/projects/testing-eeg-toolbox/output_data/';
process.savedir = '/labs/ankerlab/projects/k01/npu/data_cache/';
process.savesfx = '_cnt';
process.opts.resample = 256;

Expand Down
2 changes: 1 addition & 1 deletion functions/basefunc/artifact_channels.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
% at detecting muscle bursts
% 'grad-med': median-gradient - uses diff()
% 'spPCA': median absolute-valued coefficient
% 'Vmax': maximum value
% 'Vmax': maximum absolute value
% 'Vmedian': median value
% 'corr-min': minimum cross-channel correlation
% 'corr-med': median " "
Expand Down
81 changes: 81 additions & 0 deletions functions/basefunc/keyval.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
function [val, remaining] = keyval(key, varargin)

% KEYVAL returns the value that corresponds to the requested key in a
% key-value pair list of variable input arguments
%
% Use as
% [val] = keyval(key, varargin)
%
% See also VARARGIN

% Undocumented option
% [val] = keyval(key, varargin, default)

% Copyright (C) 2005-2007, Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
% for the documentation and details.
%
% FieldTrip is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% FieldTrip is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id: keyval.m 7123 2012-12-06 21:21:38Z roboos $

% what to return if the key is not found
emptyval = [];

if nargin==3 && iscell(varargin{1})
emptyval = varargin{2};
varargin = varargin{1};
end

if nargin==2 && iscell(varargin{1})
varargin = varargin{1};
end

if mod(length(varargin),2)
error('optional input arguments should come in key-value pairs, i.e. there should be an even number');
end

% the 1st, 3rd, etc. contain the keys, the 2nd, 4th, etc. contain the values
keys = varargin(1:2:end);
vals = varargin(2:2:end);

% the following may be faster than cellfun(@ischar, keys)
valid = false(size(keys));
for i=1:numel(keys)
valid(i) = ischar(keys{i});
end

if ~all(valid)
error('optional input arguments should come in key-value pairs, the optional input argument %d is invalid (should be a string)', i);
end

hit = find(strcmpi(key, keys));
if isempty(hit)
% the requested key was not found
val = emptyval;
elseif length(hit)==1
% the requested key was found
val = vals{hit};
else
error('multiple input arguments with the same name');
end

if nargout>1
% return the remaining input arguments with the key-value pair removed
keys(hit) = [];
vals(hit) = [];
remaining = cat(1, keys(:)', vals(:)');
remaining = remaining(:)';
end
11 changes: 6 additions & 5 deletions functions/procfunc/proc_artifact.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
EEG = eeg_interp( EEG, bad_elecs, 'spherical');
elseif reject_on==1&&interp_on==0,
tmprej = EEG.reject;
EEG = pop_select( EEG, 'nochannel', bad_elecs);
EEG = proc_select( 'nochannel', bad_elecs); %EEG = pop_select( EEG, 'nochannel', bad_elecs);
%EEG = eeg_hist(EEG, ['EEG = pop_select(EEG,''nochannel'',[' num2str(bad_elecs) ']); % label(s): ' EEG.chanlocs(bad_elecs).label]);
EEG.reject = tmprej; EEG.reject.rejmanualE(bad_elecs,:) = '';
end
Expand All @@ -130,7 +130,7 @@
end
if ~isempty(bad_epochs) && isfield(args,'reject') && args.reject>0,
tmprej = EEG.reject;
EEG = pop_select( EEG, 'notrial', bad_epochs);
EEG = proc_select( EEG, 'notrial', bad_epochs); %EEG = pop_select( EEG, 'notrial', bad_epochs);
%EEG = eeg_hist(EEG, ['EEG = pop_select(EEG,''notrial'',[' num2str(bad_epochs) ']);']);
EEG.reject = tmprej;
EEG.reject.rejmanual(bad_epochs) = ''; EEG.reject.rejmanualE(:,bad_epochs) = '';
Expand Down Expand Up @@ -181,24 +181,25 @@
tmprej = EEG.reject;
delstring = []; for d = 1:size(delete_chan,2), delstring = [delstring ' ' char({EEG.chanlocs(delete_chan(d)).labels})]; end
disp([' proc_artifact; The following channel(s) will be deleted for ' EEG.filename ': ' delstring]);
EEG = pop_select( EEG, 'nochannel', delete_chan);
EEG = proc_select( EEG, 'nochannel', delete_chan); %EEG = pop_select( EEG, 'nochannel', delete_chan);
EEG.reject = tmprej; EEG.reject.rejmanualE(delete_chan,:) = '';
end
if trialrej_on>0&&~isempty(find(sum(EEG.reject.rejmanualE)==EEG.nbchan)),
delete_trial = find(sum(EEG.reject.rejmanualE)==EEG.nbchan);
if length(delete_trial)==EEG.trials,
disp([' proc_artifact; all trials artifact for ' EEG.filename ', deleting all data...']);
EEG = pop_select(EEG, 'nochannel', 1:EEG.nbchan);
EEG = proc_select( EEG, 'nochannel', 1:EEG.nbchan); %EEG = pop_select(EEG, 'nochannel', 1:EEG.nbchan);
else,
tmprej = EEG.reject;
EEG = pop_select( EEG, 'notrial', delete_trial);
EEG = proc_select( EEG, 'notrial', delete_trial); %EEG = pop_select( EEG, 'notrial', delete_trial);
EEG.reject = tmprej;
EEG.reject.rejmanual( delete_trial) = '';
EEG.reject.rejmanualE(:,delete_trial) = '';
end
end
%EEG.reject.rejmanual(find(sign(sum(EEG.reject.rejmanualE)))) = 1;
EEG.reject.rejmanual = double(sum(EEG.reject.rejmanualE)>0);

end

case 'chan-epoch',
Expand Down
2 changes: 1 addition & 1 deletion functions/procfunc/proc_interp.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
if ~isempty(find(rejT))&&args.rejreject==1,
EEG = proc_select(EEG, 'notrial', find(rejT));
EEG.reject.rejmanualE = interpE(:,find(rejT==0));
EEG.reject.rejmanual = find(sum(EEG.reject.rejmanualE));
EEG.reject.rejmanual(find(sum(EEG.reject.rejmanualE))) = 1; % = find(sum(EEG.reject.rejmanualE)); 2019-03-06 SJB
EEG.reject.rejmanualcol = [0.5 0.5 0.5];
EEG.reject.rejglobalE = EEG.reject.rejmanualE;
EEG.reject.rejglobal = EEG.reject.rejmanual;
Expand Down

0 comments on commit b4fd56b

Please sign in to comment.