%% Timestack profile
Mpath='F:\check_outs\tudelft\vlugtenburg\scripts\Matthieu'

% make timestacks of the profiles

savefigs=0; %Toggle 

load([Mpath '\MakeTopo\AllVbeachsurveys.mat'])
%%
load([Mpath '\waveheightanalysis\Pperiod.mat'])



%% Timestack profile
%for i_transect=1:22;
i_transect=11;
for i_date=1:length(Vsurvey)
timestack(i_date,:)=Vsurvey(i_date).transects.elevation(:,i_transect)';
x=Vsurvey(i_date).transects.cr_sh(:)    ;
date(i_date)=Vsurvey(i_date).matlabdate;
end

 %% Timestack profile

figure(12)
 set(gcf,'PaperPosition',[0  0  40 20])
 set(gcf,'Position',[1          31        1680         944])
 
pcolor(date,x,timestack')
shading flat
ylim([0 1200])
caxis([-8 4])
colorbar
datetick('x','keeplimits')
hold all
stem( Pperiod(2:end,3), Pperiod(2:end,1)/10^7)
stem( Pperiod(2:end,3), Pperiod(2:end,4)/10^7)
stem( Pperiod(2:end,3), Pperiod(2:end,5)/10^7,'m')
legend('elevation [m]','Total wave power between surveys','mean daily wave power','max daily wave power')
title([ 'Profile evelation timestack, profile ' num2str(i_transect)])

hold off

if savefigs==1
filename=[ 'Profile evelation timestack_profile' num2str(i_transect) ]
print ([ Mpath '\profileanalysis\images\' filename '.jpg'],'-djpeg')
end

%% deviation from 1st profile
firstP=timestack(1,:);
firstP=repmat(firstP,length(date),1)

figure
pcolor(date,x,timestack'-firstP')
shading flat
ylim([0 1200])
caxis([-2.5 2.5])
cmap=colormap;
cmap(29:35,:)=1;
colormap(cmap)
colorbar
datetick('x','keeplimits')
hold all
stem( Pperiod(2:end,3), Pperiod(2:end,1)/10^7)
stem( Pperiod(2:end,3), Pperiod(2:end,4)/10^7)
stem( Pperiod(2:end,3), Pperiod(2:end,5)/10^7,'m')
legend('sed (r) /eros (b) [m]','Total wave power between surveys','mean daily wave power','max daily wave power')
title([ 'Profile changes with respect to 1^{st} survey timestack, profile ' num2str(i_transect)])


%% deviation from mean profile
MeanP=nanmean(timestack);
MeanP=repmat(MeanP,length(date),1)

figure
pcolor(date,x,timestack'-MeanP')
shading flat
ylim([0 1200])
caxis([-2.5 2.5])
cmap=colormap;
cmap(29:35,:)=1;
colormap(cmap)
colorbar
datetick('x','keeplimits')
hold all
stem( Pperiod(2:end,3), Pperiod(2:end,1)/10^7)
stem( Pperiod(2:end,3), Pperiod(2:end,4)/10^7)
stem( Pperiod(2:end,3), Pperiod(2:end,5)/10^7,'m')
legend('sed (r) /eros (b) [m]','Total wave power between surveys','mean daily wave power','max daily wave power')
title([ 'Profile changes with respect to mean profile timestack, profile ' num2str(i_transect)])

%% deviation from previous month
Monthlychange=diff(timestack);
Monthlychange=[zeros(1,length(x));  Monthlychange ];
figure
pcolor(date,x,Monthlychange')
shading flat
ylim([0 1200])
caxis([-1.5 1.5])
cmap=colormap;
cmap(29:35,:)=1;
colormap(cmap)
colorbar
datetick('x','keeplimits')
hold all
stem( Pperiod(2:end,3), Pperiod(2:end,1)/10^7)
stem( Pperiod(2:end,3), Pperiod(2:end,4)/10^7)
stem( Pperiod(2:end,3), Pperiod(2:end,5)/10^7,'m')
[C,h] = contour(date,x,timestack',[-9:1:0],'--k');
clabel(C,h,'LabelSpacing',72,'FontSize',10,'Color','k','Rotation',0) ;
legend('sed (r) /eros (b) [m]','Total wave power between surveys','mean daily wave power','max daily wave power','elevation [m]')
title([ 'Elevation change with respect to previous survey timestack, profile ' num2str(i_transect)])
