-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkbtrk2.m
463 lines (393 loc) · 10.5 KB
/
checkbtrk2.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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
function checkbtrk2(d,p);
% compare RDI to own bottom track
%
if ~existf(p,'zbottom'), return , end
if ~isfinite(p.zbottom), return, end
ii=find(abs(d.z+p.zbottom)<max(p.btrk_range) & ...
abs(d.z+p.zbottom)>min(p.btrk_range));
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
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);
if 0
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')
w_c=d.wctd(ii)';
disp(' use CTD pressure derived W')
else
w_c=medianan(rw,3)';
disp(' use reference layer W')
end
end
bu_used=d.bvel(ii,1);
bv_used=d.bvel(ii,2);
bw_used=d.bvel(ii,3);
bh_used=d.hbot(ii);
u_c=bu_used;
v_c=bv_used;
w_c=bw_used;
w_c2=w_c-[0;diff(w_c)/2 ];
blen=d.down.Cell_length/100;
% extract raw velocity data near bottom
ru=d.ru(d.izd,ii);
rv=d.rv(d.izd,ii);
rw=d.rw(d.izd,ii);
rtg=d.tg(d.izd,ii);
% correct velocities with solved U_ctd
rua=ru-repmat(u_c',[length(d.izd) 1]);
rva=rv-repmat(v_c',[length(d.izd) 1]);
rwa=rw-repmat(w_c',[length(d.izd) 1]);
% compute slope factor
ruan=abs(ru)./(abs(repmat(u_c',[length(d.izd) 1])));
ij=find(abs(u_c)<0.05);
ruan(:,ij)=nan;
rvan=abs(rv)./(abs(repmat(v_c',[length(d.izd) 1])));
ij=find(abs(v_c)<0.05);
rvan(:,ij)=nan;
rwan=abs(rw)./(abs(repmat(w_c',[length(d.izd) 1])));
ij=find(abs(w_c)<0.05);
rwan(:,ij)=nan;
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_RDI 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
izm=d.izm(d.izd,ii);
% real binsize
dbin=medianan(medianan(diff(izm)));
% correct nominal depth with detected bottom depth
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(rwan(ij)));
if nok>5
wbias=[wbias, 1-medianan(rwan(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] '])
% selcet bins used for own bottom track
iz=find(abs(izm+blen*p.btrk_below)<blen);
% predict velocity bias from geometry
bangle=d.down.Beam_angle;
sina=sin(bangle*pi/180);
cosa=cos(bangle*pi/180);
gamma=linspace(0,50,20);
sinab=sin(gamma*pi/180);
cosab=cos(gamma*pi/180);
% evaluate at three distances
mhbot=[150 100 50];
cm=['-g';'-b';'-r'];
% plot results
tx2=0.25;
figure(13)
clf
subplot(221)
plot(rua,izm,'.k')
hold on
plot(rua(iz),izm(iz),'.r')
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]-meannan(u_c),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')
title([' U bot-tr mean U_{brt} : ',num3str(meannan(u_c),4,2),...
' [m/s] removed'])
xlabel(' U [m/s]')
ylabel('depth [m]')
axis(ax)
text(-0.7,-154,['Bottom roughness: ',int2str(p.btrk_rough),' [m]'])
subplot(222)
ii=find(bh_used>=110);
plot(ruan(:,ii),izm(:,ii),'.g')
hold on
ii=find(bh_used<=80);
plot(ruan(:,ii),izm(:,ii),'.r')
ii=find(bh_used>80 & bh_used<110);
plot(ruan(:,ii),izm(:,ii),'.b')
axis tight
ax=axis;
ax(1:2)=[0.0 2.0];
ax(3)=-60;
ax(4)=60;
title([' U bottom track factor hbot: (g)>120 (r)<70 '])
xlabel(' abs(U)/abs(U_{RDI}) ')
ylabel('depth [m]')
axis(ax)
for i=-2:2
plot(ax(1:2),dbin*i+[0 0],'-k')
end
plot([1 1],ax(3:4),'k-','linewidth',1.5)
% plot model
for i=1:length(mhbot)
lbot=mhbot(i)./cosab;
nbot=lbot*cosa-mhbot(i)-dbin/2;
plot(sinab/sina,-nbot,cm(i,:))
end
subplot(223)
plot(rva,izm,'.k')
hold on
plot(rva(iz),izm(iz),'.r')
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]-meannan(v_c),ax(3:4),'k-','linewidth',1.5)
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')
title([' V bot-tr mean V_{brt} : ',num3str(meannan(v_c),4,2),...
' [m/s] removed'])
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)
subplot(224)
ii=find(bh_used>=110);
plot(rvan(:,ii),izm(:,ii),'.g')
hold on
ii=find(bh_used<=80);
plot(rvan(:,ii),izm(:,ii),'.r')
ii=find(bh_used>80 & bh_used<110);
plot(rvan(:,ii),izm(:,ii),'.b')
axis tight
ax=axis;
ax(1:2)=[0.0 2.0];
ax(3)=-60;
ax(4)=60;
title([' V bottom track factor hbot: (g)>120 (r)<70 '])
xlabel(' abs(V)/abs(V_{RDI}) ')
ylabel('depth [m]')
axis(ax)
for i=-2:2
plot(ax(1:2),dbin*i+[0 0],'-k')
end
plot([1 1],ax(3:4),'k-','linewidth',1.5)
% plot model
for i=1:length(mhbot)
lbot=mhbot(i)./cosab;
nbot=lbot*cosa-mhbot(i)-dbin/2;
plot(sinab/sina,-nbot,cm(i,:))
end
streamer([p.name,' Figure 13']);
figure(14)
clf
tx2=0.05;
subplot(221)
plot(rwa,izm,'.k')
hold on
plot(rwa(iz),izm(iz),'.r')
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')
title([' W bottom track [m/s] '])
xlabel(' W [m/s]')
ylabel('depth [m]')
axis(ax)
tx2=0.65;
subplot(222)
ii=find(bh_used>=110);
plot(rwan(:,ii),izm(:,ii),'.g')
hold on
ii=find(bh_used<=80);
plot(rwan(:,ii),izm(:,ii),'.r')
ii=find(bh_used>80 & bh_used<110);
plot(rwan(:,ii),izm(:,ii),'.b')
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)
for i=-2:2
plot(ax(1:2),dbin*i+[0 0],'-k')
end
plot([1 1],ax(3:4),'k-','linewidth',1.5)
plot(1-wbias,-zbias,'pb')
grid
% plot model
for i=1:length(mhbot)
lbot=mhbot(i)./cosab;
nbot=lbot*cosa-mhbot(i)-dbin/2;
plot(cosab/cosa,-nbot,cm(i,:))
end
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]'])
subplot(223)
ii=find(bh_used>=110);
plot(rtg(:,ii),izm(:,ii),'.g')
hold on
ii=find(bh_used<=80);
plot(rtg(:,ii),izm(:,ii),'.r')
ii=find(bh_used>80 & bh_used<110);
plot(rtg(:,ii),izm(:,ii),'.b')
axis tight
ax=axis;
%ax(1:2)=[-1 1]*0.4;
ax(3)=-60;
ax(4)=60;
for i=-2:2
plot(ax(1:2),dbin*i+[0 0],'-k')
end
plot([0 0],ax(3:4),'k-')
text(tx2,3,' Bottom')
title([' Target Strength '])
xlabel(' TG range corrected [dB]')
ylabel('depth [m]')
axis(ax)
streamer([p.name,' Figure 14']);
orient tall