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