Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Code/CTD.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@
"long_name": "Turbidity",
"standard_name": "sea_water_turbidity",
"coverage_content_type": "physicalMeasurement"
},
"sn": {
"units": "",
"long_name": "Serial Number",
"coverage_content_type": "auxiliaryInformation"
}
},

Expand Down
5 changes: 5 additions & 0 deletions Code/Combo.json
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,11 @@
"units": "",
"long_name": "ODAS Library Version",
"coverage_content_type": "auxiliaryInformation"
},
"sn": {
"units": "",
"long_name": "Serial Number",
"coverage_content_type": "auxiliaryInformation"
}
},

Expand Down
35 changes: 35 additions & 0 deletions Code/calc_chi.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
%
% Calculate chi from temperature gradients given an already calculated epsilon
%
% Aug-2024, Pat Welch, pat@mousebrains.com

function [dInfo, tbl] = calc_chi(diss, dInfo)
arguments (Input)
diss table % Profile information
dInfo (1,:) table % Summary information about the profile
end % arguments Input
arguments (Output)
dInfo (1,:) table % pInfo with extra fields
tbl table % Tabular form of diss struct
end % arguments Output

kappa_T = 1.4e-7; % thermal diffusivity [m^2/s]

tbl = table();
tbl.t = diss.t;
tbl.depth = diss.depth;

names = string(diss.Properties.VariableNames);

for name = names(startsWith(names, "gradT"))
gradT = diss.(name);
gradT2 = gradT.^2;
% gradT2(gradT <= 0) = NaN;
index = extractAfter(name, "gradT");
tbl.(name) = gradT;
tbl.(sprintf("chi_dT%s_mean", index)) = 2 * kappa_T * diss.N2 .* diss.epsilonMean ./ gradT2;
for j = 1:size(diss.e,2)
tbl.(sprintf("chi_dT%s_e%d", index, j)) = 2 * kappa_T * diss.N2 .* diss.e(:,j) ./ gradT2;
end % for j
end % for name
end % calc_chi
151 changes: 69 additions & 82 deletions Code/chi2binned.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,86 +19,73 @@
return;
end % if ~row.qProfileOkay

warning("Chi binning not implemented");

% fnChi = row.fnChi;
% fnBin = fullfile(pars.chi_binned_root, append(row.name, ".mat"));
% row.fnChiBin = fnBin;
%
% if isnewer(fnBin, fnChi)
% retval = {fnBin, []}; % We want this for combining
% fprintf("%s: %s is newer than %s\n", row.name, row.fnBin, row.fnChi);
% return;
% end % if isnewer
%
% if isempty(a)
% fprintf("Loading %s\n", row.fnChi);
% a = load(row.fnChi);
% end % if isempty
%
% %% Bin the data into depth bins
%
% pInfo = a.info;
% profiles = a.profiles;
%
% fprintf("%s: Binning %d profiles\n", row.name, numel(profiles));
%
% if pars.profile_direction == "time" % Bin in time
% binSize = seconds(pars.binChi_width); % Bin stepsize in (sec)
% keyName = "t";
% binFunc = @bin_by_time;
% glueFunc = @glue_lengthwise;
% else % Bin by depth
% binSize = pars.binChi_width; % Bin stepsize (m)
% keyName = pars.binChi_variable; % Variable to bin by
% binFunc = @bin_by_real;
% glueFunc = @glue_widthwise;
% end % if profile_direction
%
% casts = cell(numel(profiles),1);
% for index = 1:numel(profiles)
% profile = profiles{index};
% nE = size(profile.e, 2);
% prof2 = table();
% for name = string(profile.Properties.VariableNames)
% sz = size(profile.(name),2);
% if ~ismatrix(profile.(name)), continue; end
% if sz == 1
% prof2.(name) = profile.(name);
% elseif sz == nE
% for j = 1:sz
% prof2.(append(name, "_", string(j))) = profile.(name)(:,j);
% end % for j;
% end % if sz
% end % for name
%
% casts{index} = binFunc(binSize, keyName, prof2, pars.binChi_method);
% end % for index
%
% qDrop = cellfun(@isempty, casts); % This shouldn't happend
%
% if any(qDrop)
% casts = casts(~qDrop);
% pInfo = pInfo(~qDrop,:);
% end % any qDrop
%
% if isempty(casts)
% row.qProfileOkay = false;
% fprintf("%s: No usable casts found in %s\n", row.name, row.fnProf);
% return;
% end
%
% tbl = glueFunc("bin", casts);
%
% binned = struct ( ...
% "tbl", tbl, ...
% "info", pInfo);
% if isfield(a, "fp07")
% binned.fp07 = a.fp07;
% end % if isfield
%
% my_mk_directory(fnBin);
% save(fnBin, "-struct", "binned", pars.matlab_file_format);
% fprintf("%s: Saving %d profiles to %s\n", row.name, size(binned.info,1), fnBin);
% retval = {fnBin, binned};
fnChi = row.fnChi;
fnBin = fullfile(pars.chi_binned_root, append(row.name, ".mat"));
row.fnChiBin = fnBin;

