forked from athurnherr/LDEO_IX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkbtrk.m
387 lines (328 loc) · 10.8 KB
/
checkbtrk.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
function p=checkbtrk(d,di,de,dr,p);
% compare RDI to own bottom track
%
%======================================================================
% C H E C K B T R K . M
% doc: Sat Jul 3 23:57:25 2004
% dlm: Wed Sep 4 19:02:39 2019
% (c) 2004 ladcp@
% uE-Info: 24 0 NIL 0 0 72 0 2 8 NIL ofnI
%======================================================================
% CHANGES BY ANT:
% Jul 4, 2004: - adapted to [edit_data.m], i.e. plot unedited data
% in black & edited in blue; also use unedited data
% to calculate bias slope
% Jul 16, 2004: - adapted to changes in [edit_data.m]
% Mar 5, 2010: - debugging???
% Oct 1, 2010: - BUG: code bombed when bottom was detected (i.e. p.zbottom
% was set) but when all these bottom returns turned out
% to be outside the valid range (i.e. almost certainly
% false)
% Sep 4, 2019: - fixed plotting BUGs reported by GK
if ~existf(p,'zbottom'), return , end
if ~isfinite(p.zbottom), return, end
if ~existf(d,'bvel_own'), d.bvel_own=d.bvel*nan; d.hbot_own=d.hbot*nan; end
if ~existf(d,'bvel_rdi'), d.bvel_rdi=d.bvel*nan; d.hbot_rdi=d.hbot*nan; end
ii=find(abs(d.z+p.zbottom)<max(p.btrk_range) & ...
abs(d.z+p.zbottom)>min(p.btrk_range));
if isempty(ii), p.zbottom = nan, return, end
if existf(d,'bvel_rdi')
bu_rdi=d.bvel_rdi(ii,1);
bv_rdi=d.bvel_rdi(ii,2);
bw_rdi=d.bvel_rdi(ii,3);
else
bu_rdi=d.bvel(ii,1)*nan;
bv_rdi=d.bvel(ii,2)*nan;
bw_rdi=d.bvel(ii,3)*nan;
end
if existf(d,'hbot_rdi')
bh_rdi=d.hbot_rdi(ii);
else
bh_rdi=d.hbot(ii)*nan;
end
u_o=interp1(dr.z,dr.u,-d.z(ii)');
u_c=-interp1(dr.tim',dr.uctd',d.time_jul(ii)');
bu_own=d.bvel_own(ii,1);
bv_own=d.bvel_own(ii,2);
bw_own=d.bvel_own(ii,3);
bh_own=d.hbot_own(ii);
v_o=interp1(dr.z,dr.v,-d.z(ii)');
v_c=-interp1(dr.tim',dr.vctd',d.time_jul(ii)');
rw=d.rw(d.izd,ii);
ij=find((d.izm(d.izd,ii)+p.zbottom)<d.zd(1));
rw(ij)=nan;
if existf(d,'wctd') ==-1
w_c=d.wctd(ii)';
disp(' use CTD pressure derived W')
else
w_c=medianan(rw,3)';
disp(' use reference layer W')
end
w_c2=w_c-[0;diff(w_c)/2 ];
bu_used=d.bvel(ii,1);
bv_used=d.bvel(ii,2);
bw_used=d.bvel(ii,3);
bh_used=d.hbot(ii);
blen=d.down.Cell_length/100;
% extract raw velocity data near bottom
rube = d.ru(d.izd,ii);
rvbe = d.rv(d.izd,ii);
rwbe = d.rw(d.izd,ii);
% the same, but only velocities that passed editing
ru = d.ru; ru(find(~isfinite(d.weight))) = NaN; ru = ru(d.izd,ii);
rv = d.rv; rv(find(~isfinite(d.weight))) = NaN; rv = rv(d.izd,ii);
rw = d.rw; rw(find(~isfinite(d.weight))) = NaN; rw = rw(d.izd,ii);
% correct velocities with solved U_ctd
rua=ru-repmat(u_c',[length(d.izd) 1]); ruabe=rube-repmat(u_c',[length(d.izd) 1]);
rva=rv-repmat(v_c',[length(d.izd) 1]); rvabe=rvbe-repmat(v_c',[length(d.izd) 1]);
rwa=rw-repmat(w_c',[length(d.izd) 1]); rwabe=rwbe-repmat(w_c',[length(d.izd) 1]);
rwan=abs(rw)./abs(repmat(w_c',[length(d.izd) 1]));
rwanbe=abs(rwbe)./abs(repmat(w_c',[length(d.izd) 1]));
bua_rdi=bu_rdi-u_c;
bva_rdi=bv_rdi-v_c;
% try to use w inbetween pings for real bottom track
bwa1_rdi=bw_rdi-w_c;
bwa2_rdi=bw_rdi-w_c2;
if stdnan(bwa1_rdi)>stdnan(bwa2_rdi)
bwa_rdi=bwa2_rdi;
disp(' use inbetween w-ref')
else
bwa_rdi=bwa1_rdi;
end
bua_own=bu_own-u_c;
bva_own=bv_own-v_c;
bwa_own=bw_own-w_c;
bua_used=bu_used-u_c;
bva_used=bv_used-v_c;
bwa_used=bw_used-w_c;
% save bias and std of bottom track anomaly
p.btrk_u_bias=medianan(bua_used,6);
p.btrk_u_std=stdnan(bua_used);
p.btrk_v_bias=medianan(bva_used,6);
p.btrk_v_std=stdnan(bva_used);
p.btrk_w_bias=medianan(bwa_used,6);
p.btrk_w_std=stdnan(bwa_used);
disp(['CHECKBTRK: check bottom track against U_ctd solution '])
disp([' profiles within give acceptable range: ',int2str(length(ii))])
disp([' U bias :',num3str(p.btrk_u_bias,6,3),' [m/s] std: ',...
num3str(p.btrk_u_std,5,3),' [m/s]'])
disp([' V bias :',num3str(p.btrk_v_bias,6,3),' [m/s] std: ',...
num3str(p.btrk_v_std,5,3),' [m/s]'])
disp([' W bias :',num3str(p.btrk_w_bias,6,3),' [m/s] std: ',...
num3str(p.btrk_w_std,5,3),' [m/s]'])
if abs(p.btrk_u_bias)>0.1
warn=[' large U bottom track bias ',num2str(p.btrk_u_bias)];
disp(warn)
p.warnp(size(p.warnp,1)+1,1:length(warn))=warn;
end
if abs(p.btrk_v_bias)>0.1
warn=[' large V bottom track bias ',num2str(p.btrk_v_bias)];
disp(warn)
p.warnp(size(p.warnp,1)+1,1:length(warn))=warn;
end
% correct nominal depth with detected bottom depth
izm=d.izm(d.izd,ii);
zcor=(-d.hbot(ii)+d.z(ii));
zcor_std=stdnan(zcor);
p.btrk_rough=zcor_std;
izm=izm-repmat(zcor,[length(d.izd) 1]);
% compute bias W slope
dz=abs(diff(d.zd(1:2)));
wbias=[];
zbias=[];
nbias=[];
for i=1:6
dzi=dz*i/2;
ij=find(abs(izm+dzi)<(dz/4));
nok=sum(isfinite(rwanbe(ij)));
if nok>5
wbias=[wbias, 1-medianan(rwanbe(ij))];
zbias=[zbias, dzi];
nbias=[nbias, nok];
end
end
if exist('wbias')==1
p.wbslope=polyfit(zbias,wbias,1);
else
wbias=nan;
zbias=nan;
p.wbslope=[nan nan];
end
disp([' W slope fact :',num3str(p.wbslope(1),6,4),' [1/m] lower W below bottom '])
% compute 'wave' action
p.btrk_wdiff=medianan(abs(diff(w_c)));
disp([' W diff :',num3str(p.btrk_wdiff,6,4),' [m/s] ping to ping w difference '])
disp([' H std :',num3str(zcor_std,6,1),' [m] large means bottom is rough/sloped'])
p.btrk_tilt_mean=mean(d.tilt(ii));
p.btrk_tilt_std=std(d.tilt(ii));
disp([' Tilt mean :',num3str(p.btrk_tilt_mean,3,1),' +/- ',...
num3str(p.btrk_tilt_std,3,1),' [^o] '])
% select bins used for own bottom track
iz=find(abs(izm+blen*p.btrk_below)<blen);
% plot results
tx2=0.25;
figure(13)
clf
subplot(221); hold on;
plot(ruabe,izm,'.k'); % all velocities
plot(rua,izm,'.g'); % edited velocities
plot(ruabe(iz),izm(iz),'.r'); % used-for-BT velocities
axis tight;
ax=axis;
ax(1:2)=[-1 1]*0.8;
ax(3)=-160;
ax(4)=50;
vh=floor(ax(1)*20)/20+0.0125 : 0.025: ceil(ax(2)*20)/20;
plot(ax(1:2),[0 0],'-')
plot([0 0],ax(3:4),'k-','linewidth',1.5)
plot([0 0]+p.btrk_u_bias,ax(3:4),'r-','linewidth',1.5)
text(tx2,10,' Bottom')
if sum(isfinite(bua_rdi))>0
[y,x]=hist(bua_rdi,vh);
y([1,end])=0;
ys=sum(y);
[x,y]=stairs(x,y);
fill(x,y/max(y)*30-50,'-g')
plot([0 0]+medianan(bua_rdi,6),ax(3:4),'-g')
text(tx2,-40,['RDI n: ',int2str(ys)])
text(0.1,-10,[' bias ',num3str(medianan(bua_rdi,6),6,3)],'color','g')
end
[y,x]=hist(bua_own,vh);
y([1,end])=0;
ys=sum(y);
[x,y]=stairs(x,y);
fill(x,y/max(y)*30-100,'-b')
plot([0 0]+medianan(bua_own,6),ax(3:4),'-b')
text(tx2,-90,[' own n: ',int2str(ys)])
text(0.1,-60,[' bias ',num3str(medianan(bua_own,6),6,3)],'color','b')
[y,x]=hist(real(de.bvel-de.uctd(:,1).'),vh);
y([1,end])=0;
ys=sum(y);
[x,y]=stairs(x,y);
fill(x,y/max(y)*30-150,'-r')
text(tx2,-140,['Sup. ens. n: ',int2str(ys)])
text(0.1,-110,[' bias ',num3str(p.btrk_u_bias,6,3)],'color','r')
title([' U bot-tr mean U_{ctd} : ',num3str(-meannan(real(de.uctd(:,1))),4,2),...
' [m/s] added'])
xlabel(' U [m/s]')
ylabel('depth [m]')
axis(ax)
text(-0.7,-154,['Bottom roughness: ',int2str(p.btrk_rough),' [m]'])
subplot(222); hold on;
plot(rvabe,izm,'.k'); % all velocities
plot(rva,izm,'.g'); % edited velocities
plot(rvabe(iz),izm(iz),'.r') % used-for-BT velocities
axis tight
ax=axis;
ax(1:2)=[-1 1]*0.8;
ax(3)=-160;
ax(4)=50;
plot(ax(1:2),[0 0],'-')
plot([0 0],ax(3:4),'k-')
plot([0 0]+p.btrk_v_bias,ax(3:4),'r-','linewidth',1.5)
text(tx2,10,' Bottom')
if sum(isfinite(bva_rdi))>0
[y,x]=hist(bva_rdi,vh);
y([1,end])=0;
ys=sum(y);
[x,y]=stairs(x,y);
fill(x,y/max(y)*30-50,'-g')
plot([0 0]+medianan(bva_rdi,6),ax(3:4),'-g')
text(tx2,-40,[' RDI n: ',int2str(ys)])
text(0.1,-10,[' bias ',num3str(medianan(bva_rdi,6),6,3)],'color','g')
end
[y,x]=hist(bva_own,vh);
y([1,end])=0;
ys=sum(y);
[x,y]=stairs(x,y);
fill(x,y/max(y)*30-100,'-b')
plot([0 0]+medianan(bva_own,6),ax(3:4),'-b')
text(tx2,-90,[' own n: ',int2str(ys)])
text(0.1,-60,[' bias ',num3str(medianan(bva_own,6),6,3)],'color','b')
[y,x]=hist(imag(de.bvel-de.uctd(:,1).'),vh);
y([1,end])=0;
ys=sum(y);
[x,y]=stairs(x,y);
fill(x,y/max(y)*30-150,'-r')
text(tx2,-140,['Sup. ens. n: ',int2str(ys)])
text(0.1,-110,[' bias ',num3str(p.btrk_v_bias,6,3)],'color','r')
title([' V bot-tr mean V_{ctd} : ',num3str(-meannan(imag(de.uctd(:,1))),4,2),...
' [m/s] added'])
xlabel(' V [m/s]')
ylabel('depth [m]')
text(-0.7,-154,['Tilt : ',num3str(p.btrk_tilt_mean,3,1),' +/- ',...
num3str(p.btrk_tilt_std,3,1),' [^o]'])
axis(ax)
tx2=0.05;
subplot(223); hold on;
plot(rwabe,izm,'.k'); % all velocities
plot(rwa,izm,'.g'); % edited velocities
plot(rwabe(iz),izm(iz),'.r'); % used-for-BT velocities
axis tight
ax=axis;
ax(1:2)=[-1 1]*0.4;
vh=floor(ax(1)*20)/20+0.005 : 0.01: ceil(ax(2)*20)/20;
ax(3)=-160;
ax(4)=50;
plot(ax(1:2),[0 0],'-')
plot([0 0],ax(3:4),'k-')
plot([0 0]+p.btrk_w_bias,ax(3:4),'r-','linewidth',1.5)
text(tx2,10,' Bottom')
if sum(isfinite(bwa_rdi))>0
[y,x]=hist(bwa_rdi,vh);
y([1,end])=0;
ys=sum(y);
[x,y]=stairs(x,y);
fill(x,y/max(y)*30-50,'-g')
plot([0 0]+medianan(bwa_rdi,6),ax(3:4),'-g')
text(tx2,-40,[' RDI n: ',int2str(ys)])
text(0.1,-10,[' bias ',num3str(medianan(bva_rdi,6),6,3)],'color','g')
end
[y,x]=hist(bwa_own,vh);
y([1,end])=0;
ys=sum(y);
[x,y]=stairs(x,y);
fill(x,y/max(y)*30-100,'-b')
plot([0 0]+medianan(bwa_own,6),ax(3:4),'-b')
text(tx2,-90,[' own n: ',int2str(ys)])
text(0.1,-60,[' bias ',num3str(medianan(bwa_own,6),6,3)],'color','b')
[y,x]=hist(di.bvel(3,:)-medianan(di.rw),vh);
y([1,end])=0;
ys=sum(y);
[x,y]=stairs(x,y);
fill(x,y/max(y)*30-150,'-r')
text(tx2,-140,['Sup. ens. n: ',int2str(ys)])
text(0.1,-110,[' bias ',num3str(p.btrk_w_bias,6,3)],'color','r')
text(-0.3,-154,['W diff: ',num3str(p.btrk_wdiff,6,3),' [m/s]'])
title([' W bottom track [m/s] '])
xlabel(' W [m/s]')
ylabel('depth [m]')
axis(ax)
subplot(224); hold on;
plot(rwanbe,izm,'.k'); % all velocities
plot(rwan,izm,'.g'); % edited velocities
plot(rwan(iz),izm(iz),'.r'); % used-for-BT velocities
axis tight
ax=axis;
ax(1:2)=[0.5 1.2];
ax(3)=-60;
ax(4)=60;
title([' W bottom track factor '])
xlabel(' abs(W)/abs(W_{ref}) ')
ylabel('depth [m]')
axis(ax)
plot(ax(1:2),[0 0],'-')
plot([1 1],ax(3:4),'k-','linewidth',1.5)
text(tx2,10,' Bottom')
plot(1-polyval(p.wbslope,[40 0]),[-40 0],'-b')
plot(1-wbias,-zbias,'pb')
grid
text(0.54,-50,[' bias slope ',num3str(p.wbslope(1),6,3),' [1/m]'])
text(0.54,-58,[' offset ',num3str(p.wbslope(2),6,3) ])
text(0.54,50,[' beam angle ',int2str(d.down.Beam_angle)])
text(0.54,42,[' bin length ',int2str(d.down.Cell_length/100),' [m]'])
text(0.54,34,[' Pings/Ens ',int2str(d.down.Pings_per_Ensemble)])
text(0.54,26,[' Frequency ',int2str(d.down.Frequency),' [kHz]'])
text(0.54,10,[' Zbottom ',int2str(p.zbottom),' [m]'])
streamer([p.name,' Figure 13']);
orient tall