-
Notifications
You must be signed in to change notification settings - Fork 0
/
wmChoose_scoreEyeData.m
132 lines (90 loc) · 4.38 KB
/
wmChoose_scoreEyeData.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
% wmChoose_scoreEyeData.m
%
% preprocesses, scores, and QC's data using new autoscore in iEye_ts
% - replaces wmchoose_runPreProc.m, wmChoose_extractSaccadeData.m, and
% wmChoose_plotSummary.m
close all;
root = 'Z:/projects/wmChoose';
% ifg_fn = 'Y:/li/projects/iEye_ts/examples/p_1000hz.ifg';
ifg_fn = 'Y:\projects\old\iEye_ts\examples\p_1000hz.ifg';
%subj = {'aa1','aa2','ab1','ab2','ac1','ac2','ae','af','ag','ah','ai'}; %aa1
subj = {'sub001','sub002','sub003','sub004','sub005','sub006','sub007','sub008','sub009','sub010','sub011','sub012','sub013','sub014','sub016','sub017','sub018','sub019','sub020','sub021'};
runs_with_err = {};
errs = {};
fn_prefix = 'wmChoose_behav'; % OR _ds_preCue
QCdir = fullfile(root,'scoring_QC');
WHICH_EXCL = [11 13 20 21 22]; % based on most recent version of plotResults
% set up iEye params
ii_params = ii_loadparams;
ii_params.trial_end_value = 5;
ii_params.drift_epoch = [1 2];
ii_params.calibrate_epoch = 4;
ii_params.calibrate_mode = 'run';
ii_params.calibrate_select_mode = 'last';
ii_params.calibrate_window = 300; % originally was 300
ii_params.blink_window = [200 200];
ii_params.plot_epoch = [3 4];
ii_params.calibrate_limits = [2.5]; % error during feedback shouldn't exceed this
%ii_params.ppd = 34.1445; % behavioral room screen
for ss = 1:length(subj)
fns = sprintf('%s/data/%s_r*_%s_*.edf',root,subj{ss},fn_prefix);
thisf = dir(fns);
clear fns;
% remove files that are "r00"
ii_trial = cell(length(thisf),1);
block_num = nan(length(thisf),1);
for ff = 1:length(thisf)
fprintf('Preprocessing %s\n',thisf(ff).name);
this_edf = sprintf('%s/data/%s',root,thisf(ff).name);
% look for matching mat file
%fns = sprintf('%s/data/%s_%s*block%02.f_*.mat',root,subj{ss},fn_prefix,block_num);
%matf = dir(fns);
matf = sprintf('%smat',this_edf(1:end-3));
thisbehav = load(matf);
% for convenience...
thisbehav = thisbehav.p;
ii_params.ppd = thisbehav.ppd;
% custom for each expt
block_num(ff) = str2double(matf(strfind(matf,'_r')+[2 3]));
% turn targ_coords variable into cell of cells
% TODO: allow each cell to have numel==n_selections * 2
coords = cell(thisbehav.ntrials,1);
for tt = 1:thisbehav.ntrials
coords{tt} = {thisbehav.targ_coords{1}(tt,:), thisbehav.targ_coords{2}(tt,:)};
end
% set up trialinfo
trial_info = horzcat(thisbehav.conditions,thisbehav.targ_coords{:});
preproc_fn = sprintf('%s/preproc_iEye/%s_%s_r%02.f_preproc.mat',root,subj{ss},fn_prefix,block_num(ff));
[ii_data,ii_cfg,ii_sacc] = wmChoose_preproc1(this_edf,ifg_fn,preproc_fn,coords,trial_info,ii_params);
this_targ_coords = nan(size(ii_cfg.trialinfo,1),2);
this_targ_coords(ismember(ii_cfg.trialinfo(:,1),[1 2]),:) = ii_cfg.trialinfo(ismember(ii_cfg.trialinfo(:,1),[1 2]),[2 3]);
thisidx = find(ii_cfg.trialinfo(:,1)==3);
for tt = 1:length(thisidx)
this_targ_coords(thisidx(tt),:) = ii_cfg.trialinfo(thisidx(tt),ii_cfg.trialinfo(thisidx(tt),6)*2+[0 1]);
end
[ii_trial{ff}, ii_cfg] = ii_scoreMGS(ii_data,ii_cfg,ii_sacc,this_targ_coords,3,ii_params.drift_epoch);
close all;
close all hidden;
clear preproc_fn trial_info cond thisbehav matf fns this_edf thisbehav this_targ_coords;
end
% save for this subj a wmChoose_scored.mat containing concatenated
% ii_trial (ii_sess) and ii_cfg
ii_sess = ii_combineruns(ii_trial,block_num);
save(sprintf('%s/data/%s_wmChoose_scored.mat',root,subj{ss}),'ii_sess','WHICH_EXCL');
% plot QC files and save them [TODO]
% exclusion report
fh_excl = ii_plotQC_exclusions(ii_sess,ii_cfg,WHICH_EXCL,0);
for ff = 1:length(fh_excl)-1
saveas(fh_excl(ff),sprintf('%s/%s_excl_dot_%02.f.png',QCdir,subj{ss},ff));
end
saveas(fh_excl(end),sprintf('%s/%s_excl_all.png',QCdir,subj{ss}),0);
close(fh_excl);
% all trials
fh_trials = ii_plotQC_alltrials(ii_sess,ii_cfg,WHICH_EXCL,0);
for ff = 1:length(fh_trials)
saveas(fh_trials(ff),sprintf('%s/%s_trials_r%02.f.png',QCdir,subj{ss},block_num(ff)));
end
close(fh_trials);
close all hidden;
clear ii_sess;
end