% b12_compare_v3_mc_merged_versions.m
% plot comparisons between V2 8192 fluxes and V3 merged fluxes at MetCity
% execute each section manually to see comparison plots

%% compare CO2/CH4/O3/HS/stress fluxes
load('/Users/byronb/Raw_Data_Files.noindex/MOSAIC_2019/_processed/metcity_flux_v3/flux_merged/wins_met_gases_lags_flux_merged_v3.mat','mc_flx');
mc_flx3 = mc_flx; clear mc_flx;
load('/Users/byronb/Raw_Data_Files.noindex/MOSAIC_2019/_processed/metcity_flux_v2/flux_8192/wins_met_gases_lags_flux_8192_v2.mat','mc_flx');
mc_flx1 = mc_flx; clear mc_flx;
dt = datetime(mc_flx1.datenum,'convertfrom','datenum');

comps = {'wu_cov','wu_csp','wv_cov','wv_csp','wTs_cov','wTs_csp','hsens_cov','hsens_csp','Ts_noise','wco2_cov_ppm','wco2_cov_corr_ppm',...
         'wco2_csp_corr_ppm','wco2_csp_corr_mM','DLwco2_ppm','DLwco2_mM','uco2_mM','vco2_mM','Aco2','wch4_cov_ppb','wch4_cov_corr_ppb',...
         'wch4_csp_corr_ppb','wch4_csp_corr_uM','DLwch4_ppb','DLwch4_uM','uch4_uM','vch4_uM','Ach4','std_wco2_mM','std_wch4_uM',...
         'std_wT','std_hs','std_w','std_u','std_v'};
vars1 = mc_flx1.Properties.VariableNames;
vars2 = mc_flx3.Properties.VariableNames;

aa = []; bb = [];
for ii = 1:length(comps)
    aa(ii) = find(strcmp(vars1,comps(ii)));
    bb(ii) = find(strcmp(vars2,comps(ii)));
end

% basic wind filter for turbulence parameters: wdir outside of +/- 10° of
% bearing to ship and when U10 > 4 m/s
test = abs(mc_flx1.ship_bearing - mc_flx1.wdir_vec_mean_10m);
cc = test>10 & test<350 & mc_flx1.wspd_vec_mean_10m>=4;

for ii=1:length(comps)
    figure('position',[500,500,800,800]); plot(mc_flx1{~cc,aa(ii)},mc_flx3{~cc,bb(ii)},'.','markersize',8); grid on; grid minor; hold on;
    plot(mc_flx1{cc,aa(ii)},mc_flx3{cc,bb(ii)},'r.','markersize',8); hold off;
    vname = strrep(mc_flx1.Properties.VariableNames{aa(ii)},'_','-');
    ylabel([vname,' V3 merged']);
    xlabel([vname,' V2 8192']);
end

%% compare filtered vs unfiltered CO2/CH4 fluxes from merged raw data
% 
% load('/Users/byronb/Raw_Data_Files.noindex/MOSAIC_2019/_processed/metcity_flux_v3/flux_merged_lp/wins_met_gases_lags_flux_merged_v3_lp.mat','mc_flx');
% mc_flx3 = mc_flx; clear mc_flx;
% vars3 = mc_flx3.Properties.VariableNames;
% 
% aa = []; bb = [];
% for ii = 1:length(comps)
%     aa(ii) = find(strcmp(vars2,comps(ii)));
%     bb(ii) = find(strcmp(vars3,comps(ii)));
% end
% 
% for ii=1:length(comps)
%     figure('position',[500,500,800,800]); plot(mc_flx2{~cc,aa(ii)},mc_flx3{~cc,bb(ii)},'b.','markersize',8); grid on; grid minor; hold on;
%     plot(mc_flx2{cc,aa(ii)},mc_flx3{cc,bb(ii)},'r.','markersize',8); hold off;
%     vname = strrep(mc_flx3.Properties.VariableNames{aa(ii)},'_','-');
%     ylabel([vname,' merged low-pass']);
%     xlabel([vname,' merged']);
% end
