clear all
close all
%% Import data from spreadsheet
% Script for importing data from the following spreadsheet:
%
%    Workbook: /Volumes/Data2/TaraEuropa/Partner_data/Merge_data_discrete_inline/Simplified_LOV_discrete_data.xlsx
%    Worksheet: Sheet1
%
% Auto-generated by MATLAB on 19-Feb-2024 15:41:39

%% Set up the Import Options and import the data
opts = spreadsheetImportOptions("NumVariables", 8);

% Specify sheet and range
opts.Sheet = "Sheet1";
opts.DataRange = "A2:H55";

% Specify column names and types
opts.VariableNames = ["station", "SPMAverageg", "SPMSTD", "AveragePIF", "AveragePOF", "STDEVPIFPOF", "MeanTurbidity", "TurbiditySTD"];
opts.VariableTypes = ["double", "double", "double", "double", "double", "double", "double", "double"];

% Import the data
A= readtable("/Volumes/Data2/TaraEuropa/Partner_data/Merge_data_discrete_inline/Simplified_LOV_discrete_data.xlsx", opts, "UseExcel", false);


%% Clear temporary variables
clear opts

cp_LOV_med=NaN*ones(1,length(A.station));
cp_LOV_95=NaN*ones(1,length(A.station));
cp_LOV_5=NaN*ones(1,length(A.station));
cp_gamma_LOV_med=NaN*ones(1,length(A.station));
cp_gamma_LOV_95=NaN*ones(1,length(A.station));
cp_gamma_LOV_5=NaN*ones(1,length(A.station));
bb_LOV_med=NaN*ones(1,length(A.station));
bb_LOV_95=NaN*ones(1,length(A.station));
bb_LOV_5=NaN*ones(1,length(A.station));
bb_gamma_LOV_med=NaN*ones(1,length(A.station));
bb_gamma_LOV_95=NaN*ones(1,length(A.station));
bb_gamma_LOV_5=NaN*ones(1,length(A.station));

for i=2:length(A.station)
    filename=['ST_IOP_',num2str(A.station(i)),'.mat'];
    load(filename)
    if isempty(ST.cp_gamma_med)==0
        cp_LOV_med(i)=interp1(ST.cp_lambda,ST.cp_med,650,'linear');
        cp_LOV_95(i)=interp1(ST.cp_lambda,ST.cp_95,650,'linear');
        cp_LOV_5(i)=interp1(ST.cp_lambda,ST.cp_5,650,'linear');
        cp_gamma_LOV_med(i)=ST.cp_gamma_med;
        cp_gamma_LOV_95(i)=ST.cp_gamma_95;
        cp_gamma_LOV_5(i)=ST.cp_gamma_5;   
    end
    if isempty(ST.bb_gamma_med)==0
        bb_LOV_med(i)=interp1(ST.bb_lambda,ST.bb_med,650,'linear');
        bb_LOV_95(i)=interp1(ST.bb_lambda,ST.bb_95,650,'linear');
        bb_LOV_5(i)=interp1(ST.bb_lambda,ST.bb_5,650,'linear');
        bb_gamma_LOV_med(i)=ST.bb_gamma_med;
        bb_gamma_LOV_95(i)=ST.bb_gamma_95;
        bb_gamma_LOV_5(i)=ST.bb_gamma_5;
    end
    clear ST cp_med cp_95 cp_5 cp_gamma_med cp_gamma_95 cp_gamma_5 bb_med bb_95 bb_5 b_gamma_med b_gamma_95 b_gamma_5
end

subplot(2,2,1)
x=A.SPMAverageg;
y=cp_LOV_med;
yneg = cp_LOV_95-cp_LOV_med;
ypos = cp_LOV_med-cp_LOV_5;
xneg = A.SPMSTD;
xpos = A.SPMSTD;
errorbar(x,y,yneg,ypos,xneg,xpos,'o')
set(gca, 'YScale', 'log')
set(gca, 'XScale', 'log')
xlabel('SPM')
ylabel('c_p(650)')

subplot(2,2,2)
x=A.SPMAverageg;
y=bb_LOV_med;
yneg = bb_LOV_95-bb_LOV_med;
ypos = bb_LOV_med-bb_LOV_5;
xneg = A.SPMSTD;
xpos = A.SPMSTD;
errorbar(x,y,yneg,ypos,xneg,xpos,'o')
set(gca, 'YScale', 'log')
set(gca, 'XScale', 'log')
xlabel('SPM')
ylabel('bb_p(650)')

subplot(2,2,3)
x=A.MeanTurbidity;
y=cp_LOV_med;
yneg = cp_LOV_95-cp_LOV_med;
ypos = cp_LOV_med-cp_LOV_5;
xneg = A.TurbiditySTD;
xpos = A.TurbiditySTD;
errorbar(x,y,yneg,ypos,xneg,xpos,'o')
set(gca, 'YScale', 'log')
set(gca, 'XScale', 'log')
xlabel('Turbidity')
ylabel('c_p(650)')

subplot(2,2,4)
x=A.MeanTurbidity;
y=bb_LOV_med;
yneg = bb_LOV_95-bb_LOV_med;
ypos = bb_LOV_med-bb_LOV_5;
xneg = A.TurbiditySTD;
xpos = A.TurbiditySTD;
errorbar(x,y,yneg,ypos,xneg,xpos,'o')
set(gca, 'YScale', 'log')
set(gca, 'XScale', 'log')
xlabel('Turbidity')
ylabel('bb_p(650)')

figure
subplot(1,2,1)
x=A.SPMAverageg;
y=cp_LOV_med;
hist(y./x')
title('cp(650)/SPM')

subplot(1,2,2)
x=A.SPMAverageg;
y=bb_LOV_med;
hist(y./x')
title('bbp(650)/SPM')
    