author | A.M. Thurnherr <athurnherr@yahoo.com> |
Wed, 28 Aug 2019 17:51:34 -0400 | |
changeset 52 | 4ccccbf69dfd |
parent 49 | 5006e9158207 |
child 56 | 8f120b9f795a |
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 |
|
49 | 4 |
# dlm: Tue May 1 21:48:54 2018 |
0 | 5 |
# (c) 2010 A.M. Thurnherr |
49 | 6 |
# uE-Info: 21 14 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 |
46 | 17 |
# May 24, 2016: - calc_binDepths() -> binDepths() |
49 | 18 |
# May 1, 2018: - log-file cosmetics |
0 | 19 |
|
49 | 20 |
# This code is derived from the one used in LADCPproc, with the following |
21 |
# differences: |
|
0 | 22 |
# 1) velocity editing is simpler: no wake editing, no PPI editing, no shear |
23 |
# editing, no w outlier |
|
24 |
# 2) median/mad calculated instead of mean/stddev |
|
25 |
# 3) u,v not calculated |
|
26 |
||
27 |
#---------------------------------------------------------------------- |
|
28 |
# bin valid BT-referenced velocities |
|
29 |
# input: ensemble number, water depth (with uncertainty) |
|
30 |
# output: @BTu,@BTv,@BTw main result |
|
31 |
# editflags for information |
|
32 |
#---------------------------------------------------------------------- |
|
33 |
||
34 |
my($nBTfound,$nBTdepthFlag,$nBTvalidVelFlag,$nBTwFlag) = (0,0,0,0); |
|
35 |
my(@BTu,@BTv,@BTw); |
|
36 |
||
37 |
sub binBTprof($$$) |
|
38 |
{ |
|
39 |
my($ens,$wd,$sig_wd) = @_; |
|
40 |
||
41 |
my(@ea_max) = (0,0,0,0); my(@ea_max_bin) = (nan,nan,nan,nan); |
|
42 |
for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) { |
|
43 |
$ea_max[0] = $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][0], |
|
44 |
$ea_max_bin[0] = $bin |
|
45 |
if ($LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][0] > $ea_max[0]); |
|
46 |
$ea_max[1] = $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][1], |
|
47 |
$ea_max_bin[1] = $bin |
|
48 |
if ($LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][1] > $ea_max[1]); |
|
49 |
$ea_max[2] = $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][2], |
|
50 |
$ea_max_bin[2] = $bin |
|
51 |
if ($LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][2] > $ea_max[2]); |
|
52 |
$ea_max[3] = $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][3], |
|
53 |
$ea_max_bin[3] = $bin |
|
54 |
if ($LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][3] > $ea_max[3]); |
|
55 |
} |
|
56 |
||
57 |
return # disregard boundary maxima |
|
58 |
unless (min(@ea_max_bin) > $LADCP_firstBin-1) && |
|
59 |
(max(@ea_max_bin) < $LADCP_lastBin-1); |
|
60 |
return # inconsistent range to seabed |
|
61 |
unless (max(@ea_max_bin)-min(@ea_max_bin) <= $BT_max_bin_range_diff); |
|
62 |
||
63 |
$nBTfound++; |
|
64 |
my($seafloor_bin) = round(avg(@ea_max_bin)); |
|
65 |
||
46 | 66 |
my(@bd) = binDepths($ens); |
0 | 67 |
$nBTdepthFlag++,return # BT range inconsistent with water depth |
68 |
unless (abs($wd-$bd[$seafloor_bin]) < max($sig_wd,$LADCP{BIN_LENGTH})); |
|
69 |
||
70 |
# try vertical velocities at seabed bin plus one above and below |
|
71 |
# this does not really work because, often, only one of the bins has valid velocities |
|
72 |
my($w1) = $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$seafloor_bin-1]; |
|
73 |
my($w2) = $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$seafloor_bin ]; |
|
74 |
my($w3) = $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$seafloor_bin+1]; |
|
75 |
||
76 |
$w1 = 9e99 unless numberp($w1); # invalid velocity sentinels |
|
77 |
$w2 = 9e99 unless numberp($w1); |
|
78 |
$w3 = 9e99 unless numberp($w1); |
|
79 |
||
80 |
my($seafloor_u,$seafloor_v,$seafloor_w); |
|
81 |
||
82 |
# determine which of the three trial bins is most consistent with reflr vertical velocities |
|
13 | 83 |
return # can happen when no MEDIAN_RESIDUAL_W is available |
84 |
unless numberp($LADCP{ENSEMBLE}[$ens]->{REFLR_W}); |
|
0 | 85 |
if (abs($LADCP{ENSEMBLE}[$ens]->{REFLR_W}-$w1) < abs($LADCP{ENSEMBLE}[$ens]->{REFLR_W}-$w2) && |
86 |
abs($LADCP{ENSEMBLE}[$ens]->{REFLR_W}-$w1) < abs($LADCP{ENSEMBLE}[$ens]->{REFLR_W}-$w3)) { |
|
87 |
$seafloor_u = $LADCP{ENSEMBLE}[$ens]->{U_UNEDITED}[$seafloor_bin-1]; |
|
88 |
$seafloor_v = $LADCP{ENSEMBLE}[$ens]->{V_UNEDITED}[$seafloor_bin-1]; |
|
89 |
$seafloor_w = $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$seafloor_bin-1]; |
|
90 |
} elsif (abs($LADCP{ENSEMBLE}[$ens]->{REFLR_W}-$w1) < abs($LADCP{ENSEMBLE}[$ens]->{REFLR_W}-$w2)) { |
|
91 |
$seafloor_u = $LADCP{ENSEMBLE}[$ens]->{U_UNEDITED}[$seafloor_bin+1]; |
|
92 |
$seafloor_v = $LADCP{ENSEMBLE}[$ens]->{V_UNEDITED}[$seafloor_bin+1]; |
|
93 |
$seafloor_w = $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$seafloor_bin+1]; |
|
94 |
} else { |
|
95 |
$nBTvalidVelFlag++,return # none of 3 trial bins has valid velocity |
|
96 |
if ($w2 == 9e99); |
|
97 |
$seafloor_u = $LADCP{ENSEMBLE}[$ens]->{U_UNEDITED}[$seafloor_bin]; |
|
98 |
$seafloor_v = $LADCP{ENSEMBLE}[$ens]->{V_UNEDITED}[$seafloor_bin]; |
|
99 |
$seafloor_w = $LADCP{ENSEMBLE}[$ens]->{W_UNEDITED}[$seafloor_bin]; |
|
100 |
} |
|
101 |
||
102 |
$nBTwFlag++,return # velocity error is too great |
|
103 |
if (abs($seafloor_w-$LADCP{ENSEMBLE}[$ens]->{REFLR_W}) > $BT_max_w_error); |
|
104 |
||
105 |
for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) { |
|
106 |
next unless defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]); |
|
13 | 107 |
my($gi) = int($bd[$bin]) / $opt_o; |
0 | 108 |
push(@{$BTw[$gi]},$LADCP{ENSEMBLE}[$ens]->{W}[$bin]-$seafloor_w); |
109 |
} |
|
110 |
} |
|
111 |
||
112 |
#---------------------------------------------------------------------- |
|
113 |
# calculate BT-referenced velocity profile |
|
114 |
# input: start,end LADCP ensembles, water depth with uncertainty |
|
115 |
# output: %BT{MEDIAN_W,MAD_W,N_SAMP} |
|
116 |
#---------------------------------------------------------------------- |
|
117 |
||
118 |
sub calc_BTprof($$$$) |
|
119 |
{ |
|
120 |
my($LADCP_start,$LADCP_end,$wd,$sig_wd) = @_; |
|
121 |
||
34 | 122 |
&antsAddParams('BT_max_range',$BT_max_range, |
123 |
'BT_max_bin_range_diff',$BT_max_bin_range_diff, |
|
124 |
'BT_max_w_error',$BT_max_w_error); |
|
125 |
||
0 | 126 |
for (my($ens)=$LADCP_start; $ens<=$LADCP_end; $ens++) { |
127 |
next unless ($wd-$LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH} < $BT_max_range); |
|
128 |
binBTprof($ens,$wd,$sig_wd); |
|
129 |
} |
|
130 |
||
131 |
progress("\t$nBTfound BT ensembles found\n"); |
|
132 |
progress("\t$nBTdepthFlag flagged bad because of wrong bottom depth\n"); |
|
133 |
progress("\t$nBTvalidVelFlag flagged bad because of no valid velocities\n"); |
|
49 | 134 |
progress("\t$nBTwFlag flagged bad because of inconsistent vertical velocity\n"); |
0 | 135 |
|
136 |
for (my($gi)=0; $gi<@BTw; $gi++) { # calc grid medians & mads |
|
137 |
$BT{N_SAMP}[$gi] = @{$BTw[$gi]}; |
|
138 |
$BT{MEDIAN_W}[$gi] = median(@{$BTw[$gi]}); |
|
139 |
$BT{MAD_W}[$gi] = mad2($BT{W}[$gi],@{$BTw[$gi]}); |
|
140 |
} |
|
141 |
} |
|
142 |
||
143 |
1; |