% This file is licensed under the Allen Institute Terms of Use, which can be found at:
%http://www.alleninstitute.org/Media/policies/terms_of_use_content.html

%------------------------------------------------------------------------------------

%Script to plot Fig.S3 panels (a)-(d) using saved data for 5mV and 100Hz input
% with current-based synapses

%clear variables;

% Settings for plot
fnt = 18;
xtc = [0;50;100;150;200]*10^-3;  %x-axis ticks for time in (ms)
ytc = [0;5;10;15;20]*10^-3; %y-axis ticks for membrane potential in (mV)
xtl = [0;50;100;150;200]; %x-axis labels for time in (ms)
ytl = [0;5;10;15;20]; %y-axis labels for membrane potential in (mV)

set(0,'DefaultFigureWindowStyle','docked');
set(0,'defaultAxesFontName', 'Arial');

%load 'SuppFigS3.mat';

figure;

%%%Probability distribution time-evolution plots

%Time-evolution of probability distribution of membrane potential from NEST simulations
s1 = subplot1(2,2,1);
imagesc(tsim1,vsim1,probsim_cond);set(gca,'YDir','normal');shading flat;
set(gca, 'FontSize',fnt); 
set(gca,'XTick',xtc); set(gca,'YTick',ytc);
set(gca,'XTickLabel',xtl); set(gca,'YTickLabel',ytl);
set(gca,'FontSize',fnt);
caxis([0 100]);
ylabel('voltage (mV)');
xlabel('time (ms) \newline    (a)');
axis square tight;

%Time evolution of probability distribution of membrane potential from DiPDE
s2 = subplot1(2,2,2);
imagesc(t_cond_dipde,vsim1,prob_unif_cond_dipde(:,1:end-1)');set(gca,'YDir','normal');shading flat;
set(gca,'FontSize',fnt); 
set(gca,'XTick',xtc); set(gca,'YTick',ytc);
set(gca,'XTickLabel',xtl); set(gca,'YTickLabel',ytl);
set(gca,'FontSize',fnt);
caxis([0 100]);
xlabel('time (ms) \newline    (b)');
axis square tight;
colorbar('YTickLabel',{'0','0.2','0.4','0.6','0.8','1'});
set(gca,'FontSize',fnt);

%Settings to align heat-maps properly
s1Pos = get(s1,'position');
s2Pos = get(s2,'position');
s2Pos(1) = s1Pos(1) + 1.1*s1Pos(3);
s1Pos(4) = 0.8*s1Pos(4);
s2Pos(3:4) = [s1Pos(3:4)];
set(s1,'position',s1Pos);
set(s2,'position',s2Pos);

%FIRING RATE PLOTs
%-----------------
s3 = subplot1(2,2,3);
plot(tplot, simfrate_cond(1:end-1),'b','LineWidth',2);
set(gca,'XTick',xtc);
set(gca,'XTickLabel',xtl);
hold on;
plot(t_cond_dipde,fout_cond_dipde, '--r', 'LineWidth',2);
legend('Sim','DiPDE','Location','SouthEast');
set(gca, 'FontSize',fnt);
set(gca,'FontSize',fnt);
ylabel('Firing rate (Hz)');xlabel('time (ms) \newline    (c)');
axis square tight;

%Membrane potential probability distribution at t = 200 ms
%---------------------------------------------------------
probsim_cond(end+1,end-1) = 0;
s4 = subplot1(2,2,4);
plot(v0(1:end),10^-3*probsim_cond(1:end,end-1),'b', 'LineWidth',2);
hold on;
plot(v0(1:end),10^-3*prob_unif_cond_dipde(end-1,1:end),'--r', 'LineWidth',2);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
legend('Sim','DiPDE','Location','NorthEast');
set(gca, 'FontSize',fnt);
ylabel('Prob density (mV^{-1})');xlabel('voltage (mV) \newline        (d)');
axis square tight;

%Align panels S3(c) and S3(d) properly
%-----------------------------------
s3Pos = get(s3,'position');
s4Pos = get(s4,'position');
s4Pos(1) = s2Pos(1);
s3Pos(4) = s1Pos(4);
s4Pos(4) = s1Pos(4);
set(s3,'position',s3Pos);
set(s4,'position',s4Pos);

%print2eps Fig_S3.eps
