author | A.M. Thurnherr <athurnherr@yahoo.com> |
Sun, 13 Mar 2016 12:33:20 +0000 | |
changeset 39 | 91458506d56f |
parent 34 | e550db661c17 |
child 46 | cc6c4309828a |
permissions | -rw-r--r-- |
0 | 1 |
#====================================================================== |
2 |
# B O T T O M _ T R A C K I N G . P L |
|
3 |
# doc: Wed Oct 20 21:05:37 2010 |
|
34 | 4 |
# dlm: Tue Jan 26 15:25:14 2016 |
0 | 5 |
# (c) 2010 A.M. Thurnherr |
34 | 6 |
# uE-Info: 16 33 NIL 0 0 72 2 2 4 NIL ofnI |
0 | 7 |
#====================================================================== |
8 |
||
9 |
# HISTORY: |
|
10 |
# Oct 20, 2010: - created |
|
11 |
# Dec 30, 2010: - adapted for use with LADCP_w |
|
4
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
12 |
# Oct 11, 2011: - moved defaults to [defaults.pl] |
5
509cc9966b68
======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
4
diff
changeset
|
13 |
# Oct 24, 2011: - disabled not-very-useful %BT-params |
13 | 14 |
# Apr 22, 2013: - replace output_bin_size by opt_o |
15 | 15 |
# Mar 4, 2014: - removed old unused code |
34 | 16 |
# Jan 26, 2016: - added %PARAMs |
0 | 17 |
|
18 |
# This code is essentially identical to the one used in LADCPproc. Differences: |
|
19 |
# 1) velocity editing is simpler: no wake editing, no PPI editing, no shear |
|
20 |
# editing, no w outlier |
|
21 |
# 2) median/mad calculated instead of mean/stddev |
|
22 |
# 3) u,v not calculated |
|
23 |
||
24 |
#---------------------------------------------------------------------- |
|
25 |
# bin valid BT-referenced velocities |
|
26 |
# input: ensemble number, water depth (with uncertainty) |
|
27 |
# output: @BTu,@BTv,@BTw main result |
|
28 |
# editflags for information |
|
29 |
#---------------------------------------------------------------------- |
|
30 |
||
31 |
my($nBTfound,$nBTdepthFlag,$nBTvalidVelFlag,$nBTwFlag) = (0,0,0,0); |
|
32 |
my(@BTu,@BTv,@BTw); |
|
33 |
||
34 |
sub binBTprof($$$) |
|
35 |
{ |
|
36 |
my($ens,$wd,$sig_wd) = @_; |
|
37 |
||
38 |
my(@ea_max) = (0,0,0,0); my(@ea_max_bin) = (nan,nan,nan,nan); |
|
39 |
for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) { |
|
40 |
$ea_max[0] = $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][0], |
|
41 |
$ea_max_bin[0] = $bin |
|
42 |
if ($LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][0] > $ea_max[0]); |
|
43 |
$ea_max[1] = $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][1], |
|
44 |
$ea_max_bin[1] = $bin |
|
45 |
if ($LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][1] > $ea_max[1]); |
|
46 |
$ea_max[2] = $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][2], |
|
47 |
$ea_max_bin[2] = $bin |
|
48 |
if ($LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][2] > $ea_max[2]); |
|
49 |
$ea_max[3] = $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][3], |
|
50 |
$ea_max_bin[3] = $bin |
|
51 |
if ($LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][3] > $ea_max[3]); |
|
52 |
} |
|
53 |
||
54 |
return # disregard boundary maxima |
|
55 |
unless (min(@ea_max_bin) > $LADCP_firstBin-1) && |
|
56 |
(max(@ea_max_bin) < $LADCP_lastBin-1); |
|
57 |
return # inconsistent range to seabed |
|
58 |
unless (max(@ea_max_bin)-min(@ea_max_bin) <= $BT_max_bin_range_diff); |
|
59 |
||
60 |
$nBTfound++; |
|
61 |
my($seafloor_bin) = round(avg(@ea_max_bin)); |
|
62 |
||
63 |
my(@bd) = calc_binDepths($ens); |
|
64 |
$nBTdepthFlag++,return # BT range inconsistent with water depth |
|
65 |
unless (abs($wd-$bd[$seafloor_bin]) < max($sig_wd,$LADCP{BIN_LENGTH})); |
|
66 |
||
67 |
# try vertical velocities at seabed bin plus one above and below |
|
68 |
# this does not really work because, often, only one of the bins has valid velocities |
|
69 |
my($w1) = $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$seafloor_bin-1]; |
|
70 |
my($w2) = $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$seafloor_bin ]; |
|
71 |
my($w3) = $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$seafloor_bin+1]; |
|
72 |
||
73 |
$w1 = 9e99 unless numberp($w1); # invalid velocity sentinels |
|
74 |
$w2 = 9e99 unless numberp($w1); |
|
75 |
$w3 = 9e99 unless numberp($w1); |
|
76 |
||
77 |
my($seafloor_u,$seafloor_v,$seafloor_w); |
|
78 |
||
79 |
# determine which of the three trial bins is most consistent with reflr vertical velocities |
|
13 | 80 |
return # can happen when no MEDIAN_RESIDUAL_W is available |
81 |
unless numberp($LADCP{ENSEMBLE}[$ens]->{REFLR_W}); |
|
0 | 82 |
if (abs($LADCP{ENSEMBLE}[$ens]->{REFLR_W}-$w1) < abs($LADCP{ENSEMBLE}[$ens]->{REFLR_W}-$w2) && |
83 |
abs($LADCP{ENSEMBLE}[$ens]->{REFLR_W}-$w1) < abs($LADCP{ENSEMBLE}[$ens]->{REFLR_W}-$w3)) { |
|
84 |
$seafloor_u = $LADCP{ENSEMBLE}[$ens]->{U_UNEDITED}[$seafloor_bin-1]; |
|
85 |
$seafloor_v = $LADCP{ENSEMBLE}[$ens]->{V_UNEDITED}[$seafloor_bin-1]; |
|
86 |
$seafloor_w = $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$seafloor_bin-1]; |
|
87 |
} elsif (abs($LADCP{ENSEMBLE}[$ens]->{REFLR_W}-$w1) < abs($LADCP{ENSEMBLE}[$ens]->{REFLR_W}-$w2)) { |
|
88 |
$seafloor_u = $LADCP{ENSEMBLE}[$ens]->{U_UNEDITED}[$seafloor_bin+1]; |
|
89 |
$seafloor_v = $LADCP{ENSEMBLE}[$ens]->{V_UNEDITED}[$seafloor_bin+1]; |
|
90 |
$seafloor_w = $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$seafloor_bin+1]; |
|
91 |
} else { |
|
92 |
$nBTvalidVelFlag++,return # none of 3 trial bins has valid velocity |
|
93 |
if ($w2 == 9e99); |
|
94 |
$seafloor_u = $LADCP{ENSEMBLE}[$ens]->{U_UNEDITED}[$seafloor_bin]; |
|
95 |
$seafloor_v = $LADCP{ENSEMBLE}[$ens]->{V_UNEDITED}[$seafloor_bin]; |
|
96 |
$seafloor_w = $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$seafloor_bin]; |
|
97 |
} |
|
98 |
||
99 |
$nBTwFlag++,return # velocity error is too great |
|
100 |
if (abs($seafloor_w-$LADCP{ENSEMBLE}[$ens]->{REFLR_W}) > $BT_max_w_error); |
|
101 |
||
102 |
for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) { |
|
103 |
next unless defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]); |
|
13 | 104 |
my($gi) = int($bd[$bin]) / $opt_o; |
0 | 105 |
push(@{$BTw[$gi]},$LADCP{ENSEMBLE}[$ens]->{W}[$bin]-$seafloor_w); |
106 |
} |
|
107 |
} |
|
108 |
||
109 |
#---------------------------------------------------------------------- |
|
110 |
# calculate BT-referenced velocity profile |
|
111 |
# input: start,end LADCP ensembles, water depth with uncertainty |
|
112 |
# output: %BT{MEDIAN_W,MAD_W,N_SAMP} |
|
113 |
#---------------------------------------------------------------------- |
|
114 |
||
115 |
sub calc_BTprof($$$$) |
|
116 |
{ |
|
117 |
my($LADCP_start,$LADCP_end,$wd,$sig_wd) = @_; |
|
118 |
||
34 | 119 |
&antsAddParams('BT_max_range',$BT_max_range, |
120 |
'BT_max_bin_range_diff',$BT_max_bin_range_diff, |
|
121 |
'BT_max_w_error',$BT_max_w_error); |
|
122 |
||
0 | 123 |
for (my($ens)=$LADCP_start; $ens<=$LADCP_end; $ens++) { |
124 |
next unless ($wd-$LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH} < $BT_max_range); |
|
125 |
binBTprof($ens,$wd,$sig_wd); |
|
126 |
} |
|
127 |
||
128 |
progress("\t$nBTfound BT ensembles found\n"); |
|
129 |
progress("\t$nBTdepthFlag flagged bad because of wrong bottom depth\n"); |
|
130 |
progress("\t$nBTvalidVelFlag flagged bad because of no valid velocities\n"); |
|
131 |
progress("\t$nBTwFlag flagged bad because of incorrect vertical velocity\n"); |
|
132 |
||
133 |
for (my($gi)=0; $gi<@BTw; $gi++) { # calc grid medians & mads |
|
134 |
$BT{N_SAMP}[$gi] = @{$BTw[$gi]}; |
|
135 |
$BT{MEDIAN_W}[$gi] = median(@{$BTw[$gi]}); |
|
136 |
$BT{MAD_W}[$gi] = mad2($BT{W}[$gi],@{$BTw[$gi]}); |
|
137 |
} |
|
138 |
} |
|
139 |
||
140 |
1; |