Bin Averages and Metrics

Tianyu Zhou, 10/27/2021, at UDel

Quality Control and Binning

Load data located within Nares Strait (pre-selected and stored in a '.mat' file) and perform quality control procedures.
clc;
clear;
load('../data/OMG_data_Nares')
profi_num = size(output,1);
depth = cell(profi_num,1);
T = cell(profi_num,1);
S = cell(profi_num,1);
rho = cell(profi_num,1);
for n = 1:2%profi_num
data = output{n,5};
% NOTE: a small percentage of probes do not have salinity or density data!
if size(data,2) == 8
% for these who have salinity or density data
% Quality control (step1): remove -99 data values
depth_vec = data(:,2);
T_vec = data(:,3);
S_vec = data(:,5);
rho_vec = data(:,7);
flag = find(T_vec==-99|S_vec==-99|rho_vec==-99);
depth_vec(flag) = [];
T_vec(flag) = [];
S_vec(flag) = [];
rho_vec(flag) = [];
% Quality control (step2): binning
% binning is performed by fun_binning (see the appendix)
[T_vec,S_vec,rho_vec,depth_vec] = fun_binning(T_vec,S_vec,rho_vec,depth_vec);
depth{n} = depth_vec; % m
T{n} = T_vec; % oC
S{n} = S_vec; % ppt
rho{n} = rho_vec; % kg/m3
else
% for these who do not have salinity or density data
% Quality control (step1): remove -99 data values
depth_vec = data(:,3);
T_vec = data(:,4);
S_vec = nan;
rho_vec = nan;
flag = find(T_vec==-99);
depth_vec(flag) = [];
T_vec(flag) = [];
% Quality control (step2): binning
% binning is performed by fun_binning (see the appendix)
[T_vec,S_vec,rho_vec,depth_vec] = fun_binning(T_vec,S_vec,rho_vec,depth_vec);
depth{n} = depth_vec;
T{n} = T_vec;
S{n} = S_vec;
rho{n} = rho_vec;
end
end
depth = cell2mat(depth);
T = cell2mat(T);
S = cell2mat(S);
rho = cell2mat(rho);

Plotting the Binned Data

% Temperature Profile
n = 2;
data = output{n,5};
depth_org = data(:,2);
T_org = data(:,3);
S_org = data(:,5);
flag = find(T_org==-99|S_org==-99);
depth_org(flag) = [];
T_org(flag) = [];
S_org(flag) = [];
f = figure;
set(f,'units','centimeters','position',[1,1,9*1.2,12*1.2],'color','w')
FontSize = 15;
plot(T_org,-depth_org,'linewidth',1.5)
hold on
plot(T(n,:),-depth(n,:),'linewidth',1.5)
xlim([-2 1])
ylim([-700 0])
box on
grid on
xlabel('Temperature (^{o}C)','FontWeight','bold')
ylabel('Depth (m)','FontWeight','bold')
legend({'original','binned'},'Location','southwest')
set(gca,'FontSize',FontSize,'tickdir','out','xaxislocation','top')
% Salinity Profile
f = figure;
set(f,'units','centimeters','position',[1,1,9*1.2,12*1.2],'color','w')
FontSize = 15;
plot(S_org,-depth_org,'linewidth',1.5)
hold on
plot(S(n,:),-depth(n,:),'linewidth',1.5)
xlim([28 36])
ylim([-700 0])
box on
grid on
xlabel('Salinity (ppt)','FontWeight','bold')
ylabel('Depth (m)','FontWeight','bold')
legend({'original','binned'},'Location','southwest')
set(gca,'FontSize',FontSize,'tickdir','out','xaxislocation','top')

The Fresh Water Component

% reference: Spall (2013,JPO)
n = 2;
Sr = 34.8*ones(size(S(n,:)));
S_diff = Sr-S(n,:);
S_integ = S_diff./Sr;
index = find(S_integ<=0,1,'first');
S_integ(index:end) = [];
F = sum(S_integ)
F = 12.9996

Appendix: The Function Used for Binning

function [T_out,S_out,rho_out,depth_out] = fun_binning(T_in,S_in,rho_in,depth_in)
% Created by Tianyu Zhou, 10/27/2021, at UDel
depth_max = 1000;
dz = 1;
depth_bin = 2:dz:depth_max;
nbin = size(depth_bin,2);
T_out = ones(size(depth_bin));
S_out = ones(size(depth_bin));
rho_out = ones(size(depth_bin));
for n = 1:nbin-1
low = depth_bin(n);
high = depth_bin(n+1);
T_out(n) = mean(T_in(depth_in>=low & depth_in<=high),'omitnan');
if ~isnan(S_in)
S_out(n) = mean(S_in(depth_in>=low & depth_in<=high),'omitnan');
rho_out(n) = mean(rho_in(depth_in>=low & depth_in<=high),'omitnan');
else
S_out(n) = nan;
rho_out(n) = nan;
end
end
depth_out = depth_bin;
end