if isnewer(fnBin, fnChi)
retval = {fnBin, []}; % We want this for combining
fprintf("%s: %s is newer than %s\n", row.name, row.fnBin, row.fnChi);
return;
end % if isnewer

if isempty(a)
fprintf("Loading %s\n", row.fnChi);
a = load(row.fnChi);
end % if isempty

%% Bin the data into depth bins

pInfo = a.info;
profiles = a.profiles;

fprintf("%s: Binning %d profiles\n", row.name, numel(profiles));

if pars.profile_direction == "time" % Bin in time
binSize = seconds(pars.binChi_width); % Bin stepsize in (sec)
keyName = "t";
binFunc = @bin_by_time;
glueFunc = @glue_lengthwise;
else % Bin by depth
binSize = pars.binChi_width; % Bin stepsize (m)
keyName = pars.binChi_variable; % Variable to bin by
binFunc = @bin_by_real;
glueFunc = @glue_widthwise;
end % if profile_direction

casts = cell(numel(profiles),1);
for index = 1:numel(profiles)
profile = profiles{index};
prof2 = table();
for name = string(profile.Properties.VariableNames)
if ~ismatrix(profile.(name)), continue; end
prof2.(name) = profile.(name);
end % for name

casts{index} = binFunc(binSize, keyName, prof2, pars.binChi_method);
end % for index

qDrop = cellfun(@isempty, casts); % This shouldn't happend

if any(qDrop)
casts = casts(~qDrop);
pInfo = pInfo(~qDrop,:);
end % any qDrop

if isempty(casts)
row.qProfileOkay = false;
fprintf("%s: No usable casts found in %s\n", row.name, row.fnProf);
return;
end

tbl = glueFunc("bin", casts);

binned = struct ( ...
"tbl", tbl, ...
"info", pInfo);

my_mk_directory(fnBin);
save(fnBin, "-struct", "binned", pars.matlab_file_format);
fprintf("%s: Saving %d profiles to %s\n", row.name, size(binned.info,1), fnBin);
retval = {fnBin, binned};
end % chi2binned
8 changes: 8 additions & 0 deletions Code/convert2mat.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
a = odas_p2mat(char(row.fn), p2args{:}); % extract P file contents
my_mk_directory(row.fnMat);
save(row.fnMat, "-struct", "a", pars.matlab_file_format); % save into a mat file

row.sn = setupstr(a.setupfilestr, 'instrument_info', 'sn'); % Get the serial number in the instrument_info stanza
if isempty(row.sn)
row.sn = missing;
else
row.sn = string(row.sn{1});
end % if isempty

row.qMatOkay = true;
fprintf("Took %.2f seconds to convert %s\n", toc(stime), row.name);
catch ME
Expand Down
4 changes: 2 additions & 2 deletions Code/ctd2binned.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
fnCTD = fullfile(pars.ctd_root, append(row.name, ".mat"));
row.fnCTD = fnCTD;

cInfo = row(:,["name", "t0", "tEnd"]);
cInfo = row(:,["name", "t0", "tEnd", "sn"]);
cInfo = renamevars(cInfo, "tEnd", "t1"); % For NetCDF time range

binned = struct("tbl", tbl, "info", cInfo);
Expand Down Expand Up @@ -216,4 +216,4 @@
ctd.lon(q) = gps.lon(t) - dLondt .* dt;
ctd.lat(q) = gps.lat(t) - dLatdt .* dt;
end
end % addGPS
end % addGPS
3 changes: 2 additions & 1 deletion Code/mat2profile.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@

profilesInfo = struct();
profilesInfo.profiles = profiles;
profilesInfo.row = row(1,["name", "date", "fClock" "t0", "t1", "tEnd"]);
profilesInfo.row = row(1,["name", "date", "fClock" "t0", "t1", "tEnd", "sn"]);
profilesInfo.pInfo = profileInfo;
if qFP07
profilesInfo.fp07Lags = fp07_lags;
Expand All @@ -181,6 +181,7 @@
tbl = table();
tbl.name = repmat(row.name, nProfiles, 1);
tbl.index = (1:nProfiles)';
tbl.sn = repmat(row.sn, nProfiles,1);
tbl.t0 = NaT(nProfiles,1);
tbl.t1 = NaT(nProfiles,1);
tbl.n_slow = nan(nProfiles,1);
Expand Down
Loading