This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalibration_setup.m
176 lines (154 loc) · 6.6 KB
/
calibration_setup.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
matfiles = {'S100882A003_LakeK_Sig2_8' 'S100882A003_LakeK_Sig2_31'...
'S100882A003_LakeK_Sig2_26'};
a = [15e-6 65e-6 100e-6 250e-6 500e-6 750e-6]; % particle diameters
rho_s = [1010 1050 1100 1200 1330]; % particle desities
% .75mm at 1330 looks to be the winner blue
% or .065mm at 1010 salmon red
% of .01mm at 1010 purple
%% Force solution for concentrations
% for k=6:length(a)
% for j=1:length(rho_s)
% % attenuations: using .1mm diameter and 1100kg/m3 for now
% for i=1:length(matfiles)
% matfile = [matfiles{i} '.mat'];
% [conc, amp_cor, dir] = ABS_Correction(matfile, a(k), rho_s(j), true);
% save([dir '\' matfiles{i} '_concentration.mat'], 'conc', 'amp_cor');
% end
% end
% close all
% end
% calculate tke for each adcp datafile
for i=1:length(matfiles)
matfile = [matfiles{i} '.mat'];
[tke, time] = Beam5_TKE(matfile);
save([matfiles{i} '_tke.mat'],'tke','time')
end
% normalize concentration data - set bottom = 1
for k=1:length(a)
for j=1:length(rho_s)
for i=1:length(matfiles)
dir = ['.\calibrationFiles' matfiles{i} '_' num2str(a(k)) 'm' num2str(rho_s(j)) 'density'];
%addpath(fullfile(['E:\Documents\UW\CEWA 600\' matfiles{i} '_' num2str(a(k)) 'm' num2str(rho_s(j)) 'density']));
load([dir '\' matfiles{i} '_concentration.mat']);
%conc_orig = load([matfiles{i} '_concentration.mat']);
normal_factor = max(conc,[],2); % set bottom conc = 1
normal_conc = conc./normal_factor; % normalize by bottom conc
avg_normal = mean(normal_conc,1);
save([dir '\' matfiles{i} '_concentration.mat'], 'conc', 'amp_cor', 'normal_conc', 'avg_normal');
figure()
surface(flipud(normal_conc'),'EdgeColor','None');
colorbar
title('Normalized Concentration')
xlabel('Depth Bins');
ylabel('Time (hr)');
saveas(gcf, [dir '/Normalized_Conc.jpg']);
end
close all
end
end
%% apply linear correction to normalized concentration and corrected
% applitude - it appears the beam spreading attenuation is too strong
for k=1:length(a)
for j=1:length(rho_s)
for i=1:length(matfiles)
dir = ['.\calibrationFiles' matfiles{i} '_' num2str(a(k)) 'm' num2str(rho_s(j)) 'density'];
load([dir '\' matfiles{i} '_concentration.mat']);
background_conc = max(mink(normal_conc,2,1)); % second smallest in case of bad data?
%plot(background_conc');
% x = find(diff(background_conc)./max(background_conc)>.3);
% if numel(x)>1
% x = min(x);
% end
x = 69;
% setting background suspension = 0, i.e unknown C constant
final_cal_conc = normal_conc - [background_conc(1:x) zeros(1,length(background_conc)-x)];
final_avg_conc = mean(final_cal_conc,1);
% applying linear fix to corrected amplitude
load([dir '\' matfiles{i} '_concentration.mat']);
background_dB = max(mink(amp_cor,2,1));
final_cor_amp = amp_cor - [background_dB(1:x) zeros(1,length(background_conc)-x)];
save([dir '/' matfiles{i} '_calibrated_data.mat'], 'final_cal_conc', 'final_avg_conc', 'final_cor_amp');
figure()
surface(flipud(final_cal_conc'),'EdgeColor','None');
colorbar
title('Final Normalized Concentration')
xlabel('Depth Bins');
ylabel('Time (hr)');
saveas(gcf, [dir '/Final_Cal_Conc.jpg']);
figure()
surface(flipud(final_cor_amp'),'EdgeColor','None');
colorbar
title('Final Corrected Amplitude (-C dB)')
xlabel('Depth Bins');
ylabel('Time (hr)');
saveas(gcf, [dir '/Final_Cor_Amp.jpg']);
end
close all
end
end
%% measuring uncertainty in particle size? -
% take means of each concentration dataset and coplot them
for i=1:length(matfiles)
figure()
for k=1:length(a)
for j=1:length(rho_s)
dir = ['.\calibrationFiles\' matfiles{i} '_' num2str(a(k)) 'm' num2str(rho_s(j)) 'density'];
load([dir '\' matfiles{i} '_concentration.mat']);
plot(1:length(avg_normal), avg_normal)
hold on
end
end
xlabel('Depth Bins (4cm each)');
ylabel('Normalized Concentration');
end
for i=1:length(matfiles)
figure()
for k=1:length(a)
for j=1:length(rho_s)
dir = ['.\calibrationFiles\' matfiles{i} '_' num2str(a(k)) 'm' num2str(rho_s(j)) 'density'];
load([dir '\' matfiles{i} '_calibrated_data.mat']);
plot(1:length(final_avg_conc), final_avg_conc, 'DisplayName', [num2str(a(k)) 'um ' num2str(rho_s(j)) 'kg/m^3'])
hold on
end
end
title('Final Calibrated Concentration');
xlabel('Depth Bins (4cm each)');
ylabel('Normalized Concentration');
axis([0 length(final_avg_conc) 0 .1]);
%legend('Location','Northwest');
saveas(gcf, [matfiles{i} '.jpg']);
end
%% Create individual timeseries of corrected amplitude (dB), normalized concentration, and TKE
% Matlab can't find directories it just created. That's dumb.
for k=1:length(a)
for j=1:length(rho_s)
for i=1:length(matfiles)
dir = ['.\calibrationFiles' matfiles{i} '_' num2str(a(k)) 'm' num2str(rho_s(j)) 'density'];
load([dir '\' matfiles{i} '_calibrated_data.mat']);
load([matfiles{i} '_tke.mat']);
figure()
bin = [60 64 68]; % depth bin to plot
subplot(3,1,1)
plot(time, final_cor_amp(:,bin));
xlabel('time, hr');
datetick('x');
ylabel('corrected amplitude, -C dB');
title(matfiles{i});
legend('Bin 60','Bin 64','Bin 68');
subplot(3,1,2)
plot(time, final_cal_conc(:,bin));
xlabel('time, hr');
datetick('x');
ylabel("concentration, normalized");
legend('Bin 60','Bin 64','Bin 68');
subplot(3,1,3)
plot(time, tke(:,bin));
xlabel('time, hr');
datetick('x');
ylabel('TKE, m^2/s^2');
legend('Bin 60','Bin 64','Bin 68');
saveas(gcf, [dir '/TS.jpg']);
end
close all
end
end