-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupport_PlotGrandTEPR.m
174 lines (139 loc) · 7.31 KB
/
support_PlotGrandTEPR.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
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
function FigHandle = support_PlotGrandTEPR(TEPRCurves, Config, Meta)
if ~isfield(Config.Plots, 'Layered') || ~Config.Plots.Layered
close(gcf);
figure
hold on
end
if ~isfield(Config.Plot.GrandTEPR, 'LineStyle') % ide majd ilyen kell isfield(behav, 'stimType')
Config.Plot.GrandTEPR.LineStyle = '-';
end
if ~isfield(Config.Plot.GrandTEPR, 'LineColor') % ide majd ilyen kell isfield(behav, 'stimType')
Config.Plot.GrandTEPR.LineColor = 'g';
end
Config.Plot.GrandTEPR.LineWidth = 2.0;
if Config.Plot.GrandTEPR.EveryParticipant
for p = 1:size(TEPRCurves,2)
yVals = TEPRCurves(:, p);
% kell ez ?
% if the curve should be baseline corrected
yVals = ...
yVals - ...
mean(yVals(Config.BaselineFromSampleMapped:Config.BaselineToSampleMapped, 1), 'omitnan');
% plot_time = 1:length(yVals);
plot_time = 0:(length(yVals)-1);
FigHandle = plot(plot_time, yVals, Config.Plot.GrandTEPR.LineStyle, 'Color', Config.Plot.GrandTEPR.LineColor, 'LineWidth', Config.Plot.GrandTEPR.LineWidth);
% Transform to milliseconds
set(FigHandle, 'XData', (get(FigHandle, 'XData')-1) / Meta.NomSRate * 1000 + Config.AnalyzeFromSec*1000);
end
else
%----------------------------------------------
% TODO: áttehető sima kódba, ne itt a plottolóban legyen
% TEPRCurves_GRAND = NaN(trial_length, 1);
% TEPRCurves_GRAND(1:trial_length, 1) = mean(TEPRCurves, 2, 'omitnan');
TEPRCurves_GRAND = mean(TEPRCurves, 2, 'omitnan');
% if the curve should be baseline corrected
TEPRCurves_GRAND = ...
TEPRCurves_GRAND - ...
mean(TEPRCurves_GRAND(Config.BaselineFromSampleMapped:Config.BaselineToSampleMapped, 1), 'omitnan');
%----------------------------------------------
yVals = TEPRCurves_GRAND;
% plot_time = 1:length(yVals);
plot_time = 0:(length(yVals)-1);
% plot(plot_time, TEPRCurves_GRAND, grandTEPR_lineStyle)
FigHandle = plot(plot_time, TEPRCurves_GRAND, Config.Plot.GrandTEPR.LineStyle, 'Color', Config.Plot.GrandTEPR.LineColor, 'LineWidth', Config.Plot.GrandTEPR.LineWidth);
% grandTEPR(layeredFigCounter) = FigHandle;
% Transform to milliseconds
set(FigHandle, 'XData', (get(FigHandle, 'XData')-1) / Meta.NomSRate * 1000 + Config.AnalyzeFromSec*1000);
end
if isnan(Config.Plot.GrandTEPR.XLim)
Config.Plot.GrandTEPR.XLim = [round(Config.AnalyzeFromSec*1000) round(Config.AnalyzeToSec*1000)];
% Config.Plot.GrandTEPR.XLim = [0 round(TimeDefs.AnalyzeToSec*1000)];
end
xlim(Config.Plot.GrandTEPR.XLim);
% TODO: analógra átirni
% % xline(round(stimPresentedAtSec*1000)); % stim prez
if ~isnan(Config.Plot.GrandTEPR.YLim)
ylim(Config.Plot.GrandTEPR.YLim);
end
if Config.Plots.Grid
grid on;
grid minor;
end
if Config.Plots.Markings.Enabled == true && Config.Plots.LayeredFigCounter < 2
currylim = ylim;
colorB = [0.3 0.3 0.9];
yDt = 5;
for t = (Config.AnalyzeFromSec*1000):(Config.AnalyzeToSec*1000)
% for t = grandTEPR_xlim(1):grandTEPR_xlim(2)
if ~Config.Plots.Markings.OnEdges && (t==Config.Plot.GrandTEPR.XLim(1) || t==Config.Plot.GrandTEPR.XLim(2))
continue;
end
if Config.AlignToStimOrResp == true % STIMULUS-ALIGNED
if Config.Plots.Markings.B && t~=0 && mod(t, Config.ISISec*1000) == Config.ISISec*1000 + (Config.BaselineFromSec+Config.BaselineToSec)/2*1000
xline(t, 'Color', colorB);
text(t, currylim(2)-(currylim(2)-currylim(1))/yDt,'B', 'Color', colorB)
end
if Config.Plots.Markings.S && mod(t, Config.ISISec*1000) == 0
% todo: ONLY IF STIMULUS-ALIGNED
xline(t, 'Color', colorB);
text(t, currylim(2)-(currylim(2)-currylim(1))/yDt,'S', 'Color', colorB)
end
if Config.Plots.Markings.F && t~=0 && mod(t, Config.ISISec*1000) == Config.ISISec*1000 - fixBeforeStimSec*1000
xline(t, 'Color', colorB);
text(t, currylim(2)-(currylim(2)-currylim(1))/yDt,'F', 'Color', colorB)
end
elseif Config.AlignToStimOrResp == false % RESPONSE-ALIGNED
if Config.Plots.Markings.B && t~=0 && t/(Config.ISISec*1000) == Config.ISISec*1000 + (Config.BaselineFromSec+Config.BaselineToSec)/2*1000
xline(t, 'Color', colorB);
text(t, currylim(2)-(currylim(2)-currylim(1))/yDt,'B', 'Color', colorB)
end
if Config.Plots.Markings.R && t/(Config.ISISec*1000) == 0
xline(t, 'Color', colorB);
text(t, currylim(2)-(currylim(2)-currylim(1))/yDt,'R', 'Color', colorB)
end
end
% if mod(t, TimeDefs.ISISec*1000) == 0
% xline(t+ (TimeDefs.BaselineFromSec+TimeDefs.BaselineToSec)/2*1000, 'Color', colorB);
% text(t+ (TimeDefs.BaselineFromSec+TimeDefs.BaselineToSec)/2*1000, currylim(2)-(currylim(2)-currylim(1))/yDt,'B', 'Color', colorB)
%
% xline(t, 'Color', colorB);
% text(t, currylim(2)-(currylim(2)-currylim(1))/yDt,'S', 'Color', colorB)
%
% xline(t -Config.FixBeforeStimSec*1000, 'Color', colorB);
% text(t -Config.FixBeforeStimSec*1000, currylim(2)-(currylim(2)-currylim(1))/yDt,'F', 'Color', colorB)
%
% end
end
end
set(gcf, 'Position', get(0, 'Screensize')*Config.Plots.ScaleFactor);
% title(['TEPR curve averaged across all Participants']);
xlabel(['Time [ms]']);
if Config.Z_norm_method == 0
if Meta.flag_PXorMM == 1
ylabel(['Pupil size [px]']);
else
ylabel(['Pupil size [mm]']);
end
else
ylabel(['Pupil size [a.u.]']);
end
OutFilePath = ['~RESULTS/' Meta.RootDirTag '/' ];
if ~exist(OutFilePath, 'dir')
mkdir(OutFilePath);
end
OutFileName = ['TEPR'];
OutFileName = [OutFileName ' alignSR=' num2str(Config.AlignToStimOrResp)];
OutFileName = [OutFileName ' skipN=' num2str(Config.SkipFirstNtrials)];
OutFileName = [OutFileName ' filt=' num2str(Config.Filter.Behav.Enabled)];
OutFileName = [OutFileName ' (' Config.Filter.Behav.FriendlyName ')'];
if Config.Plot.GrandTEPR.EveryParticipant
OutFileName = [OutFileName '_EP'];
end
OutFileName = [OutFileName '.png'];
OutFileName = char(OutFileName);
% set(gcf, 'Position', get(0, 'Screensize'));
set(gcf, 'Position', get(0, 'Screensize')*Config.Plots.ScaleFactor);
saveas(gcf,[OutFilePath OutFileName]);
hold off;
pause(0.5)
end