% Make spatial and box plots of the reconstruction skill

%efln='spatial_skill_cesm_lme010_r12000_p998_state_t2qjozn_avg_AprMar_prxydtst_5_prxtp_tca_2604_swtchbld100_21-Dec-2017_16:05:26.mat'; seas='A2M';
%efln='spatial_skill_cesm_lme010_r12000_p998_state_t2qjozn_avg_DecFeb_prxydtst_5_prxtp_tca_2598_swtchbld100_21-Dec-2017_16:19:04.mat'; seas='DJF';
%efln='spatial_skill_cesm_lme010_r12000_p998_state_t2qjozn_avg_JunAug_prxydtst_5_prxtp_tca_2588_swtchbld100_21-Dec-2017_16:30:40.mat'; seas='JJA';

efln='spatial_skill_cesm_lme010_r12000_p998_state_t2qjozn_avg_AprMar_prxydtst_5_prxtp_tca_2896_swtchbld100_05-Jan-2018_14:33:07.mat'; seas='A2M';
%efln='spatial_skill_cesm_lme010_r12000_p998_state_t2qjozn_avg_DecFeb_prxydtst_5_prxtp_tca_2896_swtchbld100_05-Jan-2018_14:40:23.mat'; seas='DJF';
%efln='spatial_skill_cesm_lme010_r12000_p998_state_t2qjozn_avg_JunAug_prxydtst_5_prxtp_tca_2896_swtchbld100_05-Jan-2018_14:49:45.mat'; seas='JJA';

load(['./output-recon/' efln],'sptlskll','lat','lon','analyrs','fln','proxy')
load('./colormaps/distinct_colors_20.mat')
load('./colormaps/WhiteYellowOrangeRed.mat')

sf={'pdsi','spei','t2m'};
sn={'rp','ce','crps','crpss'};


%============================
% Box plot summaries
%============================

varS=NaN(length(lat)*length(lon),length(sf),length(sn));
for i=1:length(sf)
   for j=1:length(sn)
      % Extract skill field
      varS(:,i,j)=eval(['sptlskll.' sf{i} '.' sn{j}]);
   end
end


% Just plot r and CRPSS
% PDSI r; SPEI r; T2m r; PDSI CRPSS; SPEI CRPSS; T2m CRPSS
varSplt=reshape(varS(:,:,[1 4]),length(lat)*length(lon),length(sf)*2);

%lbls={'PDSI','SPEI','T2m','PDSI','SPEI','T2m'};
%grp={1,2,3,1,2,3};
%cgrp=[clrs.blue;clrs.orange;clrs.purple];

% Compute spatially correlation
disp(seas)
disp(['corr(r,CRPSS) SPEI = ' num2str(nancorr(varSplt(:,2),varSplt(:,5)))])
disp(['corr(r,CRPSS) T2m = ' num2str(nancorr(varSplt(:,3),varSplt(:,6)))])











