BB9spectra

From Pnb
Jump to navigation Jump to search
function BB9spectra()
%plot BB9 spectra 5m binned with depth





pathname = pwd;
dhnumber = pathname(end-2:end);
%=====LISST DATA SET MODULE========
data_lst = load('LISST_indexarr');
lst_depth = .01*data_lst(:,37);
lst_date1 = num2str(data_lst(:,39));
lst_date2 = num2str(data_lst(:,40));
lst_day = str2num(lst_date1(:,1:3));
lst_hrs = str2num(lst_date1(:,4:5));

%when lisst minutes reset every 60 sec
for ml =1:length(lst_date2)
    hld = lst_date2(ml,1:2);
    char(hld);
    hld = str2num(hld);
    if isempty(hld)
        lst_min(ml) =0;
        continue
    end
    lst_min(ml) = hld;%str2num(lst_date2(ml,1:2))
    
end
lst_min = (lst_min)';
lst_sec = str2num(lst_date2(:,3:4));

JD = lst_hrs.*3600 + lst_min.*60 + lst_sec; %this is in seconds
%start from zero
JD = JD-JD(1); %lisst time in seconds starting from zero
%======END LISST MODULE========


%=====BB9 MODULE========
% since BB9 time is more accurate, use it for merging
ECOname = strcat('archive_23_ECO.',dhnumber);
%[BB9_data,BB9_HDR] = hdrload('archive_23_ECO.040');
[BB9_data,BB9_HDR] = hdrload(ECOname);
%BB9_data = load(ECOname);
BB9_time  = BB9_data(:,1); %(in ms) si
BB9_time = BB9_time - BB9_time(1);
BB9_time = BB9_time./1000;


%====CTD MODULE=======
CTDname = strcat('archive_22_SBE25CTD.',dhnumber)

[CTD_dat,CTD_hdr] = hdrload(CTDname);

%[CTD_dat,CTD_hdr] = hdrload('archive_22_SBE25CTD.040');
ctd_time = CTD_dat(:,1); %ms
ctd_time = ctd_time./1000; %seconds
%ctd_depth = CTD_dat(:,2);
%ctd_temp = CTD_dat(:,3);
%ctd_cond = CTD_dat(:,4);
%ctd_sal = CTD_dat(:,5);

%====ACS MODULE=======
ACSname = strcat('archive_21_ACS.',dhnumber)
[ACS_dat,ACS_hdr] = hdrload(ACSname);
%ACS_D = interp1(nmini30s_T,nmini30s_D,ctd_time);


%=====MERGING MODULE=====

BB9_new = interp1(BB9_time,BB9_data,ctd_time);
sample =[];
if issorted(data_lst(:,1)) == 0
    issorted(JD)
    issorted(ctd_time)
    issorted(data_lst(:,1))
    issorted(data_lst(:,37))
    
    %at this point CTD and BB9 data is parsed.  BB data is matched to CTD time
    
    %======= FILTERING NAN IF TIME RECORDS GO OVER =====
    nn= isnan(BB9_new);
    non= find(nn(:,1) ==1);
    CTD_dat(non,:) = [];
    BB9_new(non,:) = [];
    %=====
    ctd_time = CTD_dat(:,1); %ms
    ctd_time = ctd_time./1000; %seconds
    ctd_depth = CTD_dat(:,2);
    ctd_temp = CTD_dat(:,3);
    ctd_cond = CTD_dat(:,4);
    ctd_sal = CTD_dat(:,5);
    
    CTD30s_D = ctd_depth;%interp1(nmini30s_T,nmini30s_D,ctd_time); %gets a depth dimention relative to 8Hz ctd time (same dimension as ctd data)
    ACS_D = interp1(ctd_time,ctd_depth,.001*ACS_dat(:,1));
    BB9_D = interp1(ctd_time,ctd_depth,BB9_time);
    
    
    CTD_dat(:,2) = CTD30s_D; %repair CTD depth column in data
end


%===============================
%====BB9 spectra plotting=======



sepparation_index =  find(BB9_D == max(BB9_D)); %where to split cast
sep_ind = sepparation_index(1);
for i = 1:size(BB9_new,2)
BB9_downcast(:,i) = smooth(BB9_new(1:sep_ind,i));
end
BB9_D = smooth(BB9_D(1:sep_ind,:));

