% analyze_Jul01_to_Jul10.m
% look at flux, flux footprint and met variables for this period

xvals = [datetime(2020,7,1),datetime(2020,7,10)];

open('/Users/byronb/Raw_Data_Files.noindex/MOSAIC_2019/_processed/metcity_flux_v3/flux_merged/plots/daily_means/fch4_daily_metcity.fig');
xlim(xvals); ylim([-5,15]);
open('/Users/byronb/Raw_Data_Files.noindex/MOSAIC_2019/_processed/metcity_flux_v3/flux_merged/plots/daily_means/fco2_daily_metcity.fig');
xlim(xvals); ylim([-2,2]);
open('/Users/byronb/Raw_Data_Files.noindex/MOSAIC_2019/_processed/metcity_flux_v3/flux_merged/plots/daily_means/hs_daily_metcity.fig');
xlim(xvals); ylim([-4,1]);
open('/Users/byronb/Raw_Data_Files.noindex/MOSAIC_2019/_processed/Central_Observatory_Winds_V2/plots/bow_tower_winds.fig');
open('/Users/byronb/Raw_Data_Files.noindex/MOSAIC_2019/_processed/ship_flux_V3/flux_merged/plots/hourly_analysis/co2Flux_ship.fig');

load('/Users/byronb/Raw_Data_Files.noindex/MOSAIC_2019/_processed/ship_flux_V3/flux_merged/MOSAiC_ship_flux_co2_ch4_o3_dms_hr.mat');
dt_hr = datetime(flx_hr.datenum,'convertfrom','datenum');
figure; plot(dt_hr,flx_hr.Ta_hr,'.','markersize',10); grid on; grid minor; ylabel('Tair, °C');
xlim(xvals);
figure; plot(dt_hr,flx_hr.Pmb_hr,'.','markersize',10); grid on; grid minor; ylabel('Pmb');
xlim(xvals);

% summary plot of all fluxes
load('/Users/byronb/Raw_Data_Files.noindex/MOSAIC_2019/_processed/ship_flux_V3/flux_merged/MOSAiC_ship_flux_co2_ch4_o3_dms_daily.mat');
load('/Users/byronb/Raw_Data_Files.noindex/MOSAIC_2019/_processed/metcity_flux_v3/flux_merged/MOSAiC_metcity_flux_co2_ch4_daily.mat');

dt_dd = datetime(flx_dd.datenum,'ConvertFrom','datenum');
dt_range = xvals(1):days(1):xvals(2);
[~,ia,~] = intersect(dt_dd,dt_range);
xlims = [datetime(2020,7,1),datetime(2020,7,11)];
figure('Position',[300,300,600,1000]);
subtightplot(3,1,1,[0.05,0.05],[0.03,0.03],[0.08,0.08]);
    plot(xlims,[0,0],'k-','LineWidth',1); hold on;
    h1 = errorbar(dt_range + hours(12),flx_dd.Fwco2_csp_mM_dd(ia),...
             flx_dd.SEwco2_csp_mM_dd(ia),'o','LineWidth',2,...
             'MarkerSize',10);
    h2 = errorbar(dt_range + hours(12),mc_flx_dd.Fwco2_csp_mM_dd(ia),...
             mc_flx_dd.SEwco2_csp_mM_dd(ia),'x','LineWidth',2,...
             'MarkerSize',10);
    ax = gca; ax.FontSize = 12;
    grid on; grid minor; ylabel('F_{co2} mM/m^2/d \pm SEM'); xlim(xlims);
    legend([h1,h2],'Ship','MetCity','Location','northwest',...
            'FontSize',12);
    title('Jul 1 to 10, 2020 Turbulent Fluxes','FontSize',18);
subtightplot(3,1,2,[0.05,0.05],[0.03,0.03],[0.08,0.08]);
    plot(xlims,[0,0],'k-','LineWidth',1); hold on;
    h1 = errorbar(dt_range + hours(12),flx_dd.Fwch4_csp_uM_dd(ia),...
             flx_dd.SEwch4_csp_uM_dd(ia),'o','LineWidth',2,...
             'MarkerSize',10);
    h2 = errorbar(dt_range + hours(12),mc_flx_dd.Fwch4_csp_uM_dd(ia),...
             mc_flx_dd.SEwch4_csp_uM_dd(ia),'x','LineWidth',2,...
             'MarkerSize',10);
    ax = gca; ax.FontSize = 12;
    grid on; grid minor; ylabel('F_{ch4} \muM/m^2/d \pm SEM'); xlim(xlims);
subtightplot(3,1,3,[0.05,0.05],[0.03,0.03],[0.08,0.08]);
    plot(xlims,[0,0],'k-','LineWidth',1); hold on;
    h1 = errorbar(dt_range + hours(12),flx_dd.hs_csp_dd(ia),...
             flx_dd.SEhs_csp_dd(ia),'o','LineWidth',2,...
             'MarkerSize',10);
    h2 = errorbar(dt_range + hours(12),mc_flx_dd.hs_csp_dd(ia),...
             mc_flx_dd.SEhs_csp_dd(ia),'x','LineWidth',2,...
             'MarkerSize',10);
    ax = gca; ax.FontSize = 12;
    grid on; grid minor; ylabel('Sens.Heat W/m^2 \pm SEM'); xlim(xlims);








