Skip to content

Commit

Permalink
some bug fix for import / design in 3D
Browse files Browse the repository at this point in the history
  • Loading branch information
CPernet committed Jan 30, 2014
1 parent b141727 commit 3cc0e67
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 199 deletions.
5 changes: 5 additions & 0 deletions README.txt
@@ -0,0 +1,5 @@
README.txt

The LInear MOdelling of EEG data (LIMO EEG) toolbox is a Matlab toolbox dedicated to the analysis of MEEG data. It is interfaced with EEGLAB to act as a plug in. However, once data are imported all is performed within LIMO EEG and the toolbox can thus work for any data sets.

The repository is the developmental version - the stable version can be downlaoaded from https://gforge.dcn.ed.ac.uk/gf/project/limo_eeg/
16 changes: 10 additions & 6 deletions limo_design_matrix_tf.m
Expand Up @@ -60,6 +60,7 @@
full_factorial = varargin{2}.design.fullfactorial;
chanlocs = varargin{2}.data.chanlocs;
type_of_analysis = varargin{2}.design.type_of_analysis;
size3D = varargin{2}.data.size3D;
flag = varargin{3};
try
expected_chanlocs = varargin{2}.data.expected_chanlocs;
Expand Down Expand Up @@ -412,18 +413,21 @@

% Reorder this Yr to save this as 4D
Yr=limo_tf_4d_reshape(Yr);
save Yr Yr ;
save Yr Yr -v7.3;

% no matter the analysis we have Beta, Yhat, Res
Yhat = zeros(LIMO.data.size3D); save Yhat Yhat; clear Yhat
Res = zeros(LIMO.data.size3D); save Res Res; clear Res
Betas = zeros(LIMO.data.size3D(1),LIMO.data.size3D(2),size(X,2)); save Betas Betas; clear Betas
% note - overwritten in limo_eeg_tf, saved here for size-check
Yhat = zeros(size3D);
Res = zeros(size3D);
Betas = zeros(size3D(1),size3D(2),size(X,2));

% note - overwritten in limo_eeg_tf, saved here for size-check
save Yhat Yhat -v7.3; clear Yhat
save Res Res -v7.3; clear Res
save Betas Betas -v7.3; clear Betas

% only for univariate analyses
if strcmp(type_of_analysis,'Mass-univariate')
R2 = zeros(LIMO.data.size3D(1),LIMO.data.size3D(2),3); save R2 R2;
R2 = zeros(size3D(1),size3D(2),3); save R2 R2 -v7.3;
end
clear Yr R2

Expand Down
206 changes: 108 additions & 98 deletions limo_display_results.m
Expand Up @@ -201,110 +201,120 @@ function limo_display_results(Type,FileName,PathName,p,MCC,LIMO,flag)
save LIMO LIMO
end

% imagesc
ax(1) = subplot(3,3,[1 2 4 5 7 8]);
if LIMO.analysis_flag == 1
timevect = linspace(LIMO.data.start*1000,LIMO.data.end*1000,size(toplot,2));
ratio = timevect(2)-timevect(1); % (LIMO.data.end*1000 - LIMO.data.start*1000) / size(toplot,2);
if LIMO.data.start < 0
frame_zeros = find(timevect == 0);
if isempty(frame_zeros)
frame_zeros = round(abs(LIMO.data.start*1000) / ratio)+1;

if LIMO.analysis_flag ~= 3 % 2D maps
% imagesc
ax(1) = subplot(3,3,[1 2 4 5 7 8]);
if LIMO.analysis_flag == 1
timevect = linspace(LIMO.data.start*1000,LIMO.data.end*1000,size(toplot,2));
ratio = timevect(2)-timevect(1); % (LIMO.data.end*1000 - LIMO.data.start*1000) / size(toplot,2);
if LIMO.data.start < 0
frame_zeros = find(timevect == 0);
if isempty(frame_zeros)
frame_zeros = round(abs(LIMO.data.start*1000) / ratio)+1;
end
else
frame_zeros = 1;
end
else
frame_zeros = 1;
scale = toplot.*mask; scale(scale==0)=NaN;
imagesc(timevect,1:size(toplot,1),scale);