%Tref = 22.6 %(from factory cal)
%header_b = ['Time(ms)  c400.9	c404.1	c407.3	c410.3	c413.7	c417.1	c420.5	c424.2	c427.9	c431.7	c435.2	c438.6	c442.5	c446.3	c450.0	c454.3	c458.1	c462.2	c466.2	c470.5	c474.5	c478.5	c482.7	c486.7	c490.6	c494.6	c498.6	c502.4	c506.6	c510.7	c514.7	c518.9	c522.7	c526.8	c530.8	c534.6	c538.4	c542.3	c546.1	c549.9	c553.6	c557.4	c561.0	c564.7	c568.1	c571.3	c574.7	c577.8	c581.2	c584.6	c588.3	c591.8	c595.2	c598.9	c602.6	c606.3	c610.2	c613.9	c617.7	c621.5	c625.2	c629.2	c632.9	c636.8	c640.7	c644.3	c648.4	c652.4	c656.0	c660.0	c663.9	c667.8	c671.3	c674.9	c679.1	c682.7	c686.3	c689.7	c693.4	c697.0	c700.5	c703.9	c707.1	c710.7	c714.2	c717.4	c720.8	c724.1	c727.5	c730.5	c734.2	a402.6	a405.9	a408.9	a411.9	a415.3	a418.7	a422.4	a426.0	a429.5	a433.3	a436.8	a440.3	a444.0	a447.9	a452.0	a455.9	a459.9	a463.8	a468.2	a472.2	a476.4	a480.4	a484.5	a488.5	a492.3	a496.1	a500.1	a504.1	a508.3	a512.5	a516.5	a520.3	a524.4	a528.2	a532.3	a536.1	a539.7	a543.9	a547.6	a551.4	a555.2	a558.7	a562.8	a566.2	a569.0	a572.2	a575.6	a579.0	a582.4	a585.8	a589.3	a592.7	a596.4	a599.9	a603.6	a607.3	a611.3	a615.0	a618.9	a622.7	a626.4	a630.2	a634.0	a638.0	a641.8	a645.6	a649.6	a653.5	a657.5	a661.1	a665.0	a668.8	a672.6	a676.3	a680.1	a683.8	a687.1	a690.8	a694.7	a698.1	a701.5	a705.0	a708.4	a711.8	a715.2	a718.5	a721.7	a725.1	a728.4	a731.8	a735.0	iTemp(C)	Conduct	Depth	XTemp	Salinity'];
header_b = ['Time(ms)	Beta(412)	BetaP(412)	bbP(412)	bb(412)	Beta(440)	BetaP(440)	bbP(440)	bb(440)	Beta(488)	BetaP(488)	bbP(488)	bb(488)	Beta(510)	BetaP(510)	bbP(510)	bb(510)	Beta(532)	BetaP(532)	bbP(532)	bb(532)	Beta(595)	BetaP(595)	bbP(595)	bb(595)	Beta(660)	BetaP(660)	bbP(660)	bb(660)	Beta(676)	BetaP(676)	bbP(676)	bb(676)	Beta(715)	BetaP(715)	bbP(715)	bb(715)'];
BBwvln = [412,440,488,510,532,595,660,676,715]
legendvals = regexp(header_b,'\s','split')
channels = legendvals(4:4:end-1); %generating a list of ACS channels for TScal



bwindow =5;
disp('doing BB9 binning')
[binned,stats,stdev,medi]=databinner(BB9_D(1:sep_ind),BB9_downcast,bwindow)
%[binned,stats,stdev,medi]=databinner(ACS_D(1:sep_ind),ACS_downcast,bwindow)
for i=1:length(legendvals)
    header_std{i} = char([' std',legendvals{i}])';
end
%header_std = char(header_std)';



m35_index = find(abs(BB9_D(1:sep_ind) -35) == min(abs(BB9_D(1:sep_ind) - 35)));
m50_index = find(abs(BB9_D(1:sep_ind) -50) == min(abs(BB9_D(1:sep_ind) - 50)));
m80_index = find(abs(BB9_D(1:sep_ind) -80) == min(abs(BB9_D(1:sep_ind) - 80)));
m95_index = find(abs(BB9_D(1:sep_ind) -95) == min(abs(BB9_D(1:sep_ind) - 95)));

figure
plot(BBwvln,BB9_downcast(m35_index(1),4:4:end-1),BBwvln,BB9_downcast(m50_index(1),4:4:end-1),BBwvln,BB9_downcast(m80_index(1),4:4:end-1),BBwvln,BB9_downcast(m95_index(1),4:4:end-1))%,400:3.8202:740,avg_spec_001May2012unfilb(:,2:91),    400:3.8202:740,avg_spec_001May2012filc(:,2:91),400:3.8202:740,avg_spec_001May2012unfilc(:,2:91))
title(['BB9 279 spectra ',ECOname(end-7:end)])
xlabel('400-740nm');
ylabel('bbp data 1/m')
legend('35m','50m','80m','95m')%,'May2012-unfilter','May2012-newfilter','May2012-newunfilter','May2012-newfilter runII','May2012-newunfilter runII')
saveas(gcf, ['BB9_bbp',ECOname(end-7:end)], 'png')


figure
plot(BBwvln,BB9_downcast(m35_index(1),5:4:end),BBwvln,BB9_downcast(m50_index(1),5:4:end),BBwvln,BB9_downcast(m80_index(1),5:4:end),BBwvln,BB9_downcast(m95_index(1),5:4:end))%,400:3.8202:740,avg_spec_001May2012unfilb(:,2:91),    400:3.8202:740,avg_spec_001May2012filc(:,2:91),400:3.8202:740,avg_spec_001May2012unfilc(:,2:91))
title(['BB9 279 spectra ',ECOname(end-7:end)])
xlabel('400-740nm');
ylabel('bb data 1/m')
legend('35m','50m','80m','95m')%,'May2012-unfilter','May2012-newfilter','May2012-newunfilter','May2012-newfilter runII','May2012-newunfilter runII')
saveas(gcf, ['BB9_bb',ECOname(end-7:end)], 'png')