-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrialprog.m~
More file actions
216 lines (173 loc) · 9.43 KB
/
trialprog.m~
File metadata and controls
216 lines (173 loc) · 9.43 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
%==========================
% temp
%=========================
% for i=1:length(ori)
% for j = 1:length(cont)
% for k = 1:length(rad)
% ocr{i}{j}{k} = find((LL.orientationDeg1 == ori(i)) & (LL.contrastPC1 == cont(j)) & (LL.radiusDeg2 == rad(k)));
% end
% end
% end
clear all; clc; close all;
monkeyName = 'iScan';
expDate = '120214';
protocolName = 'ReadLL';
folderSourceString = '/media/Data/';
gridType = 'Microelectrode';
type = '1';
FsEye=200;
eyeRangeMS{1} = [-320 320]; timePeriodMS{1} = [-500 500]; maxStimPos{1} = 20;
eyeRangeMS{2} = [-480 800]; timePeriodMS{2} = [-1000 1000]; maxStimPos{2} = 10;
% folderName = [folderSourceString 'data\' monkeyName '\' gridType '\' expDate '\' protocolName '\'];
folderName = [folderSourceString 'data/' monkeyName '/' gridType '/' expDate '/' protocolName '/']; % [Vinay] for linux
folderExtract = [folderName 'extractedData'];
%LL = getStimResultsLLGRF(monkeyName,expDate,protocolName,folderSourceString);
% save([folderExtract '\LL.mat'],'LL');
%save([folderExtract '/LL.mat'],'LL'); % Vinay - for linux
eyeRangeMS = [-480 800];
Fs = 200;
eyeRangePos = eyeRangeMS*Fs/1000;
% if ~exist('folderSourceString','var') folderSourceString ='F:\'; end
if ~exist('folderSourceString','var') folderSourceString ='/media/'; end % Vinay - for linux
% monkeyName = removeIfPresent(monkeyName,'\');
% expDate = removeIfPresent(expDate,'\');
% protocolName = removeIfPresent(protocolName,'\');
% folderSourceString = appendIfNotPresent(folderSourceString,'\');
% Vinay - for linux
monkeyName = removeIfPresent(monkeyName,'/');
expDate = removeIfPresent(expDate,'/');
protocolName = removeIfPresent(protocolName,'/');
folderSourceString = appendIfNotPresent(folderSourceString,'/');
% datFileName = [folderSourceString 'data\rawData\' monkeyName expDate '\' monkeyName expDate protocolName '.dat'];
datFileName = [folderSourceString 'data/rawData/' monkeyName expDate '/' monkeyName expDate protocolName '.dat']; % Vinay - for linux
% Get Lablib data
header = readLLFile('i',datFileName);
% Stimulus properties
numTrials = header.numberOfTrials;
stimNumber=1;
correctIndex=1;
trialEndIndex=1;
if (strcmp(protocolName,'GRF_001') || strcmp(protocolName,'GRF_002'))
for i=1:numTrials
%disp(i);
clear trials
trials = readLLFile('t',i);
if isfield(trials,'trialEnd')
allTrials.trialEnded(i) = 1;
allTrials.catchTrials(trialEndIndex) = trials.trial.data.catchTrial;
allTrials.instructTrials(trialEndIndex) = trials.trial.data.instructTrial;
allTrials.trialCertify(trialEndIndex) = trials.trialCertify.data;
allTrials.targetPosAllTrials(trialEndIndex) = trials.trial.data.targetIndex+1;
allTrials.eotCodes(trialEndIndex) = trials.trialEnd.data;
allTrials.fixWindowSize(trialEndIndex) = trials.fixWindowData.data.windowDeg.size.width;
allTrials.respWindowSize(trialEndIndex) = trials.responseWindowData.data.windowDeg.size.width;
allTrials.certifiedNonInstruction(trialEndIndex) = (allTrials.instructTrials(trialEndIndex)==0)*(allTrials.trialCertify(trialEndIndex)==0);
if (allTrials.eotCodes(trialEndIndex)==0) && (allTrials.certifiedNonInstruction(trialEndIndex)==1) ...
&& (allTrials.catchTrials(trialEndIndex)==1) % Work on only Correct Trials, which are not instruction or uncertified trials. [Vinay] - work even if it is a catch trial-changed this from 0 to 1
% Get Eye Data
eyeX = trials.eyeXData.data;
eyeY = trials.eyeYData.data;
% eyeStartTime = trials.eyeXData.timeMS(1); % This is wrong.
% The eye data is synchronized with trialStartTime.
eyeStartTime = trials.trialStart.timeMS;
eyeAllTimes = eyeStartTime + (0:(length(eyeX)-1))*(1000/Fs);
stimOnTimes = [trials.stimulusOnTime.timeMS];
numStimuli = allTrials.targetPosAllTrials(trialEndIndex); %=length(stimOnTimes)/3;
goodTrials.targetPos(correctIndex) = numStimuli;
goodTrials.targetTime(correctIndex) = stimOnTimes(end);
goodTrials.fixateMS(correctIndex) = trials.fixate.timeMS;
goodTrials.fixonMS(correctIndex) = trials.fixOn.timeMS;
goodTrials.stimOnTimes{correctIndex} = stimOnTimes;
% Find position of Gabor1
gaborPos = find([trials.stimDesc.data.gaborIndex]==1); % could be 4 gabors for GRF protocol
if numStimuli>1 % The first one is not the target
for j=1:numStimuli-1
stimTime = stimOnTimes(gaborPos(j));
stp=find(eyeAllTimes>=stimTime,1);
stimData.stimOnsetTimeFromFixate(stimNumber) = stimTime-trials.fixate.timeMS;
stimData.stimPos(stimNumber) = j;
if (j==1) % First stimulus may not have sufficient baseline
eyeData(stimNumber).eyePosDataX = eyeX(stp:stp+eyeRangePos(2)-1);
eyeData(stimNumber).eyePosDataY = eyeY(stp:stp+eyeRangePos(2)-1);
else
eyeData(stimNumber).eyePosDataX = eyeX(stp+eyeRangePos(1):stp+eyeRangePos(2)-1);
eyeData(stimNumber).eyePosDataY = eyeY(stp+eyeRangePos(1):stp+eyeRangePos(2)-1);
end
eyeData(stimNumber).eyeCal = trials.eyeCalibrationData.data.cal;
stimNumber=stimNumber+1;
end
end
correctIndex=correctIndex+1;
end
trialEndIndex=trialEndIndex+1;
end
end
else
for i=1:numTrials
%disp(i);
clear trials
trials = readLLFile('t',i);
if isfield(trials,'trialEnd')
allTrials.trialEnded(i) = 1;
%allTrials.catchTrials(trialEndIndex) = trials.trial.data.catchTrial;
%allTrials.instructTrials(trialEndIndex) = trials.trial.data.instructTrial;
allTrials.trialCertify(trialEndIndex) = trials.trialCertify.data;
%allTrials.targetPosAllTrials(trialEndIndex) = trials.trial.data.targetIndex+1;
allTrials.eotCodes(trialEndIndex) = trials.trialEnd.data;
allTrials.fixWindowSize(trialEndIndex) = trials.fixWindowData.data.windowDeg.size.width;
%allTrials.respWindowSize(trialEndIndex) = trials.responseWindowData.data.windowDeg.size.width;
%allTrials.certifiedNonInstruction(trialEndIndex) = (allTrials.instructTrials(trialEndIndex)==0)*(allTrials.trialCertify(trialEndIndex)==0);
if (allTrials.eotCodes(trialEndIndex)==0) % Work on only Correct Trials, which are not instruction or uncertified trials. [Vinay] - work even if it is a catch trial-changed this from 0 to 1
% Get Eye Data
eyeX = trials.eyeLXData.data;
eyeY = trials.eyeLYData.data;
% eyeStartTime = trials.eyeXData.timeMS(1); % This is wrong.
% The eye data is synchronized with trialStartTime.
eyeStartTime = trials.trialStart.timeMS;
eyeAllTimes = eyeStartTime + (0:(length(eyeX)-1))*(1000/Fs);
stimOnTimes = [trials.fixOn.timeMS];
%numStimuli = allTrials.targetPosAllTrials(trialEndIndex); %=length(stimOnTimes)/3;
%goodTrials.targetPos(correctIndex) = numStimuli;
%goodTrials.targetTime(correctIndex) = stimOnTimes(end);
goodTrials.fixateMS(correctIndex) = trials.fixate.timeMS;
goodTrials.fixonMS(correctIndex) = trials.fixOn.timeMS;
%goodTrials.stimOnTimes{correctIndex} = stimOnTimes;
% Find position of Gabor1
%gaborPos = find([trials.stimDesc.data.gaborIndex]==1); % could be 4 gabors for GRF protocol
% if numStimuli>1 % The first one is not the target
% for j=1:numStimuli-1
stimTime = stimOnTimes;
stp=find(eyeAllTimes>=stimTime,1);
%stimData.stimOnsetTimeFromFixate(stimNumber) = stimTime-trials.fixate.timeMS;
%stimData.stimPos(stimNumber) = j;
% if (j==1) % First stimulus may not have sufficient baseline
eyeData(stimNumber).eyePosDataX = eyeX(stp:stp+eyeRangePos(2)-1);
eyeData(stimNumber).eyePosDataY = eyeY(stp:stp+eyeRangePos(2)-1);
% else
% eyeData(stimNumber).eyePosDataX = eyeX(stp+eyeRangePos(1):stp+eyeRangePos(2)-1);
% eyeData(stimNumber).eyePosDataY = eyeY(stp+eyeRangePos(1):stp+eyeRangePos(2)-1);
% end
eyeData(stimNumber).eyeCal = trials.eyeLeftCalibrationData.data.cal;
stimNumber=stimNumber+1;
% end
end
correctIndex=correctIndex+1;
end
trialEndIndex=trialEndIndex+1;
end
end
end
save([folderExtract '/BehaviorData.mat'],'allTrials','goodTrials','stimData'); % Vinay - for linux
% save([folderExtract '\EyeData.mat'],'eyeData','eyeRangeMS');
save([folderExtract '/EyeData.mat'],'eyeData','eyeRangeMS'); % Vinay - for linux
folderName = [folderSourceString 'data/' monkeyName '/' gridType '/' expDate '/' protocolName '/'];
folderExtract = [folderName 'extractedData/'];
clear eyeData
load([folderExtract 'EyeData.mat']);
[eyeDataDegX,eyeDataDegY] = convertEyeDataToDeg(eyeData,1);
for i=1:20
plot(eyeDataDegX{i},eyeDataDegY{i});
hold on;
disp(i);
pause;
end