clc 
clear all
close all

% data assimilation plots

da_corr_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_corr_2.mat';
da_corr_data = load(da_corr_file);

da_ci_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_corr_ci_2.mat';
da_ci_data = load(da_ci_file);


da_corr_vec = [da_corr_data.corr_mat(:,6)';...
    da_corr_data.corr_mat(:,7)';...
    da_corr_data.corr_mat(:,10)';...
    da_corr_data.corr_mat(:,2)'];

da_corr_vec = [da_corr_vec nanmean(da_corr_vec,2)];

da_corr_vec = round(da_corr_vec,2);

da_ll_vec = [da_ci_data.ci_mat(:,10)';...
    da_ci_data.ci_mat(:,12)';...
    da_ci_data.ci_mat(:,18)';...
    da_ci_data.ci_mat(:,2)'];

da_ll_vec = [da_ll_vec nanmean(da_ll_vec,2)];

da_ll_vec = da_corr_vec - da_ll_vec*1.1;
da_ll_vec = round(da_ll_vec,2);

da_ul_vec = [da_ci_data.ci_mat(:,11)';...
    da_ci_data.ci_mat(:,13)';...
    da_ci_data.ci_mat(:,19)';...
    da_ci_data.ci_mat(:,3)'];

da_ul_vec = [da_ul_vec nanmean(da_ul_vec,2)];

da_ul_vec = da_ul_vec*1.1 - da_corr_vec;
da_ul_vec = round(da_ul_vec,2);


station_names = {'Walnut Gulch 1';'Walnut Gulch 2';'Walnut Gulch 3';'Little Washita';'Fort Cobb1';'Fort Cobb2';...
    'Little River';'St Jospehs';...
    'South Fork 1';'South Fork 2';'South Fork';'Tonzi Ranch';'TxSON 1';'TxSON 2';'All'};

station_names = {'WG 1   ';'WG 2   ';'WG 3   ';'LW   ';'FC 1   ';'FC 2   ';...
    'LR   ';'SJ   ';...
    'SF 1   ';'SF 2   ';'SF 3   ';'TR   ';'TX 1   ';'TX 2   ';'All   '};


% sf_index = [9 11];
% 
% da_corr_vec(:,sf_index) = [];
% da_ll_vec(:,sf_index) = [];
% da_ul_vec(:,sf_index) = [];
% station_names(sf_index) = [];

x = 1:size(da_corr_vec,2);

C = linspecer(4);


figure

errorbar(x-0.3,da_corr_vec(1,:),da_ll_vec(1,:),da_ul_vec(1,:),'LineStyle','none','Color',C(2,:),...
    'Marker','s','MarkerFaceColor',C(2,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x-0.1,da_corr_vec(2,:),da_ll_vec(2,:),da_ul_vec(2,:),'LineStyle','none','Color',C(1,:),...
    'Marker','d','MarkerFaceColor',C(1,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.1,da_corr_vec(3,:),da_ll_vec(3,:),da_ul_vec(3,:),'LineStyle','none','Color',C(3,:),...
    'Marker','o','MarkerFaceColor',C(3,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.3,da_corr_vec(4,:),da_ll_vec(4,:),da_ul_vec(4,:),'LineStyle','none','Color',C(4,:),...
    'Marker','^','MarkerFaceColor',C(4,:),'LineWidth',2,'MarkerSize',9)
grid on
% Reduce the size of the axis so that all the labels fit in the figure.
pos = get(gca,'Position');
set(gca,'Position',[pos(1), .2, pos(3) .65])
% Add a title.
title('','FontSize',14)
% Set the X-Tick locations so that every other month is labeled.
Xt = 1:size(da_corr_vec,2);
Xl = [0 size(da_corr_vec,2)+1];
set(gca,'XTick',Xt,'XLim',Xl,'FontSize',16);
set(gca,'YLim',[0.4 1.1]);
ax = axis;    % Current axis limits
axis(axis);    % Set the axis limit modes (e.g. XLimMode) to manual
Yl = ax(3:4);  % Y-axis limits
% Place the text labels
t = text(Xt,Yl(1)*ones(1,length(Xt)),station_names);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
    'Rotation',45,'FontSize',16);
% Remove the default labels
set(gca,'XTickLabel','')
% Get the Extent of each text object.  This
% loop is unavoidable.
for i = 1:length(t)
    ext(i,:) = get(t(i),'Extent');
end
% Determine the lowest point.  The X-label will be
% placed so that the top is aligned with this point.
LowYPoint = min(ext(:,2));
% Place the axis label at this point
XMidPoint = Xl(1)+abs(diff(Xl))/2;
tl = text(XMidPoint,LowYPoint,'', ...
    'VerticalAlignment','top', ...
    'HorizontalAlignment','center');
ylabel('correlation [-]','FontSize',16)
% h=legend('NRv5','L2P','NN','Location','northeast');
% set(h,'FontSize',14)
h=legend('DA-NN','DA-NN-CDF','DA-L2P-gCDF','OL','Location','northoutside',...
    'Orientation','horizontal');
set(h,'FontSize',16)

set(gcf,'paperunits','centimeters')
set(gcf,'paperposition',[1 1 40 16.5])
saveas(gcf,['/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_corr_da'],'epsc')
print('/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_corr_da','-dpng','-r300')


% plot DA bias

da_bias_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_bias.mat';
da_bias_data = load(da_bias_file);

da_bias_std_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_bias_std.mat';
da_bias_std_data = load(da_bias_std_file);

da_bias_vec = [da_bias_data.bias_mat(:,6)';...
    da_bias_data.bias_mat(:,7)';...
    da_bias_data.bias_mat(:,10)';...
    da_bias_data.bias_mat(:,2)'];
% da_bias_vec(:,[9 11]) =[];


da_bias_ll_vec = [da_bias_std_data.std_mat(:,6)';...
    da_bias_std_data.std_mat(:,7)';...
    da_bias_std_data.std_mat(:,10)';...
    da_bias_std_data.std_mat(:,2)'];
% da_bias_ll_vec(:,[9 11]) =[];
da_bias_ul_vec = da_bias_ll_vec;
% da_bias_ul_vec = da_bias_vec + da_bias_ul_vec;
% da_bias_ll_vec = da_bias_vec - da_bias_ll_vec;


da_bias_ll_vec = [da_bias_ll_vec nanmean(da_bias_ll_vec,2)];
da_bias_ul_vec = [da_bias_ul_vec nanmean(da_bias_ul_vec,2)];
da_bias_vec = [da_bias_vec nanmean(da_bias_vec,2)];

%da_bias_ll_vec = da_bias_vec - da_bias_ll_vec;

%da_bias_ul_vec = da_bias_ll_vec + da_bias_vec;

x = 1:size(da_corr_vec,2);

% station_names = {'Walnut Gulch 1';'Walnut Gulch 2';'Walnut Gulch 3';'Little Washita';'Fort Cobb1';'Fort Cobb2';...
%     'Little River';'St Jospehs';...
%     'South Fork';'Tonzi Ranch';'TxSON 1';'TxSON 2';'All'};

% station_names = {'WG 1   ';'WG 2   ';'WG 3   ';'LW   ';'FC 1   ';'FC 2   ';...
%     'LR   ';'SJ   ';...
%     'SF   ';'TR   ';'TX 1   ';'TX 2   ';'All   '};

C = linspecer(4);
x2 = 0:0.1:(size(da_corr_vec,2)+1);

figure

errorbar(x-0.3,da_bias_vec(1,:),da_bias_ll_vec(1,:),da_bias_ul_vec(1,:),'LineStyle','none','Color',C(2,:),...
    'Marker','s','MarkerFaceColor',C(2,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x-0.1,da_bias_vec(2,:),da_bias_ll_vec(2,:),da_bias_ul_vec(2,:),'LineStyle','none','Color',C(1,:),...
    'Marker','d','MarkerFaceColor',C(1,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.1,da_bias_vec(3,:),da_bias_ll_vec(3,:),da_bias_ul_vec(3,:),'LineStyle','none','Color',C(3,:),...
    'Marker','o','MarkerFaceColor',C(3,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.3,da_bias_vec(4,:),da_bias_ll_vec(4,:),da_bias_ul_vec(4,:),'LineStyle','none','Color',C(4,:),...
    'Marker','^','MarkerFaceColor',C(4,:),'LineWidth',2,'MarkerSize',9)
plot(x2,zeros(size(x2)),'-k')
grid on 
% Reduce the size of the axis so that all the labels fit in the figure.
pos = get(gca,'Position');
set(gca,'Position',[pos(1), .2, pos(3) .65])
% Add a title.
title('','FontSize',20)
% Set the X-Tick locations so that every other month is labeled.
Xt = 1:size(da_corr_vec,2);
Xl = [0 size(da_corr_vec,2)+1];
set(gca,'XTick',Xt,'XLim',Xl,'FontSize',16);
set(gca,'YLim',[0 0.2]);
ax = axis;    % Current axis limits
axis(axis);    % Set the axis limit modes (e.g. XLimMode) to manual
Yl = ax(3:4);  % Y-axis limits
% Place the text labels
t = text(Xt,Yl(1)*ones(1,length(Xt)),station_names);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
      'Rotation',45,'FontSize',16);
% Remove the default labels
set(gca,'XTickLabel','')
% Get the Extent of each text object.  This
% loop is unavoidable.
for i = 1:length(t)
    ext(i,:) = get(t(i),'Extent');
end
% Determine the lowest point.  The X-label will be
% placed so that the top is aligned with this point.
LowYPoint = min(ext(:,2));
% Place the axis label at this point
XMidPoint = Xl(1)+abs(diff(Xl))/2;
tl = text(XMidPoint,LowYPoint,'', ...
    'VerticalAlignment','top', ...
    'HorizontalAlignment','center');
ylabel('absolute bias [m^3 m^{-3}]','FontSize',16)
h=legend('DA-NN','DA-NN-CDF','DA-L2P-gCDF','OL','Location','northoutside',...
    'Orientation','horizontal');
set(h,'FontSize',16)
set(gcf,'paperunits','centimeters')
set(gcf,'paperposition',[1 1 40 16.5])
saveas(gcf,['/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_bias_da'],'epsc')
print('/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_bias_da','-dpng','-r300')

% plot DA ubRMSE

da_ubrmse_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_ubrmse.mat';
da_ubrmse_data = load(da_ubrmse_file);

da_ubrmse_std_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_ubrmse_std.mat';
da_ubrmse_std_data = load(da_ubrmse_std_file);

da_ubrmse_vec = [da_ubrmse_data.ubrmse_mat(:,6)';...
    da_ubrmse_data.ubrmse_mat(:,7)';...
    da_ubrmse_data.ubrmse_mat(:,10)';...
    da_ubrmse_data.ubrmse_mat(:,2)'];
% da_ubrmse_vec(:,[9 11]) =[];


da_ubrmse_ll_vec = [da_ubrmse_std_data.ubrmse_std_mat(:,6)';...
    da_ubrmse_std_data.ubrmse_std_mat(:,7)';...
    da_ubrmse_std_data.ubrmse_std_mat(:,10)';...
    da_ubrmse_std_data.ubrmse_std_mat(:,2)'];
da_ubrmse_ll_vec = sqrt(da_ubrmse_ll_vec)./sqrt(size(da_ubrmse_ll_vec,2));
% da_ubrmse_ll_vec(:,[9 11]) =[];
da_ubrmse_ul_vec = da_ubrmse_ll_vec;
% da_ubrmse_ul_vec = da_ubrmse_vec + da_ubrmse_ul_vec;
% da_ubrmse_ll_vec = da_ubrmse_vec - da_ubrmse_ll_vec;


da_ubrmse_ll_vec = [da_ubrmse_ll_vec nanmean(da_ubrmse_ll_vec,2)];
da_ubrmse_ul_vec = [da_ubrmse_ul_vec nanmean(da_ubrmse_ul_vec,2)];
da_ubrmse_vec = [da_ubrmse_vec nanmean(da_ubrmse_vec,2)];

%da_ubrmse_ll_vec = da_ubrmse_vec - da_ubrmse_ll_vec;

%da_ubrmse_ul_vec = da_ubrmse_ll_vec + da_ubrmse_vec;

x = 1:size(da_corr_vec,2);

% station_names = {'Walnut Gulch 1';'Walnut Gulch 2';'Walnut Gulch 3';'Little Washita';'Fort Cobb1';'Fort Cobb2';...
%     'Little River';'St Jospehs';...
%     'South Fork';'Tonzi Ranch';'TxSON 1';'TxSON 2';'All'};

% station_names = {'WG 1   ';'WG 2   ';'WG 3   ';'LW   ';'FC 1   ';'FC 2   ';...
%     'LR   ';'SJ   ';...
%     'SF   ';'TR   ';'TX 1   ';'TX 2   ';'All   '};

C = linspecer(4);
x2 = 0:0.1:(size(da_corr_vec,2)+1);

figure

errorbar(x-0.3,da_ubrmse_vec(1,:),da_ubrmse_ll_vec(1,:),da_ubrmse_ul_vec(1,:),'LineStyle','none','Color',C(2,:),...
    'Marker','s','MarkerFaceColor',C(2,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x-0.1,da_ubrmse_vec(2,:),da_ubrmse_ll_vec(2,:),da_ubrmse_ul_vec(2,:),'LineStyle','none','Color',C(1,:),...
    'Marker','d','MarkerFaceColor',C(1,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.1,da_ubrmse_vec(3,:),da_ubrmse_ll_vec(3,:),da_ubrmse_ul_vec(3,:),'LineStyle','none','Color',C(3,:),...
    'Marker','o','MarkerFaceColor',C(3,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.3,da_ubrmse_vec(4,:),da_ubrmse_ll_vec(4,:),da_ubrmse_ul_vec(4,:),'LineStyle','none','Color',C(4,:),...
    'Marker','^','MarkerFaceColor',C(4,:),'LineWidth',2,'MarkerSize',9)
plot(x2,zeros(size(x2)),'-k')
grid on 
% Reduce the size of the axis so that all the labels fit in the figure.
pos = get(gca,'Position');
set(gca,'Position',[pos(1), .2, pos(3) .65])
% Add a title.
title('','FontSize',20)
% Set the X-Tick locations so that every other month is labeled.
Xt = 1:size(da_corr_vec,2);
Xl = [0 size(da_corr_vec,2)+1];
set(gca,'XTick',Xt,'XLim',Xl,'FontSize',16);
set(gca,'YLim',[0 0.1]);
ax = axis;    % Current axis limits
axis(axis);    % Set the axis limit modes (e.g. XLimMode) to manual
Yl = ax(3:4);  % Y-axis limits
% Place the text labels
t = text(Xt,Yl(1)*ones(1,length(Xt)),station_names);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
      'Rotation',45,'FontSize',16);
% Remove the default labels
set(gca,'XTickLabel','')
% Get the Extent of each text object.  This
% loop is unavoidable.
for i = 1:length(t)
    ext(i,:) = get(t(i),'Extent');
end
% Determine the lowest point.  The X-label will be
% placed so that the top is aligned with this point.
LowYPoint = min(ext(:,2));
% Place the axis label at this point
XMidPoint = Xl(1)+abs(diff(Xl))/2;
tl = text(XMidPoint,LowYPoint,'', ...
    'VerticalAlignment','top', ...
    'HorizontalAlignment','center');
ylabel('ubRMSE [m^3 m^{-3}]','FontSize',16)
h=legend('DA-NN','DA-NN-CDF','DA-L2P-gCDF','OL','Location','northoutside',...
    'Orientation','horizontal');
set(h,'FontSize',16)
set(gcf,'paperunits','centimeters')
set(gcf,'paperposition',[1 1 40 16.5])
saveas(gcf,['/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_ubrmse_da'],'epsc')
print('/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_ubrmse_da','-dpng','-r300')



%% plot comparison with L4 data

da_corr_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_corr_2.mat';
da_corr_data = load(da_corr_file);

da_ci_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_corr_ci_2.mat';
da_ci_data = load(da_ci_file);

l4_corr_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_corr.mat';
l4_corr_data = load(l4_corr_file);

l4_ci_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_corr_ci.mat';
l4_ci_data = load(l4_ci_file);

nrv4_corr = l4_corr_data.corr_mat(:,3);
smap_l4_corr = l4_corr_data.corr_mat(:,2);

da_l4_corr_vec = [da_corr_data.corr_mat(:,6)';...
    da_corr_data.corr_mat(:,2)';...
    nrv4_corr';...
    smap_l4_corr'];

da_l4_ll_vec = [da_ci_data.ci_mat(:,10)';...
    da_ci_data.ci_mat(:,2)';...
    l4_ci_data.ci_mat(:,4)'
    l4_ci_data.ci_mat(:,2)'];

da_l4_ul_vec = [da_ci_data.ci_mat(:,11)';...
    da_ci_data.ci_mat(:,3)';...
    l4_ci_data.ci_mat(:,5)';...
    l4_ci_data.ci_mat(:,3)'];


da_l4_corr_vec = [da_l4_corr_vec mean(da_l4_corr_vec,2)];

% da_corr_vec = round(da_corr_vec,2);



da_l4_ll_vec = [da_l4_ll_vec mean(da_l4_ll_vec,2)];

da_l4_ll_vec = (da_l4_corr_vec - da_l4_ll_vec)*2;
%da_ll_vec = round(da_ll_vec,2);

da_l4_ul_vec = [da_l4_ul_vec mean(da_l4_ul_vec,2)];

da_l4_ul_vec = (da_l4_ul_vec - da_l4_corr_vec)*2;
%da_ul_vec = round(da_ul_vec,2);

% sf_index = [9 11];
% 
% da_l4_corr_vec(:,sf_index) = [];
% da_l4_ll_vec(:,sf_index) = [];
% da_l4_ul_vec(:,sf_index) = [];

x = 1:(size(da_l4_corr_vec,2));

C = linspecer(4);

figure

errorbar(x-0.3,da_l4_corr_vec(1,:),da_l4_ll_vec(1,:),da_l4_ul_vec(1,:),'LineStyle','none','Color',C(2,:),...
    'Marker','s','MarkerFaceColor',C(2,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x-0.1,da_l4_corr_vec(2,:),da_l4_ll_vec(2,:),da_l4_ul_vec(2,:),'LineStyle','none','Color',C(4,:),...
    'Marker','^','MarkerFaceColor',C(4,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.1,da_l4_corr_vec(3,:),da_l4_ll_vec(3,:),da_l4_ul_vec(3,:),'LineStyle','none','Color',C(3,:),...
    'Marker','o','MarkerFaceColor',C(3,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.3,da_l4_corr_vec(4,:),da_l4_ll_vec(4,:),da_l4_ul_vec(4,:),'LineStyle','none','Color',C(1,:),...
    'Marker','d','MarkerFaceColor',C(1,:),'LineWidth',2,'MarkerSize',9)
grid on
% Reduce the size of the axis so that all the labels fit in the figure.
pos = get(gca,'Position');
set(gca,'Position',[pos(1), .2, pos(3) .65])
% Add a title.
title('','FontSize',14)
% Set the X-Tick locations so that every other month is labeled.
Xt = 1:size(da_corr_vec,2);
Xl = [0 size(da_corr_vec,2)+1];
set(gca,'XTick',Xt,'XLim',Xl,'FontSize',16);
set(gca,'YLim',[0.4 1.1]);
ax = axis;    % Current axis limits
axis(axis);    % Set the axis limit modes (e.g. XLimMode) to manual
Yl = ax(3:4);  % Y-axis limits
% Place the text labels
t = text(Xt,Yl(1)*ones(1,length(Xt)),station_names);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
    'Rotation',45,'FontSize',16);
% Remove the default labels
set(gca,'XTickLabel','')
% Get the Extent of each text object.  This
% loop is unavoidable.
for i = 1:length(t)
    ext(i,:) = get(t(i),'Extent');
end
% Determine the lowest point.  The X-label will be
% placed so that the top is aligned with this point.
LowYPoint = min(ext(:,2));
% Place the axis label at this point
XMidPoint = Xl(1)+abs(diff(Xl))/2;
tl = text(XMidPoint,LowYPoint,'', ...
    'VerticalAlignment','top', ...
    'HorizontalAlignment','center');
ylabel('correlation [-]','FontSize',16)

h=legend('DA-NN','OL','OL-L4','DA-L4','Location','northoutside',...
    'Orientation','horizontal');
set(h,'FontSize',16)

set(gcf,'paperunits','centimeters')
set(gcf,'paperposition',[1 1 40 16.5])
saveas(gcf,['/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_corr_da_l4'],'epsc')
print('/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_corr_da_l4','-dpng','-r300')


% plot bias

da_bias_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_bias_2.mat';
da_bias_data = load(da_bias_file);

l4_bias_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_bias.mat';
l4_bias_data = load(l4_bias_file);

l4_bias_std_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_bias_std.mat';
l4_bias_std_data = load(l4_bias_std_file);

l4_bias_ci_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_bias_ci.mat';
l4_bias_ci_data = load(l4_bias_ci_file);

da_bias_vec = [da_bias_data.bias_mat(:,6)';...
    da_bias_data.bias_mat(:,2)';...
    abs(l4_bias_data.bias_mat(:,3))';...
    abs(l4_bias_data.bias_mat(:,2))'];
% da_bias_vec(:,[9 11]) =[];

da_bias_std_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_bias_std.mat';
da_bias_std_data = load(da_bias_std_file);

da_bias_ll_vec = [da_bias_std_data.std_mat(:,6)';...
    da_bias_std_data.std_mat(:,2)';...
    l4_bias_std_data.std_mat(:,3)';...
    l4_bias_std_data.std_mat(:,2)'];
% da_bias_ll_vec(:,[9 11]) =[];
da_bias_ul_vec = da_bias_ll_vec;

da_bias_vec = [da_bias_vec mean(da_bias_vec,2)];
da_bias_ll_vec = [da_bias_ll_vec mean(da_bias_ll_vec,2)];
da_bias_ul_vec = [da_bias_ul_vec mean(da_bias_ul_vec,2)];


x = 1:size(da_bias_vec,2);

% station_names = {'Walnut Gulch 1';'Walnut Gulch 2';'Walnut Gulch 3';'Little Washita';'Fort Cobb1';'Fort Cobb2';...
%     'Little River';'St Jospehs';...
%     'South Fork';'Tonzi Ranch';'TxSON 1';'TxSON 2';'All'};

% station_names = {'WG 1   ';'WG 2   ';'WG 3   ';'LW   ';'FC 1   ';'FC 2   ';...
%    'LR   ';'SJ   ';...
%     'SF   ';'TR   ';'TX 1   ';'TX 2   ';'All   '};

C = linspecer(4);
x2 = 0:0.1:(size(da_bias_vec,2)+1);


figure
errorbar(x-0.3,da_bias_vec(1,:),da_bias_ll_vec(1,:),da_bias_ul_vec(1,:),'LineStyle','none','Color',C(2,:),...
    'Marker','s','MarkerFaceColor',C(2,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x-0.1,da_bias_vec(2,:),da_bias_ll_vec(2,:),da_bias_ul_vec(2,:),'LineStyle','none','Color',C(4,:),...
    'Marker','^','MarkerFaceColor',C(4,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.1,da_bias_vec(3,:),da_bias_ll_vec(3,:),da_bias_ul_vec(3,:),'LineStyle','none','Color',C(3,:),...
    'Marker','o','MarkerFaceColor',C(3,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.3,da_bias_vec(4,:),da_bias_ll_vec(4,:),da_bias_ul_vec(4,:),'LineStyle','none','Color',C(1,:),...
    'Marker','d','MarkerFaceColor',C(1,:),'LineWidth',2,'MarkerSize',9)
plot(x2,zeros(size(x2)),'-k')
grid on 
% Reduce the size of the axis so that all the labels fit in the figure.
pos = get(gca,'Position');
set(gca,'Position',[pos(1), .2, pos(3) .65])
% Add a title.
title('','FontSize',14)
% Set the X-Tick locations so that every other month is labeled.
Xt = 1:size(da_bias_vec,2);
Xl = [0 size(da_bias_vec,2)+1];
set(gca,'XTick',Xt,'XLim',Xl,'FontSize',16);
set(gca,'YLim',[0 0.2]);
ax = axis;    % Current axis limits
axis(axis);    % Set the axis limit modes (e.g. XLimMode) to manual
Yl = ax(3:4);  % Y-axis limits
% Place the text labels
t = text(Xt,Yl(1)*ones(1,length(Xt)),station_names);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
      'Rotation',45,'FontSize',16);
% Remove the default labels
set(gca,'XTickLabel','')
% Get the Extent of each text object.  This
% loop is unavoidable.
for i = 1:length(t)
  ext(i,:) = get(t(i),'Extent');
end
% Determine the lowest point.  The X-label will be
% placed so that the top is aligned with this point.
LowYPoint = min(ext(:,2));
% Place the axis label at this point
XMidPoint = Xl(1)+abs(diff(Xl))/2;
tl = text(XMidPoint,LowYPoint,'', ...
          'VerticalAlignment','top', ...
          'HorizontalAlignment','center');
      ylabel('bias [m^3 m^{-3}]','FontSize',16)
h=legend('DA-NN','OL','OL-L4','DA-L4','Location','northoutside',...
    'Orientation','horizontal');
set(h,'FontSize',16)
set(gcf,'paperunits','centimeters')
set(gcf,'paperposition',[1 1 40 16.5])
saveas(gcf,['/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_bias_da_l4'],'epsc')
print('/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_bias_da_l4','-dpng','-r300')


% plot L4 ubRMSE

da_ubrmse_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_ubrmse.mat';
da_ubrmse_data = load(da_ubrmse_file);

l4_ubrmse_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_ubrmse.mat';
l4_ubrmse_data = load(l4_ubrmse_file);

l4_ubrmse_std_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_bias_ubrmse_std.mat';
l4_ubrmse_std_data = load(l4_ubrmse_std_file);

% l4_ubrmse_ci_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_ubrmse_ci.mat';
% l4_ubrmse_ci_data = load(l4_ubrmse_ci_file);

da_ubrmse_vec = [da_ubrmse_data.ubrmse_mat(:,6)';...
    da_ubrmse_data.ubrmse_mat(:,2)';...
    l4_ubrmse_data.ubrmse_mat(:,3)';...
    l4_ubrmse_data.ubrmse_mat(:,2)'];
% da_ubrmse_vec(:,[9 11]) =[];

da_ubrmse_std_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_ubrmse_std.mat';
da_ubrmse_std_data = load(da_ubrmse_std_file);

da_ubrmse_ll_vec = [da_ubrmse_std_data.ubrmse_std_mat(:,6)';...
    da_ubrmse_std_data.ubrmse_std_mat(:,2)';...
    l4_ubrmse_std_data.ubrmse_std_mat(:,3)';...
    l4_ubrmse_std_data.ubrmse_std_mat(:,2)'];
da_ubrmse_ll_vec = sqrt(da_ubrmse_ll_vec)./sqrt(size(da_ubrmse_ll_vec,2));
% da_ubrmse_ll_vec(:,[9 11]) =[];
da_ubrmse_ul_vec = da_ubrmse_ll_vec;

da_ubrmse_vec = [da_ubrmse_vec mean(da_ubrmse_vec,2)];
da_ubrmse_ll_vec = [da_ubrmse_ll_vec mean(da_ubrmse_ll_vec,2)];
da_ubrmse_ul_vec = [da_ubrmse_ul_vec mean(da_ubrmse_ul_vec,2)];


x = 1:size(da_ubrmse_vec,2);

% station_names = {'Walnut Gulch 1';'Walnut Gulch 2';'Walnut Gulch 3';'Little Washita';'Fort Cobb1';'Fort Cobb2';...
%     'Little River';'St Jospehs';...
%     'South Fork';'Tonzi Ranch';'TxSON 1';'TxSON 2';'All'};

% station_names = {'WG 1   ';'WG 2   ';'WG 3   ';'LW   ';'FC 1   ';'FC 2   ';...
%    'LR   ';'SJ   ';...
%     'SF   ';'TR   ';'TX 1   ';'TX 2   ';'All   '};

C = linspecer(4);
x2 = 0:0.1:(size(da_ubrmse_vec,2)+1);


figure
errorbar(x-0.3,da_ubrmse_vec(1,:),da_ubrmse_ll_vec(1,:),da_ubrmse_ul_vec(1,:),'LineStyle','none','Color',C(2,:),...
    'Marker','s','MarkerFaceColor',C(2,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x-0.1,da_ubrmse_vec(2,:),da_ubrmse_ll_vec(2,:),da_ubrmse_ul_vec(2,:),'LineStyle','none','Color',C(4,:),...
    'Marker','^','MarkerFaceColor',C(4,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.1,da_ubrmse_vec(3,:),da_ubrmse_ll_vec(3,:),da_ubrmse_ul_vec(3,:),'LineStyle','none','Color',C(3,:),...
    'Marker','o','MarkerFaceColor',C(3,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.3,da_ubrmse_vec(4,:),da_ubrmse_ll_vec(4,:),da_ubrmse_ul_vec(4,:),'LineStyle','none','Color',C(1,:),...
    'Marker','d','MarkerFaceColor',C(1,:),'LineWidth',2,'MarkerSize',9)
plot(x2,zeros(size(x2)),'-k')
grid on 
% Reduce the size of the axis so that all the labels fit in the figure.
pos = get(gca,'Position');
set(gca,'Position',[pos(1), .2, pos(3) .65])
% Add a title.
title('','FontSize',14)
% Set the X-Tick locations so that every other month is labeled.
Xt = 1:size(da_ubrmse_vec,2);
Xl = [0 size(da_ubrmse_vec,2)+1];
set(gca,'XTick',Xt,'XLim',Xl,'FontSize',16);
set(gca,'YLim',[0 0.1]);
ax = axis;    % Current axis limits
axis(axis);    % Set the axis limit modes (e.g. XLimMode) to manual
Yl = ax(3:4);  % Y-axis limits
% Place the text labels
t = text(Xt,Yl(1)*ones(1,length(Xt)),station_names);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
      'Rotation',45,'FontSize',16);
% Remove the default labels
set(gca,'XTickLabel','')
% Get the Extent of each text object.  This
% loop is unavoidable.
for i = 1:length(t)
  ext(i,:) = get(t(i),'Extent');
end
% Determine the lowest point.  The X-label will be
% placed so that the top is aligned with this point.
LowYPoint = min(ext(:,2));
% Place the axis label at this point
XMidPoint = Xl(1)+abs(diff(Xl))/2;
tl = text(XMidPoint,LowYPoint,'', ...
          'VerticalAlignment','top', ...
          'HorizontalAlignment','center');
      ylabel('ubRMSE [m^3 m^{-3}]','FontSize',16)
h=legend('DA-NN','OL','OL-L4','DA-L4','Location','northoutside',...
    'Orientation','horizontal');
set(h,'FontSize',16)
set(gcf,'paperunits','centimeters')
set(gcf,'paperposition',[1 1 40 16.5])
saveas(gcf,['/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_ubrmse_da_l4'],'epsc')
print('/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_ubrmse_da_l4','-dpng','-r300')


%% plot root zone metric plots

da_corr_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_corr_RZ_2.mat';
da_corr_data = load(da_corr_file);

da_ci_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_corr_ci_RZ_2.mat';
da_ci_data = load(da_ci_file);

da_corr_vec = [da_corr_data.corr_mat(:,6)';...
    da_corr_data.corr_mat(:,7)';...
    da_corr_data.corr_mat(:,10)';...
    da_corr_data.corr_mat(:,2)'];

da_corr_vec = [da_corr_vec nanmean(da_corr_vec,2)];

da_corr_vec = round(da_corr_vec,2);

da_ll_vec = [da_ci_data.ci_mat(:,10)';...
    da_ci_data.ci_mat(:,12)';...
    da_ci_data.ci_mat(:,18)';...
    da_ci_data.ci_mat(:,2)'];

da_ll_vec = [da_ll_vec nanmean(da_ll_vec,2)];

da_ll_vec = da_corr_vec - da_ll_vec*1.1;
da_ll_vec = round(da_ll_vec,2);

da_ul_vec = [da_ci_data.ci_mat(:,11)';...
    da_ci_data.ci_mat(:,13)';...
    da_ci_data.ci_mat(:,19)';...
    da_ci_data.ci_mat(:,3)'];

da_ul_vec = [da_ul_vec nanmean(da_ul_vec,2)];

da_ul_vec = da_ul_vec*1.1 - da_corr_vec;
da_ul_vec = round(da_ul_vec,2);



station_names = {'Walnut Gulch 1';'Walnut Gulch 2';'Walnut Gulch 3';'Little Washita';'Fort Cobb1';'Fort Cobb2';...
    'Little River';'St Jospehs';...
    'South Fork 1';'South Fork 2';'South Fork';'Tonzi Ranch';'TxSON 1';'TxSON 2';'All'};

station_names = {'WG 1   ';'WG 2   ';'WG 3   ';'LW   ';'FC 1   ';'FC 2   ';...
    'LR   ';'SJ   ';...
    'SF 1   ';'SF 2   ';'SF 3   ';'TR   ';'TX 1   ';'TX 2   ';'All   '};

% 
% sf_index = [9 11];
% 
% da_corr_vec(:,sf_index) = [];
% da_ll_vec(:,sf_index) = [];
% da_ul_vec(:,sf_index) = [];
% station_names(sf_index) = [];

x = 1:size(da_corr_vec,2);

C = linspecer(4);


figure

errorbar(x-0.3,da_corr_vec(1,:),da_ll_vec(1,:),da_ul_vec(1,:),'LineStyle','none','Color',C(2,:),...
    'Marker','s','MarkerFaceColor',C(2,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x-0.1,da_corr_vec(2,:),da_ll_vec(2,:),da_ul_vec(2,:),'LineStyle','none','Color',C(1,:),...
    'Marker','d','MarkerFaceColor',C(1,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.1,da_corr_vec(3,:),da_ll_vec(3,:),da_ul_vec(3,:),'LineStyle','none','Color',C(3,:),...
    'Marker','o','MarkerFaceColor',C(3,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.3,da_corr_vec(4,:),da_ll_vec(4,:),da_ul_vec(4,:),'LineStyle','none','Color',C(4,:),...
    'Marker','^','MarkerFaceColor',C(4,:),'LineWidth',2,'MarkerSize',9)
grid on
% Reduce the size of the axis so that all the labels fit in the figure.
pos = get(gca,'Position');
set(gca,'Position',[pos(1), .2, pos(3) .65])
% Add a title.
title('','FontSize',14)
% Set the X-Tick locations so that every other month is labeled.
Xt = 1:size(da_corr_vec,2);
Xl = [0 size(da_corr_vec,2)+1];
set(gca,'XTick',Xt,'XLim',Xl,'FontSize',16);
set(gca,'YLim',[0 1.1]);
ax = axis;    % Current axis limits
axis(axis);    % Set the axis limit modes (e.g. XLimMode) to manual
Yl = ax(3:4);  % Y-axis limits
% Place the text labels
t = text(Xt,Yl(1)*ones(1,length(Xt)),station_names);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
    'Rotation',45,'FontSize',16);
% Remove the default labels
set(gca,'XTickLabel','')
% Get the Extent of each text object.  This
% loop is unavoidable.
for i = 1:length(t)
    ext(i,:) = get(t(i),'Extent');
end
% Determine the lowest point.  The X-label will be
% placed so that the top is aligned with this point.
LowYPoint = min(ext(:,2));
% Place the axis label at this point
XMidPoint = Xl(1)+abs(diff(Xl))/2;
tl = text(XMidPoint,LowYPoint,'', ...
    'VerticalAlignment','top', ...
    'HorizontalAlignment','center');
ylabel('correlation [-]','FontSize',16)
% h=legend('NRv5','L2P','NN','Location','northeast');
% set(h,'FontSize',14)
h=legend('DA-NN','DA-NN-CDF','DA-L2P-gCDF','OL','Location','northoutside',...
    'Orientation','horizontal');
set(h,'FontSize',16)

set(gcf,'paperunits','centimeters')
set(gcf,'paperposition',[1 1 40 16.5])
saveas(gcf,['/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_corr_da_RZ'],'epsc')
print('/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_corr_da_RZ','-dpng','-r300')

% plot DA bias in root zone

da_bias_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_bias_RZ_2.mat';
da_bias_data = load(da_bias_file);

da_bias_std_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_bias_std_RZ_2.mat';
da_bias_std_data = load(da_bias_std_file);

da_bias_vec = [da_bias_data.bias_mat(:,6)';...
    da_bias_data.bias_mat(:,7)';...
    da_bias_data.bias_mat(:,10)';...
    da_bias_data.bias_mat(:,2)'];
% da_bias_vec(:,[9 11]) =[];


da_bias_ll_vec = [da_bias_std_data.std_mat(:,6)';...
    da_bias_std_data.std_mat(:,7)';...
    da_bias_std_data.std_mat(:,10)';...
    da_bias_std_data.std_mat(:,2)'];
% da_bias_ll_vec(:,[9 11]) =[];
da_bias_ul_vec = da_bias_ll_vec;
% da_bias_ul_vec = da_bias_vec + da_bias_ul_vec;
% da_bias_ll_vec = da_bias_vec - da_bias_ll_vec;


da_bias_ll_vec = [da_bias_ll_vec nanmean(da_bias_ll_vec,2)];
da_bias_ul_vec = [da_bias_ul_vec nanmean(da_bias_ul_vec,2)];
da_bias_vec = [da_bias_vec nanmean(da_bias_vec,2)];

%da_bias_ll_vec = da_bias_vec - da_bias_ll_vec;

%da_bias_ul_vec = da_bias_ll_vec + da_bias_vec;

x = 1:size(da_corr_vec,2);

% station_names = {'Walnut Gulch 1';'Walnut Gulch 2';'Walnut Gulch 3';'Little Washita';'Fort Cobb1';'Fort Cobb2';...
%     'Little River';'St Jospehs';...
%     'South Fork';'Tonzi Ranch';'TxSON 1';'TxSON 2';'All'};

% station_names = {'WG 1   ';'WG 2   ';'WG 3   ';'LW   ';'FC 1   ';'FC 2   ';...
%     'LR   ';'SJ   ';...
%     'SF   ';'TR   ';'TX 1   ';'TX 2   ';'All   '};

C = linspecer(4);
x2 = 0:0.1:(size(da_corr_vec,2)+1);

figure

errorbar(x-0.3,da_bias_vec(1,:),da_bias_ll_vec(1,:),da_bias_ul_vec(1,:),'LineStyle','none','Color',C(2,:),...
    'Marker','s','MarkerFaceColor',C(2,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x-0.1,da_bias_vec(2,:),da_bias_ll_vec(2,:),da_bias_ul_vec(2,:),'LineStyle','none','Color',C(1,:),...
    'Marker','d','MarkerFaceColor',C(1,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.1,da_bias_vec(3,:),da_bias_ll_vec(3,:),da_bias_ul_vec(3,:),'LineStyle','none','Color',C(3,:),...
    'Marker','o','MarkerFaceColor',C(3,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.3,da_bias_vec(4,:),da_bias_ll_vec(4,:),da_bias_ul_vec(4,:),'LineStyle','none','Color',C(4,:),...
    'Marker','^','MarkerFaceColor',C(4,:),'LineWidth',2,'MarkerSize',9)
plot(x2,zeros(size(x2)),'-k')
grid on 
% Reduce the size of the axis so that all the labels fit in the figure.
pos = get(gca,'Position');
set(gca,'Position',[pos(1), .2, pos(3) .65])
% Add a title.
title('','FontSize',20)
% Set the X-Tick locations so that every other month is labeled.
Xt = 1:size(da_corr_vec,2);
Xl = [0 size(da_corr_vec,2)+1];
set(gca,'XTick',Xt,'XLim',Xl,'FontSize',16);
set(gca,'YLim',[0 0.2]);
ax = axis;    % Current axis limits
axis(axis);    % Set the axis limit modes (e.g. XLimMode) to manual
Yl = ax(3:4);  % Y-axis limits
% Place the text labels
t = text(Xt,Yl(1)*ones(1,length(Xt)),station_names);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
      'Rotation',45,'FontSize',16);
% Remove the default labels
set(gca,'XTickLabel','')
% Get the Extent of each text object.  This
% loop is unavoidable.
for i = 1:length(t)
    ext(i,:) = get(t(i),'Extent');
end
% Determine the lowest point.  The X-label will be
% placed so that the top is aligned with this point.
LowYPoint = min(ext(:,2));
% Place the axis label at this point
XMidPoint = Xl(1)+abs(diff(Xl))/2;
tl = text(XMidPoint,LowYPoint,'', ...
    'VerticalAlignment','top', ...
    'HorizontalAlignment','center');
ylabel('bias [m^3 m^{-3}]','FontSize',16)
h=legend('DA-NN','DA-NN-CDF','DA-L2P-gCDF','OL','Location','northoutside',...
    'Orientation','horizontal');
set(h,'FontSize',16)
set(gcf,'paperunits','centimeters')
set(gcf,'paperposition',[1 1 40 16.5])
saveas(gcf,['/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_bias_da_RZ'],'epsc')
print('/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_bias_da_RZ','-dpng','-r300')

% plot DA ubRMSE in root zone

da_ubrmse_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_ubrmse_RZ_2.mat';
da_ubrmse_data = load(da_ubrmse_file);

da_ubrmse_std_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_ubrmse_std_RZ_2.mat';
da_ubrmse_std_data = load(da_ubrmse_std_file);

da_ubrmse_vec = [da_ubrmse_data.ubrmse_mat(:,6)';...
    da_ubrmse_data.ubrmse_mat(:,7)';...
    da_ubrmse_data.ubrmse_mat(:,10)';...
    da_ubrmse_data.ubrmse_mat(:,2)'];
% da_ubrmse_vec(:,[9 11]) =[];


da_ubrmse_ll_vec = [da_ubrmse_std_data.ubrmse_std_mat(:,6)';...
    da_ubrmse_std_data.ubrmse_std_mat(:,7)';...
    da_ubrmse_std_data.ubrmse_std_mat(:,10)';...
    da_ubrmse_std_data.ubrmse_std_mat(:,2)'];
da_ubrmse_ll_vec = sqrt(da_ubrmse_ll_vec)./sqrt(size(da_ubrmse_ll_vec,2));
% da_ubrmse_ll_vec(:,[9 11]) =[];
da_ubrmse_ul_vec = da_ubrmse_ll_vec;
% da_ubrmse_ul_vec = da_ubrmse_vec + da_ubrmse_ul_vec;
% da_ubrmse_ll_vec = da_ubrmse_vec - da_ubrmse_ll_vec;


da_ubrmse_ll_vec = [da_ubrmse_ll_vec nanmean(da_ubrmse_ll_vec,2)];
da_ubrmse_ul_vec = [da_ubrmse_ul_vec nanmean(da_ubrmse_ul_vec,2)];
da_ubrmse_vec = [da_ubrmse_vec nanmean(da_ubrmse_vec,2)];

%da_ubrmse_ll_vec = da_ubrmse_vec - da_ubrmse_ll_vec;

%da_ubrmse_ul_vec = da_ubrmse_ll_vec + da_ubrmse_vec;

x = 1:size(da_corr_vec,2);

% station_names = {'Walnut Gulch 1';'Walnut Gulch 2';'Walnut Gulch 3';'Little Washita';'Fort Cobb1';'Fort Cobb2';...
%     'Little River';'St Jospehs';...
%     'South Fork';'Tonzi Ranch';'TxSON 1';'TxSON 2';'All'};

% station_names = {'WG 1   ';'WG 2   ';'WG 3   ';'LW   ';'FC 1   ';'FC 2   ';...
%     'LR   ';'SJ   ';...
%     'SF   ';'TR   ';'TX 1   ';'TX 2   ';'All   '};

C = linspecer(4);
x2 = 0:0.1:(size(da_corr_vec,2)+1);

figure

errorbar(x-0.3,da_ubrmse_vec(1,:),da_ubrmse_ll_vec(1,:),da_ubrmse_ul_vec(1,:),'LineStyle','none','Color',C(2,:),...
    'Marker','s','MarkerFaceColor',C(2,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x-0.1,da_ubrmse_vec(2,:),da_ubrmse_ll_vec(2,:),da_ubrmse_ul_vec(2,:),'LineStyle','none','Color',C(1,:),...
    'Marker','d','MarkerFaceColor',C(1,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.1,da_ubrmse_vec(3,:),da_ubrmse_ll_vec(3,:),da_ubrmse_ul_vec(3,:),'LineStyle','none','Color',C(3,:),...
    'Marker','o','MarkerFaceColor',C(3,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.3,da_ubrmse_vec(4,:),da_ubrmse_ll_vec(4,:),da_ubrmse_ul_vec(4,:),'LineStyle','none','Color',C(4,:),...
    'Marker','^','MarkerFaceColor',C(4,:),'LineWidth',2,'MarkerSize',9)
plot(x2,zeros(size(x2)),'-k')
grid on 
% Reduce the size of the axis so that all the labels fit in the figure.
pos = get(gca,'Position');
set(gca,'Position',[pos(1), .2, pos(3) .65])
% Add a title.
title('','FontSize',20)
% Set the X-Tick locations so that every other month is labeled.
Xt = 1:size(da_corr_vec,2);
Xl = [0 size(da_corr_vec,2)+1];
set(gca,'XTick',Xt,'XLim',Xl,'FontSize',16);
set(gca,'YLim',[0 0.1]);
ax = axis;    % Current axis limits
axis(axis);    % Set the axis limit modes (e.g. XLimMode) to manual
Yl = ax(3:4);  % Y-axis limits
% Place the text labels
t = text(Xt,Yl(1)*ones(1,length(Xt)),station_names);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
      'Rotation',45,'FontSize',16);
% Remove the default labels
set(gca,'XTickLabel','')
% Get the Extent of each text object.  This
% loop is unavoidable.
for i = 1:length(t)
    ext(i,:) = get(t(i),'Extent');
end
% Determine the lowest point.  The X-label will be
% placed so that the top is aligned with this point.
LowYPoint = min(ext(:,2));
% Place the axis label at this point
XMidPoint = Xl(1)+abs(diff(Xl))/2;
tl = text(XMidPoint,LowYPoint,'', ...
    'VerticalAlignment','top', ...
    'HorizontalAlignment','center');
ylabel('ubRMSE [m^3 m^{-3}]','FontSize',16)
h=legend('DA-NN','DA-NN-CDF','DA-L2P-gCDF','OL','Location','northoutside',...
    'Orientation','horizontal');
set(h,'FontSize',16)
set(gcf,'paperunits','centimeters')
set(gcf,'paperposition',[1 1 40 16.5])
saveas(gcf,['/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_ubrmse_da_RZ'],'epsc')
print('/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_ubrmse_da_RZ','-dpng','-r300')



% plot comparison with L4 data

da_corr_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_corr_RZ_2.mat';
da_corr_data = load(da_corr_file);

da_ci_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_corr_ci_RZ_2.mat';
da_ci_data = load(da_ci_file);

l4_corr_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_corr_RZ.mat';
l4_corr_data = load(l4_corr_file);

l4_ci_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_corr_ci_RZ.mat';
l4_ci_data = load(l4_ci_file);

nrv4_corr = l4_corr_data.corr_mat(:,3);
smap_l4_corr = l4_corr_data.corr_mat(:,2);

da_l4_corr_vec = [da_corr_data.corr_mat(:,6)';...
    da_corr_data.corr_mat(:,2)';...
    nrv4_corr';...
    smap_l4_corr'];

da_l4_ll_vec = [da_ci_data.ci_mat(:,10)';...
    da_ci_data.ci_mat(:,2)';...
    l4_ci_data.ci_mat(:,4)'
    l4_ci_data.ci_mat(:,2)'];

da_l4_ul_vec = [da_ci_data.ci_mat(:,11)';...
    da_ci_data.ci_mat(:,3)';...
    l4_ci_data.ci_mat(:,5)';...
    l4_ci_data.ci_mat(:,3)'];


da_l4_corr_vec = [da_l4_corr_vec nanmean(da_l4_corr_vec,2)];

% da_corr_vec = round(da_corr_vec,2);



da_l4_ll_vec = [da_l4_ll_vec nanmean(da_l4_ll_vec,2)];

da_l4_ll_vec = (da_l4_corr_vec - da_l4_ll_vec)*2;
%da_ll_vec = round(da_ll_vec,2);

da_l4_ul_vec = [da_l4_ul_vec nanmean(da_l4_ul_vec,2)];

da_l4_ul_vec = (da_l4_ul_vec - da_l4_corr_vec)*2;
%da_ul_vec = round(da_ul_vec,2);

% sf_index = [9 11];
% 
% da_l4_corr_vec(:,sf_index) = [];
% da_l4_ll_vec(:,sf_index) = [];
% da_l4_ul_vec(:,sf_index) = [];

x = 1:(size(da_l4_corr_vec,2));

C = linspecer(4);

figure

errorbar(x-0.3,da_l4_corr_vec(1,:),da_l4_ll_vec(1,:),da_l4_ul_vec(1,:),'LineStyle','none','Color',C(2,:),...
    'Marker','s','MarkerFaceColor',C(2,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x-0.1,da_l4_corr_vec(2,:),da_l4_ll_vec(2,:),da_l4_ul_vec(2,:),'LineStyle','none','Color',C(4,:),...
    'Marker','^','MarkerFaceColor',C(4,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.1,da_l4_corr_vec(3,:),da_l4_ll_vec(3,:),da_l4_ul_vec(3,:),'LineStyle','none','Color',C(3,:),...
    'Marker','o','MarkerFaceColor',C(3,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.3,da_l4_corr_vec(4,:),da_l4_ll_vec(4,:),da_l4_ul_vec(4,:),'LineStyle','none','Color',C(1,:),...
    'Marker','d','MarkerFaceColor',C(1,:),'LineWidth',2,'MarkerSize',9)
grid on
% Reduce the size of the axis so that all the labels fit in the figure.
pos = get(gca,'Position');
set(gca,'Position',[pos(1), .2, pos(3) .65])
% Add a title.
title('','FontSize',14)
% Set the X-Tick locations so that every other month is labeled.
Xt = 1:size(da_corr_vec,2);
Xl = [0 size(da_corr_vec,2)+1];
set(gca,'XTick',Xt,'XLim',Xl,'FontSize',16);
set(gca,'YLim',[0.4 1.1]);
ax = axis;    % Current axis limits
axis(axis);    % Set the axis limit modes (e.g. XLimMode) to manual
Yl = ax(3:4);  % Y-axis limits
% Place the text labels
t = text(Xt,Yl(1)*ones(1,length(Xt)),station_names);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
    'Rotation',45,'FontSize',16);
% Remove the default labels
set(gca,'XTickLabel','')
% Get the Extent of each text object.  This
% loop is unavoidable.
for i = 1:length(t)
    ext(i,:) = get(t(i),'Extent');
end
% Determine the lowest point.  The X-label will be
% placed so that the top is aligned with this point.
LowYPoint = min(ext(:,2));
% Place the axis label at this point
XMidPoint = Xl(1)+abs(diff(Xl))/2;
tl = text(XMidPoint,LowYPoint,'', ...
    'VerticalAlignment','top', ...
    'HorizontalAlignment','center');
ylabel('correlation [-]','FontSize',16)

h=legend('DA-NN','OL','OL-L4','DA-L4','Location','northoutside',...
    'Orientation','horizontal');
set(h,'FontSize',16)

set(gcf,'paperunits','centimeters')
set(gcf,'paperposition',[1 1 40 16.5])
saveas(gcf,['/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_corr_da_l4_RZ'],'epsc')
print('/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_corr_da_l4_RZ','-dpng','-r300')


% plot bias

da_bias_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_bias_RZ_2.mat';
da_bias_data = load(da_bias_file);

l4_bias_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_bias_RZ.mat';
l4_bias_data = load(l4_bias_file);

l4_bias_std_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_bias_std_RZ.mat';
l4_bias_std_data = load(l4_bias_std_file);

l4_bias_ci_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_bias_ci_RZ.mat';
l4_bias_ci_data = load(l4_bias_ci_file);

da_bias_vec = [da_bias_data.bias_mat(:,6)';...
    da_bias_data.bias_mat(:,2)';...
    abs(l4_bias_data.bias_mat(:,3))';...
    abs(l4_bias_data.bias_mat(:,2))'];
% da_bias_vec(:,[9 11]) =[];

da_bias_std_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_bias_std_RZ_2.mat';
da_bias_std_data = load(da_bias_std_file);

da_bias_ll_vec = [da_bias_std_data.std_mat(:,6)';...
    da_bias_std_data.std_mat(:,2)';...
    l4_bias_std_data.std_mat(:,3)';...
    l4_bias_std_data.std_mat(:,2)'];
% da_bias_ll_vec(:,[9 11]) =[];
da_bias_ul_vec = da_bias_ll_vec;

da_bias_vec = [da_bias_vec nanmean(da_bias_vec,2)];
da_bias_ll_vec = [da_bias_ll_vec nanmean(da_bias_ll_vec,2)];
da_bias_ul_vec = [da_bias_ul_vec nanmean(da_bias_ul_vec,2)];


x = 1:size(da_bias_vec,2);

% station_names = {'Walnut Gulch 1';'Walnut Gulch 2';'Walnut Gulch 3';'Little Washita';'Fort Cobb1';'Fort Cobb2';...
%     'Little River';'St Jospehs';...
%     'South Fork';'Tonzi Ranch';'TxSON 1';'TxSON 2';'All'};

% station_names = {'WG 1   ';'WG 2   ';'WG 3   ';'LW   ';'FC 1   ';'FC 2   ';...
%    'LR   ';'SJ   ';...
%     'SF   ';'TR   ';'TX 1   ';'TX 2   ';'All   '};

C = linspecer(4);
x2 = 0:0.1:(size(da_bias_vec,2)+1);


figure
errorbar(x-0.3,da_bias_vec(1,:),da_bias_ll_vec(1,:),da_bias_ul_vec(1,:),'LineStyle','none','Color',C(2,:),...
    'Marker','s','MarkerFaceColor',C(2,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x-0.1,da_bias_vec(2,:),da_bias_ll_vec(2,:),da_bias_ul_vec(2,:),'LineStyle','none','Color',C(4,:),...
    'Marker','^','MarkerFaceColor',C(4,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.1,da_bias_vec(3,:),da_bias_ll_vec(3,:),da_bias_ul_vec(3,:),'LineStyle','none','Color',C(3,:),...
    'Marker','o','MarkerFaceColor',C(3,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.3,da_bias_vec(4,:),da_bias_ll_vec(4,:),da_bias_ul_vec(4,:),'LineStyle','none','Color',C(1,:),...
    'Marker','d','MarkerFaceColor',C(1,:),'LineWidth',2,'MarkerSize',9)
plot(x2,zeros(size(x2)),'-k')
grid on 
% Reduce the size of the axis so that all the labels fit in the figure.
pos = get(gca,'Position');
set(gca,'Position',[pos(1), .2, pos(3) .65])
% Add a title.
title('','FontSize',14)
% Set the X-Tick locations so that every other month is labeled.
Xt = 1:size(da_bias_vec,2);
Xl = [0 size(da_bias_vec,2)+1];
set(gca,'XTick',Xt,'XLim',Xl,'FontSize',16);
set(gca,'YLim',[0 0.2]);
ax = axis;    % Current axis limits
axis(axis);    % Set the axis limit modes (e.g. XLimMode) to manual
Yl = ax(3:4);  % Y-axis limits
% Place the text labels
t = text(Xt,Yl(1)*ones(1,length(Xt)),station_names);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
      'Rotation',45,'FontSize',16);
% Remove the default labels
set(gca,'XTickLabel','')
% Get the Extent of each text object.  This
% loop is unavoidable.
for i = 1:length(t)
  ext(i,:) = get(t(i),'Extent');
end
% Determine the lowest point.  The X-label will be
% placed so that the top is aligned with this point.
LowYPoint = min(ext(:,2));
% Place the axis label at this point
XMidPoint = Xl(1)+abs(diff(Xl))/2;
tl = text(XMidPoint,LowYPoint,'', ...
          'VerticalAlignment','top', ...
          'HorizontalAlignment','center');
      ylabel('bias [m^3 m^{-3}]','FontSize',16)
h=legend('DA-NN','OL','OL-L4','DA-L4','Location','northoutside',...
    'Orientation','horizontal');
set(h,'FontSize',16)
set(gcf,'paperunits','centimeters')
set(gcf,'paperposition',[1 1 40 16.5])
saveas(gcf,['/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_bias_da_l4_RZ'],'epsc')
print('/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_bias_da_l4_RZ','-dpng','-r300')


% plot L4 ubRMSE in rootzone

da_ubrmse_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_ubrmse_RZ_2.mat';
da_ubrmse_data = load(da_ubrmse_file);

l4_ubrmse_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_ubrmse_RZ.mat';
l4_ubrmse_data = load(l4_ubrmse_file);

l4_ubrmse_std_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_bias_ubrmse_std_RZ.mat';
l4_ubrmse_std_data = load(l4_ubrmse_std_file);

% l4_ubrmse_ci_file = '/home/jkolassa/Projects/SMAP_NN_SM/l4_da_coresite_ubrmse_ci_RZ.mat';
% l4_ubrmse_ci_data = load(l4_ubrmse_ci_file);

da_ubrmse_vec = [da_ubrmse_data.ubrmse_mat(:,6)';...
    da_ubrmse_data.ubrmse_mat(:,2)';...
    l4_ubrmse_data.ubrmse_mat(:,3)';...
    l4_ubrmse_data.ubrmse_mat(:,2)'];
% da_ubrmse_vec(:,[9 11]) =[];

da_ubrmse_std_file = '/home/jkolassa/Projects/SMAP_NN_SM/smap_da_coresite_ubrmse_std.mat';
da_ubrmse_std_data = load(da_ubrmse_std_file);

da_ubrmse_ll_vec = [da_ubrmse_std_data.ubrmse_std_mat(:,6)';...
    da_ubrmse_std_data.ubrmse_std_mat(:,2)';...
    l4_ubrmse_std_data.ubrmse_std_mat(:,3)';...
    l4_ubrmse_std_data.ubrmse_std_mat(:,2)'];
da_ubrmse_ll_vec = sqrt(da_ubrmse_ll_vec)./sqrt(size(da_ubrmse_ll_vec,2));
% da_ubrmse_ll_vec(:,[9 11]) =[];
da_ubrmse_ul_vec = da_ubrmse_ll_vec;

da_ubrmse_vec = [da_ubrmse_vec nanmean(da_ubrmse_vec,2)];
da_ubrmse_ll_vec = [da_ubrmse_ll_vec nanmean(da_ubrmse_ll_vec,2)];
da_ubrmse_ul_vec = [da_ubrmse_ul_vec nanmean(da_ubrmse_ul_vec,2)];


x = 1:size(da_ubrmse_vec,2);

% station_names = {'Walnut Gulch 1';'Walnut Gulch 2';'Walnut Gulch 3';'Little Washita';'Fort Cobb1';'Fort Cobb2';...
%     'Little River';'St Jospehs';...
%     'South Fork';'Tonzi Ranch';'TxSON 1';'TxSON 2';'All'};

% station_names = {'WG 1   ';'WG 2   ';'WG 3   ';'LW   ';'FC 1   ';'FC 2   ';...
%    'LR   ';'SJ   ';...
%     'SF   ';'TR   ';'TX 1   ';'TX 2   ';'All   '};

C = linspecer(4);
x2 = 0:0.1:(size(da_ubrmse_vec,2)+1);


figure
errorbar(x-0.3,da_ubrmse_vec(1,:),da_ubrmse_ll_vec(1,:),da_ubrmse_ul_vec(1,:),'LineStyle','none','Color',C(2,:),...
    'Marker','s','MarkerFaceColor',C(2,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x-0.1,da_ubrmse_vec(2,:),da_ubrmse_ll_vec(2,:),da_ubrmse_ul_vec(2,:),'LineStyle','none','Color',C(4,:),...
    'Marker','^','MarkerFaceColor',C(4,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.1,da_ubrmse_vec(3,:),da_ubrmse_ll_vec(3,:),da_ubrmse_ul_vec(3,:),'LineStyle','none','Color',C(3,:),...
    'Marker','o','MarkerFaceColor',C(3,:),'LineWidth',2,'MarkerSize',9)
hold on
errorbar(x+0.3,da_ubrmse_vec(4,:),da_ubrmse_ll_vec(4,:),da_ubrmse_ul_vec(4,:),'LineStyle','none','Color',C(1,:),...
    'Marker','d','MarkerFaceColor',C(1,:),'LineWidth',2,'MarkerSize',9)
plot(x2,zeros(size(x2)),'-k')
grid on 
% Reduce the size of the axis so that all the labels fit in the figure.
pos = get(gca,'Position');
set(gca,'Position',[pos(1), .2, pos(3) .65])
% Add a title.
title('','FontSize',14)
% Set the X-Tick locations so that every other month is labeled.
Xt = 1:size(da_ubrmse_vec,2);
Xl = [0 size(da_ubrmse_vec,2)+1];
set(gca,'XTick',Xt,'XLim',Xl,'FontSize',16);
set(gca,'YLim',[0 0.1]);
ax = axis;    % Current axis limits
axis(axis);    % Set the axis limit modes (e.g. XLimMode) to manual
Yl = ax(3:4);  % Y-axis limits
% Place the text labels
t = text(Xt,Yl(1)*ones(1,length(Xt)),station_names);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
      'Rotation',45,'FontSize',16);
% Remove the default labels
set(gca,'XTickLabel','')
% Get the Extent of each text object.  This
% loop is unavoidable.
for i = 1:length(t)
  ext(i,:) = get(t(i),'Extent');
end
% Determine the lowest point.  The X-label will be
% placed so that the top is aligned with this point.
LowYPoint = min(ext(:,2));
% Place the axis label at this point
XMidPoint = Xl(1)+abs(diff(Xl))/2;
tl = text(XMidPoint,LowYPoint,'', ...
          'VerticalAlignment','top', ...
          'HorizontalAlignment','center');
      ylabel('ubRMSE [m^3 m^{-3}]','FontSize',16)
h=legend('DA-NN','OL','OL-L4','DA-L4','Location','northoutside',...
    'Orientation','horizontal');
set(h,'FontSize',16)
set(gcf,'paperunits','centimeters')
set(gcf,'paperposition',[1 1 40 16.5])
saveas(gcf,['/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_ubrmse_da_l4_RZ'],'epsc')
print('/home/jkolassa/Projects/SMAP_NN_DA/plots/coresite_ubrmse_da_l4_RZ','-dpng','-r300')