elseif LIMO.analysis_flag == 2
freqvect=linspace(LIMO.data.freq_list(1),LIMO.data.freq_list(end),size(toplot,2));
frame_zeros = 1; ratio = freqvect(2)-freqvect(1);
scale = toplot.*mask; scale(scale==0)=NaN;
imagesc(freqvect,1:size(toplot,1),scale);
end
scale = toplot.*mask; scale(scale==0)=NaN;
imagesc(timevect,1:size(toplot,1),scale);

elseif LIMO.analysis_flag == 2 || LIMO.analysis_flag == 3
freqvect=linspace(LIMO.data.freq_list(1),LIMO.data.freq_list(end),size(toplot,2));
scale = toplot.*mask; scale(scale==0)=NaN;
imagesc(freqvect,1:size(toplot,1),scale);
end

v = max(toplot(:)); [e,f]=find(toplot==v);
try
caxis([min(min(scale)), max(max(scale))]);
catch caxiserror
end
color_images_(scale,LIMO);
title(mytitle,'Fontsize',16)

if length(e)>1 % happen if we have multiple times the exact same max values
e = e(1); f = f(1); % then we take the 1st (usually an artefact but allows to see it)
end

% ERP plot at best electrode
ax(3) = subplot(3,3,9);

if LIMO.analysis_flag == 1
mytitle2 = sprintf('time course @ \n electrode %s (%g)', LIMO.data.chanlocs(e).labels,LIMO.data.chanlocs(e).urchan);
plot(timevect,toplot(e,:),'LineWidth',3); grid on; axis tight
elseif LIMO.analysis_flag == 2
mytitle2 = sprintf('power spectra @ \n electrode %s (%g)', LIMO.data.chanlocs(e).labels,LIMO.data.chanlocs(e).urchan);
plot(freqvect,toplot(e,:),'LineWidth',3); grid on; axis tight
end
title(mytitle2,'FontSize',12)

% topoplot at max time
ax(2) = subplot(3,3,6);
chans = LIMO.data.chanlocs;
topoplot(toplot(:,f),chans,'maplimits','maxmin');
if LIMO.analysis_flag == 1
title(['topoplot @ ' num2str(round(timevect(f))) 'ms'],'FontSize',12)
set(gca,'XTickLabel', timevect);
elseif LIMO.analysis_flag == 2
title(['topoplot @' num2str(round(timevect(f))) 'Hz'],'FontSize',12);
set(gca,'XTickLabel', LIMO.data.freq_list);
end;

% update with mouse clicks
if flag == 1
update = 0;
while update ==0
try
[x,y,button]=ginput(1);
catch
update =1; break
end
if button > 1
update = 1;
end
clickedAx = gca;
if clickedAx ~=ax(1)
disp('right click to exit')
else
frame = frame_zeros + round(x / ratio);

% ERP plot at best electrode and topoplot
% at max time or freq
y = round(y);
if LIMO.analysis_flag == 1; % If time analysis
mytitle2 = sprintf('time course @ \n electrode %s (%g)', LIMO.data.chanlocs(e).labels,LIMO.data.chanlocs(e).urchan);
subplot(3,3,9,'replace');
plot(timevect,toplot(e,:),'LineWidth',3); grid on; axis tight
subplot(3,3,6,'replace');
topoplot(toplot(:,frame),LIMO.data.chanlocs);
title(['topoplot @ ' num2str(round(x)) 'ms'],'FontSize',12)

elseif LIMO.analysis_flag == 2 % If freq analysis
mytitle2 = sprintf('power spectra @ \n electrode %s (%g)', LIMO.data.chanlocs(e).labels,LIMO.data.chanlocs(e).urchan);
subplot(3,3,9,'replace');
plot(freqvect,toplot(e,:),'LineWidth',3); grid on; axis tight
subplot(3,3,6,'replace');
topoplot(toplot(:,frame),LIMO.data.chanlocs);
title(['topoplot @ ' num2str(round(x)) 'Hz'],'FontSize',12)

end
v = max(toplot(:)); [e,f]=find(toplot==v);
try
caxis([min(min(scale)), max(max(scale))]);
catch caxiserror
end
color_images_(scale,LIMO);
title(mytitle,'Fontsize',16)

if length(e)>1 % happen if we have multiple times the exact same max values
e = e(1); f = f(1); % then we take the 1st (usually an artefact but allows to see it)
end

% ERP plot at best electrode
ax(3) = subplot(3,3,9);

