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