clear all; clc
% model written by Allison Shaw (contact for assistance: ashaw@umn.edu)
% started December 2022
%   last updated: 5 January 2022

load figS2sims.mat


eps1 = 0.00000001; % set threshold below which consider speed zero

    % set NaNs to zero to be able to calculate difference
    mat_speed_without(isnan(mat_speed_without))=0;
    mat_speed_without2 = mat_speed_without;
    mat_speed_without2(mat_speed_without2<eps1)=0;
    mat_speed_with2 = mat_speed_with;
    mat_speed_with2(mat_speed_with2<eps1)=0;
    % set zeros to NaN for plotting
    diff_1 = mat_speed_with2 - mat_speed_without2;
    diff_1(abs(diff_1)<eps1)=NaN;

avec2 = fliplr(avec);


mymap = parula;
mymap = [1 1 1; mymap]; % add white for non-spreading simulations

fs1 = 10;  % axes labels
fs3 = 09;  % axis numbering
lw2 = 1; % fig edges

width = 10;
height = 11.5;
xpos = 3;
ypos = 2;
sx = 0.15;
sy = 0.09;
w1 = 0.37;
w2 = w1 - 0.13;
he = 0.22;
dy = 0.1;
dx = 0.17;


xx = 9;
yy = 10;

figure(1); clf
hh = gcf;
set(hh,'PaperUnits','centimeters');
set(hh,'Units','centimeters');
set(gcf,'Position',[xpos ypos width height])



colormap(mymap)

for jjj = 1:3
    
    axes('position',[sx sy+(3-jjj)*(dy+he) w1 he])
    imagesc(flipud(diff_1(:,:,jjj)),[-0.15 0.15])
    colorbar
    set(gca,'XTick',1:xx:length(muvec))
    set(gca,'XTickLabel',muvec(1:xx:end))
    set(gca,'YTick',1:yy:length(avec2))
    set(gca,'YTickLabel',avec2(1:yy:end))
    ylabel('a','fontsize',fs1)
    xlabel('\mu','fontsize',fs1)
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');

    axes('position',[sx+dx+w1 sy+(3-jjj)*(dy+he) w2 he])
    imagesc(flipud(1*(diff_1(:,:,jjj)<0) + 2*(diff_1(:,:,jjj)>=0)),[0 2])
    set(gca,'XTick',1:xx:length(muvec))
    set(gca,'XTickLabel',muvec(1:xx:end))
    set(gca,'YTick',1:yy:length(avec2))
    set(gca,'YTickLabel',avec2(1:yy:end))
    ylabel('a','fontsize',fs1)
    xlabel('\mu','fontsize',fs1)
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');
end



% label subpanels
axes('position',[0 0 1 1],'visible','off')
hold on
     text(0.01,0.97,'a)')
     text(0.55,0.97,'b)')
     text(0.01,0.64,'c)')
     text(0.55,0.64,'d)')
     text(0.01,0.32,'e)')
     text(0.55,0.32,'f)')
     set(gca,'FontSize',fs3,'Fontname', 'Arial');
axis([0 1 0 1])

% Backup previous settings
prePaperType = get(hh,'PaperType');
prePaperPosition = get(hh,'PaperPosition');
prePaperSize = get(hh,'PaperSize');

% Make changing paper type possible
set(hh,'PaperType','<custom>');
% Set the page size and position to match the figure's dimensions
position = get(hh,'Position');
set(hh,'PaperPosition',[0,0,position(3:4)]);
set(hh,'PaperSize',position(3:4));

%print -dpdf -r600 Figure1.pdf
print -djpeg -r600 figS2.jpg

% Restore the previous settings
set(hh,'PaperType',prePaperType);
set(hh,'PaperPosition',prePaperPosition);
set(hh,'PaperSize',prePaperSize);