if LIMO.analysis_flag == 1
mytitle2 = sprintf('time course @ \n electrode %s (%g)', LIMO.data.chanlocs(e).labels,LIMO.data.chanlocs(e).urchan);
plot(timevect,toplot(e,:),'LineWidth',3); grid on; axis tight
elseif LIMO.analysis_flag == 2
mytitle2 = sprintf('power spectra @ \n electrode %s (%g)', LIMO.data.chanlocs(e).labels,LIMO.data.chanlocs(e).urchan);
plot(freqvect,toplot(e,:),'LineWidth',3); grid on; axis tight
end
title(mytitle2,'FontSize',12)

% topoplot at max time
ax(2) = subplot(3,3,6);
chans = LIMO.data.chanlocs;
topoplot(toplot(:,f),chans,'maplimits','maxmin');
if LIMO.analysis_flag == 1
title(['topoplot @ ' num2str(round(timevect(f))) 'ms'],'FontSize',12)
set(gca,'XTickLabel', timevect);
elseif LIMO.analysis_flag == 2
title(['topoplot @' num2str(round(freqvect(f))) 'Hz'],'FontSize',12);
set(gca,'XTickLabel', LIMO.data.freq_list);
end;

% update with mouse clicks
if flag == 1
update = 0;
while update ==0
try
mytitle2 = sprintf('time course @ \n electrode %s (%g)', LIMO.data.expected_chanlocs(y).labels,LIMO.data.expected_chanlocs(y).urchan);
catch ME
mytitle2 = sprintf('time course @ \n electrode %s (%g)', LIMO.data.chanlocs(y).labels,LIMO.data.chanlocs(y).urchan);
[x,y,button]=ginput(1);
catch
update =1; break
end
if button > 1
update = 1;
end
clickedAx = gca;
if clickedAx ~=ax(1)
disp('right click to exit')
else
frame = frame_zeros + round(x / ratio);
% ERP plot at best electrode and topoplot
% at max time or freq
y = round(y);
if LIMO.analysis_flag == 1; % If time analysis
subplot(3,3,6,'replace');
topoplot(toplot(:,frame),LIMO.data.chanlocs);
title(['topoplot @ ' num2str(round(x)) 'ms'],'FontSize',12)

subplot(3,3,9,'replace');
plot(timevect,toplot(y,:),'LineWidth',3); grid on; axis tight
mytitle2 = sprintf('time course @ \n electrode %s (%g)', LIMO.data.chanlocs(e).labels,LIMO.data.chanlocs(e).urchan);
title(mytitle2,'FontSize',12);

elseif LIMO.analysis_flag == 2 % If freq analysis
subplot(3,3,6,'replace');
topoplot(toplot(:,frame),LIMO.data.chanlocs);
title(['topoplot @ ' num2str(round(x)) 'Hz'],'FontSize',12)

subplot(3,3,9,'replace');
plot(freqvect,toplot(y,:),'LineWidth',3); grid on; axis tight
mytitle2 = sprintf('power spectra @ \n electrode %s (%g)', LIMO.data.chanlocs(y).labels,LIMO.data.chanlocs(y).urchan);
title(mytitle2,'FontSize',12);

end
try
mytitle2 = sprintf('time course @ \n electrode %s (%g)', LIMO.data.expected_chanlocs(y).labels,LIMO.data.expected_chanlocs(y).urchan);
catch ME
mytitle2 = sprintf('time course @ \n electrode %s (%g)', LIMO.data.chanlocs(y).labels,LIMO.data.chanlocs(y).urchan);
end
title(mytitle2,'FontSize',12)
end
title(mytitle2,'FontSize',12)
end
end

else % LIMO.analysis_flag == 3 - 3D maps
limo_time_freq_display(toplot,timevect,freqvect,mytitle);
end
end

Expand Down Expand Up @@ -741,7 +751,7 @@ function limo_display_results(Type,FileName,PathName,p,MCC,LIMO,flag)
ylabel('Amplitude in {\mu}V','FontSize',16)
elseif LIMO.analysis_flag == 2
xlabel('Freq in Hz','FontSize',16)
ylabel('Power spectra density');
ylabel('Power spectral density','FontSize',16);
end

LIMO.cache.ERPplot = average;
Expand Down

0 comments on commit 3cc0e67

Please sign in to comment.