-
Notifications
You must be signed in to change notification settings - Fork 2
/
make_ssp_inputs.m
75 lines (67 loc) · 2.3 KB
/
make_ssp_inputs.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
% Script that matches times of passages with closest sound speed profile.
% Also computes harmonic mean sound speed and saves both to file along with
% image (save both range and time versions), associated vectors and ship properties.
dCINMSB = 580; % assume site depth is this
% load sound speed profiles
sspCSV = 'J:\CALCOFI_NO_UCSB_SPRAY_CASE.csv';
sspDataName = 'J:\CASE_only.mat';
T = importdata(sspCSV);
addpath('E:\Code\GSW\')
%%
nanRows = isnan(T.data(:,3));
T.data(nanRows,:) = [];
T.textdata(nanRows,:) = [];
idStr = [];
iSet = 1;
myTimes = [];
Tkeep = [];
for iS = 1:length(T.textdata)
if ~strcmp(T.textdata{iS,2} ,'CASE')
continue
end
if strcmp(T.textdata{iS,5},'2')||strcmp(T.textdata{iS,5},'3')
T.textdata{iS,5} = '1';
end
idStr{iSet,1} = sprintf('%s_%s_%s',T.textdata{iS,2},T.textdata{iS,3},T.textdata{iS,5});
%myTimes = [myTimes;datenum(T.textdata{iS,3})];
Tkeep.data(iSet,:) = T.data(iS,:);
Tkeep.textdata(iSet,:) = T.textdata(iS,:);
iSet = iSet+1;
end
[uR,iA,iC] = unique(idStr);%,'rows');
uRowIdxSort = sort(iA);
myDepths = 1:200;
%%
CT = Tkeep.data(:,2);
PR = Tkeep.data(:,1);% equating Pressure to depth, not quite right...
SA = Tkeep.data(:,3);
sound_speed = gsw_sound_speed(SA,CT,PR);
Tkeep.data(:,4) = sound_speed;
sspSet = struct;
for iU = 1:size(uRowIdxSort,1)-1
%thisProfile = T.data(uRowIdxSort(iU):(uRowIdxSort(iU+1)-1),:);
profIdxs = find(iC==iU);
thisProfile = Tkeep.data(profIdxs,:);
thisProfileText = Tkeep.textdata(profIdxs,:);
if size(thisProfile,1)<25 %||iU == 895;
continue
end
[~,uR] = unique(thisProfile(:,1));
thisProfile = thisProfile(uR,:);
resampledProfile = interp1(thisProfile(:,1),thisProfile(:,4),myDepths,'linear','extrap')';
sspSet(iU).profile = resampledProfile;
try
sspSet(iU).datenum = datenum(thisProfileText(1,3),'dd-mmm-yy');
catch
sspSet(iU).datenum = datenum(thisProfileText(1,3),'yyyymmdd');
end
sspSet(iU).datetxt = thisProfileText(1,3);
H = sndspd_mean(myDepths',resampledProfile,dCINMSB);
sspSet(iU).harmMeanSSP = H;
end
[tSort,IX] = sort([sspSet(:).datenum]);
sspSet = sspSet(IX);
imagesc([sspSet.profile])
plot([sspSet.datenum],[sspSet.harmMeanSSP])
%sspDataName = strrep(sspCSV,'.csv','.mat');
save(sspDataName,'sspSet','-v7.3')