author | Andreas Thurnherr <ant@ldeo.columbia.edu> |
Mon, 08 Mar 2021 07:58:53 -0500 | |
changeset 57 | 5a59411306ba |
parent 43 | b63fa355644c |
permissions | -rwxr-xr-x |
0 | 1 |
#!/usr/bin/perl |
2 |
#====================================================================== |
|
3 |
# L I S T B T |
|
4 |
# doc: Sat Jan 18 18:41:49 2003 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
14
diff
changeset
|
5 |
# dlm: Mon Apr 2 18:31:18 2018 |
0 | 6 |
# (c) 2003 A.M. Thurnherr |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
14
diff
changeset
|
7 |
# uE-Info: 43 61 NIL 0 0 72 11 2 4 NIL ofnI |
0 | 8 |
#====================================================================== |
9 |
||
10 |
# Extract Bottom-Track Data |
|
11 |
||
12 |
# NOTE: NO SOUND-SPEED CORRECTION APPLIED YET!!! |
|
13 |
||
14 |
# HISTORY: |
|
15 |
# Jan 18, 2003: - created |
|
16 |
# Jan 23, 2003: - added magnetic declination |
|
17 |
# Jan 25, 2003: - continued construction |
|
18 |
# Feb 11, 2003: - finally made it work |
|
19 |
# Feb 12, 2003: - added default profile output |
|
20 |
# Feb 13, 2003: - corrected raw output |
|
21 |
# Feb 14, 2003: - added errors if instrument-BT filters are more strict |
|
22 |
# than command-line values |
|
23 |
# Feb 18, 2003: - removed -d dependency on -W |
|
24 |
# Mar 3, 2003: - added -C)ompass correction |
|
25 |
# Mar 10, 2003: - added -f)orce to allow visbeck-style post processing |
|
26 |
# Mar 16, 2003: - added range comment |
|
27 |
# Feb 26, 2004: - added Earth-coordinate support |
|
28 |
# Feb 27, 2004: - made water-track calculation conditional (-E || -B) |
|
29 |
# Mar 9, 2004: - added magnetic_declination to %PARAMs |
|
30 |
# Apr 1, 2004: - added CTD u/v stats to %PARAMs |
|
31 |
# Apr 2, 2004: - added CTD_msf (mean square fluctuation) stat |
|
32 |
# Apr 3, 2004: - BUG: CTD vels were repeated for stats |
|
33 |
# - removed non-ANTS option |
|
34 |
# Nov 8, 2005: - UNIXTIME => UNIX_TIME |
|
35 |
# - adapted to new binary read library |
|
36 |
# - output editing statistics |
|
37 |
# Aug 15, 2006: - added -b |
|
38 |
# Aug 25, 2006: - fiddled |
|
39 |
# Sep 19, 2007: - adapted to new [RDI_BB_Read.pl] (not tested) |
|
40 |
# Nov 1, 2008: - BUG: sig(u) was reported instead of sig(v) |
|
41 |
# Jul 30, 2009: - NaN => nan |
|
14 | 42 |
# Nov 25, 2013: - checkEnsemble() expunged |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
14
diff
changeset
|
43 |
# Apr 2, 2018: - BUG: velBeamToInstrument() used old usage |
0 | 44 |
|
45 |
# NOTES: |
|
46 |
# - the RDI BT data contains ranges that are greater than the |
|
47 |
# WT ping ranges. I don't know if those data are valid! |
|
48 |
# - there is a fair bit of heuristic used, especially in the |
|
49 |
# reference-layer calculation |
|
50 |
# - depth-correction (-m) is highly recommended because it allows |
|
51 |
# much better bad-BT detection and it is required for a valid |
|
52 |
# comparison with LADCP profiles |
|
53 |
# - the criterion for bottom-interference of the water-track data |
|
54 |
# is derived from Firing's [merge.c] (adding 1.5 bin lengths to |
|
55 |
# the calculated range), modified by taking the real beam angle |
|
56 |
# into account. |
|
57 |
# - from the RDI manuals it is not entirely clear whether the BT range |
|
58 |
# is given in vertical or in along-beam meters; comparison with the |
|
59 |
# WT range (calculated from the bin with the maximum echo amplitude) |
|
60 |
# shows that vertical meters are used |
|
61 |
||
62 |
# NOTES on quality checks: |
|
63 |
# -a minimum BT amplitude; setting this to 50 (RDI default is 30) |
|
64 |
# reduces the vertical range over which the bottom is detected but |
|
65 |
# not the quality of the bottom track data; therefore, this should |
|
66 |
# probably not be used. |
|
67 |
# -c minimum BT correlation; the RDI default for this parameter is 220, |
|
68 |
# which seems to work fine. |
|
69 |
# -e max error velocity (BT & WT); this is primarily used for detecting |
|
70 |
# good BT data, i.e. it should be set to a small value (Firing uses |
|
71 |
# 0.1m/s in merge); if too small a value is chosen too many good |
|
72 |
# data are discarded; note that the same error-velocity criterion |
|
73 |
# is used to separate good from bad data when mean profiles are |
|
74 |
# constructed. |
|
75 |
# -w max difference between reference-layer w and BT w; this is a |
|
76 |
# powerful criterion for determining good BT data; I like a value of |
|
77 |
# 0.03 m/s. |
|
78 |
# -d when the depth is corrected (-m) the... |
|
79 |
||
80 |
$0 =~ m{(.*)/[^/]+}; |
|
81 |
require "$1/RDI_BB_Read.pl"; |
|
82 |
require "$1/RDI_Coords.pl"; |
|
83 |
require "$1/RDI_Utils.pl"; |
|
84 |
use Getopt::Std; |
|
85 |
||
86 |
$USAGE = "$0 @ARGV"; |
|
87 |
die("Usage: $0 " . |
|
88 |
"[use -b)ins <1st,last>] " . |
|
89 |
"[write -R)aw data] [write -B)T data] " . |
|
90 |
"[write -E)nsembles <pref>] [-F)ilter ensembles <script>] " . |
|
91 |
"[-C)ompass correction <amp/phase/bias>] " . |
|
92 |
"[-w) <max-diff|0.03>] [-a)mp <min|30>] [-e)rr-vel <max|0.05>] " . |
|
93 |
"[-c)orrelation <min|220>] " . |
|
94 |
"[-W)ater <depth> [allowed -d)epth-diff <maxdiff|20>]] " . |
|
95 |
"[-f)orce (no setup tests)] " . |
|
96 |
"[-M)agnetic <declination>] " . |
|
97 |
"<RDI file>\n") |
|
98 |
unless (&getopts("BC:E:F:M:RW:a:b:c:d:e:fw:") && @ARGV == 1); |
|
99 |
||
100 |
print(STDERR "WARNING: magnetic declination not set!\n") |
|
101 |
unless defined($opt_M); |
|
102 |
||
103 |
$opt_c = 220 unless defined($opt_c); # defaults |
|
104 |
$opt_a = 30 unless defined($opt_a); |
|
105 |
$opt_e = 0.05 unless defined($opt_e); |
|
106 |
$opt_w = 0.03 unless defined($opt_w); |
|
107 |
$opt_d = 20 unless defined($opt_d); |
|
108 |
||
109 |
if (defined($opt_C)) { # compass correction |
|
110 |
($CC_amp,$CC_phase,$CC_bias) = split('/',$opt_C); |
|
111 |
die("$0: can't decode -C$opt_C\n") |
|
112 |
unless defined($CC_bias); |
|
113 |
} |
|
114 |
||
115 |
unless ($opt_f) { # check BT setup |
|
116 |
readHeader($ARGV[0],\%dta); |
|
117 |
die("$0: minimum instrument BT correlation ($dta{BT_MIN_CORRELATION}) " . |
|
118 |
"too large for selected criterion (-c $opt_c) --- use -f to override\n") |
|
119 |
if ($dta{BT_MIN_CORRELATION} > $opt_c); |
|
120 |
die("$0: minimum instrument BT amplitude ($dta{BT_MIN_EVAL_AMPLITUDE}) " . |
|
121 |
"too large for selected criterion (-a $opt_a) --- use -f to override\n") |
|
122 |
if ($dta{BT_MIN_EVAL_AMPLITUDE} > $opt_a); |
|
123 |
die("$0: maximum instrument BT error velocity ($dta{BT_MAX_ERROR_VELOCITY}) " . |
|
124 |
"too small for selected criterion (-e $opt_e) --- use -f to override\n") |
|
1 | 125 |
if (defined($dta{BT_MAX_ERROR_VELOCITY}) && $dta{BT_MAX_ERROR_VELOCITY} < $opt_e); |
0 | 126 |
} |
127 |
||
128 |
require $opt_F if defined($opt_F); # load filter |
|
129 |
||
130 |
print(STDERR "reading $ARGV[0]..."); |
|
131 |
readData($ARGV[0],\%dta); # read data |
|
132 |
print(STDERR "done\n"); |
|
133 |
||
134 |
$dta{HEADING_BIAS} = -$opt_M; # magnetic declination |
|
135 |
ensure_BT_RANGE(\%dta); # make sure they're there |
|
136 |
||
137 |
$firstBin = $lastBin = '*'; # bins to use |
|
138 |
($firstBin,$lastBin) = split(',',$opt_b) |
|
139 |
if defined($opt_b); |
|
140 |
$firstBin = 1 if ($firstBin eq '*'); |
|
141 |
$lastBin = $dta{N_BINS} if ($lastBin eq '*'); |
|
142 |
$firstBin--; $lastBin--; |
|
143 |
die("$ARGV[0]: not enough bins for ref layer\n") |
|
144 |
unless ($lastBin-$firstBin >= 6); |
|
145 |
||
146 |
if ($dta{BEAM_COORDINATES}) { # coords used |
|
147 |
$beamCoords = 1; |
|
148 |
} elsif (!$dta{EARTH_COORDINATES}) { |
|
149 |
die("$ARGV[0]: only beam and earth coordinates implemented so far\n"); |
|
150 |
} |
|
151 |
||
152 |
#====================================================================== |
|
153 |
# Calculate reference-layer w |
|
154 |
#====================================================================== |
|
155 |
||
156 |
sub w($) |
|
157 |
{ |
|
158 |
my($ens) = @_; |
|
159 |
my($i,$n,@v,$w); |
|
160 |
||
161 |
for (my($b)=$firstBin; $b<=$lastBin; $b++) { |
|
162 |
if ($beamCoords) { |
|
163 |
next if ($dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$b][0] < 100 || |
|
164 |
$dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$b][1] < 100 || |
|
165 |
$dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$b][2] < 100 || |
|
166 |
$dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$b][3] < 100); |
|
167 |
@v = velInstrumentToEarth(\%dta,$ens, |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
14
diff
changeset
|
168 |
velBeamToInstrument(\%dta,$ens, |
0 | 169 |
@{$dta{ENSEMBLE}[$ens]->{VELOCITY}[$b]})); |
170 |
} else { |
|
171 |
next if ($dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$b][0] > 0 || |
|
172 |
$dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$b][1] > 0 || |
|
173 |
$dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$b][2] > 0 || |
|
174 |
$dta{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$b][3] < 100); |
|
175 |
@v = velApplyHdgBias(\%dta,$ens, |
|
176 |
@{$dta{ENSEMBLE}[$ens]->{VELOCITY}[$b]}); |
|
177 |
} |
|
178 |
next unless (defined($v[3]) && abs($v[3]) <= $opt_e); |
|
179 |
$w += $v[2]; $n++; |
|
180 |
} |
|
181 |
# printf(STDERR "$ens $n %.3f\n",$n>=1?$w/$n:-999); |
|
182 |
return $n>=2 ? $w/$n : undef; |
|
183 |
} |
|
184 |
||
185 |
#====================================================================== |
|
186 |
# Dump raw BT data from one ensemble |
|
187 |
#====================================================================== |
|
188 |
||
189 |
sub dumpRaw($) |
|
190 |
{ |
|
191 |
my($e) = @_; |
|
192 |
||
193 |
unless ($headerDone) { |
|
194 |
print("#ANTS# [] $USAGE\n"); |
|
195 |
print("#ANTS#PARAMS# RDI_file{$ARGV[0]}\n"); |
|
196 |
print("#ANTS#FIELDS# {ens} {range1} {range2} {range3} {range4} " . |
|
197 |
"{beamvel1} {beamvel2} {beamvel3} {beamvel4} {cor1} " . |
|
198 |
"{cor2} {cor3} {cor4} {amp1} {amp2} {amp3} {amp4}\n"); |
|
199 |
$headerDone = 1; |
|
200 |
} |
|
201 |
||
202 |
printf("%d %f %f %f %f %f %f %f %f %d %d %d %d %d %d %d %d\n", |
|
203 |
$dta{ENSEMBLE}[$e]->{NUMBER}, |
|
204 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[0], |
|
205 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[1], |
|
206 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[2], |
|
207 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[3], |
|
208 |
$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[0], |
|
209 |
$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[1], |
|
210 |
$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[2], |
|
211 |
$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[3], |
|
212 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[0], |
|
213 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[1], |
|
214 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[2], |
|
215 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[3], |
|
216 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[0], |
|
217 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[1], |
|
218 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[2], |
|
219 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[3] |
|
220 |
); |
|
221 |
} |
|
222 |
||
223 |
#====================================================================== |
|
224 |
# Dump processed BT data from one ensemble |
|
225 |
#====================================================================== |
|
226 |
||
227 |
sub dumpBT($) |
|
228 |
{ |
|
229 |
my($e) = @_; |
|
230 |
||
231 |
unless ($headerDone) { |
|
232 |
print("#ANTS# [] $USAGE\n"); |
|
233 |
printf("#ANTS#PARAMS# RDI_file{$ARGV[0]} bottom_time{%.1f}\n", |
|
234 |
$dta{ENSEMBLE}[$maxz_e]->{ELAPSED}); |
|
235 |
print("#ANTS#FIELDS# {ens} {unix_time} {time} {depth} {BT_range} " . |
|
236 |
"{WT_range} {u} {v} {w} {e} {w_ref} {corr} {amp}\n"); |
|
237 |
$headerDone = 1; |
|
238 |
} |
|
239 |
||
240 |
printf("%d %.2f %.2f %.1f %.1f %.1f %.4f %.4f %.4f %.4f %.4f %.1f %.1f\n", |
|
241 |
$dta{ENSEMBLE}[$e]->{NUMBER}, |
|
242 |
$dta{ENSEMBLE}[$e]->{UNIX_TIME}, |
|
243 |
$dta{ENSEMBLE}[$e]->{ELAPSED}, |
|
244 |
$dta{ENSEMBLE}[$e]->{DEPTH}, |
|
245 |
$dta{ENSEMBLE}[$e]->{BT_MEAN_RANGE}, |
|
246 |
$dta{ENSEMBLE}[$e]->{WT_MEAN_RANGE}, |
|
247 |
@{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}}, |
|
248 |
$dta{ENSEMBLE}[$e]->{W_REF}, |
|
249 |
$dta{ENSEMBLE}[$e]->{BT_MEAN_CORRELATION}, |
|
250 |
$dta{ENSEMBLE}[$e]->{BT_MEAN_EVAL_AMPLITUDE} |
|
251 |
); |
|
252 |
} |
|
253 |
||
254 |
#====================================================================== |
|
255 |
# Dump a single ensemble with valid BT data to separate file |
|
256 |
#====================================================================== |
|
257 |
||
258 |
sub dumpEns(@) # write profile |
|
259 |
{ |
|
260 |
my($e) = @_; |
|
261 |
my($b,$i); |
|
262 |
||
263 |
open(P,">$opt_E.$e") || die("$opt_E.$e: $!\n"); |
|
264 |
print(P "#ANTS#PARAMS# " . |
|
265 |
"depth{$dta{ENSEMBLE}[$e]->{DEPTH}} " . |
|
266 |
"range{$dta{ENSEMBLE}[$e]->{BT_MEAN_RANGE}} " . |
|
267 |
"wt_range{$dta{ENSEMBLE}[$e]->{WT_MEAN_RANGE}} " . |
|
268 |
"w_ref{$dta{ENSEMBLE}[$e]->{W_REF}} " . |
|
269 |
"BT_u{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[0]} " . |
|
270 |
"BT_v{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[1]} " . |
|
271 |
"BT_w{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[2]} " . |
|
272 |
"BT_e{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[3]} " . |
|
273 |
"BT_cor1{$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[0]} " . |
|
274 |
"BT_cor2{$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[1]} " . |
|
275 |
"BT_cor3{$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[2]} " . |
|
276 |
"BT_cor4{$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[3]} " . |
|
277 |
"BT_amp1{$dta{ENSEMBLE}[$e]->{BT_AMPLITUDE}[0]} " . |
|
278 |
"BT_amp2{$dta{ENSEMBLE}[$e]->{BT_AMPLITUDE}[1]} " . |
|
279 |
"BT_amp3{$dta{ENSEMBLE}[$e]->{BT_AMPLITUDE}[2]} " . |
|
280 |
"BT_amp4{$dta{ENSEMBLE}[$e]->{BT_AMPLITUDE}[3]} " . |
|
281 |
"BTFWT_u{$dta{ENSEMBLE}[$e]->{BTFWT_VELOCITY}[0]} " . |
|
282 |
"BTFWT_v{$dta{ENSEMBLE}[$e]->{BTFWT_VELOCITY}[1]} " . |
|
283 |
"BTFWT_w{$dta{ENSEMBLE}[$e]->{BTFWT_VELOCITY}[2]} " . |
|
284 |
"\n" |
|
285 |
); |
|
286 |
print(P "#ANTS#FIELDS# " . |
|
287 |
"{depth} {hab} {u} {v} {w} {e} {cor1} {cor2} {cor3} {cor4} " . |
|
288 |
"{amp1} {amp2} {amp3} {amp4} {pcg1} {pcg2} {pcg3} {pcg4}\n" |
|
289 |
); |
|
290 |
||
291 |
my($slc) = (1-cos(rad($dta{BEAM_ANGLE})))*$dta{ENSEMBLE}[$e]->{BT_MEAN_RANGE} |
|
292 |
+ 1.5*$dta{BIN_LENGTH}; # side-lobe contamination |
|
293 |
for ($b=$firstBin; $b<=$lastBin; $b++) { |
|
294 |
next unless (defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0]) && |
|
295 |
defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1]) && |
|
296 |
defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2]) && |
|
297 |
defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3])); |
|
298 |
my($dz) = $dta{DISTANCE_TO_BIN1_CENTER} + $b*$dta{BIN_LENGTH}; |
|
299 |
last if ($dta{ENSEMBLE}[$e]->{BT_MEAN_RANGE}-$dz <= $slc); |
|
300 |
my(@v) = $beamCoords |
|
301 |
? velInstrumentToEarth(\%dta,$e, |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
14
diff
changeset
|
302 |
velBeamToInstrument(\%dta,$e, |
0 | 303 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]})) |
304 |
: velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}); |
|
305 |
next unless defined($v[0]); |
|
306 |
next if (abs($v[3]) > $opt_e || |
|
307 |
abs($v[2]-$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[2]) > 0.1); |
|
308 |
$v[0] -= $dta{ENSEMBLE}[$e]->{BT_VELOCITY}[0]; |
|
309 |
$v[1] -= $dta{ENSEMBLE}[$e]->{BT_VELOCITY}[1]; |
|
310 |
my(@out) = ( |
|
311 |
$dta{ENSEMBLE}[$e]->{DEPTH}+$dz, |
|
312 |
$dta{ENSEMBLE}[$e]->{BT_MEAN_RANGE}-$dz, |
|
313 |
$v[0],$v[1],$v[2],$v[3], |
|
314 |
@{$dta{ENSEMBLE}[$e]->{CORRELATION}[$b]}, |
|
315 |
@{$dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b]}, |
|
316 |
@{$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[$b]} |
|
317 |
); |
|
318 |
for ($i=0; $i<17; $i++) { $out[$i] = nan unless defined($out[$i]); } |
|
319 |
print(P "@out\n"); |
|
320 |
} |
|
321 |
close(P); |
|
322 |
} |
|
323 |
||
324 |
#====================================================================== |
|
325 |
# Add Ensemble With Valid BT Data to Profile |
|
326 |
#====================================================================== |
|
327 |
||
328 |
sub binEns($) |
|
329 |
{ |
|
330 |
my($e) = @_; |
|
331 |
my($slc) = (1-cos(rad($dta{BEAM_ANGLE})))*$dta{ENSEMBLE}[$e]->{BT_MEAN_RANGE} |
|
332 |
+ 1.5*$dta{BIN_LENGTH}; # side-lobe contamination |
|
333 |
for (my($b)=$firstBin; $b<=$lastBin; $b++) { |
|
334 |
next unless (defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][0]) && |
|
335 |
defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][1]) && |
|
336 |
defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][2]) && |
|
337 |
defined($dta{ENSEMBLE}[$e]->{VELOCITY}[$b][3])); |
|
338 |
my($dz) = $dta{DISTANCE_TO_BIN1_CENTER} + $b*$dta{BIN_LENGTH}; |
|
339 |
last if ($dta{ENSEMBLE}[$e]->{BT_MEAN_RANGE}-$dz <= $slc); |
|
340 |
my(@v) = $beamCoords |
|
341 |
? velInstrumentToEarth(\%dta,$e, |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
14
diff
changeset
|
342 |
velBeamToInstrument(\%dta,$e, |
0 | 343 |
@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]})) |
344 |
: velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{VELOCITY}[$b]}); |
|
345 |
next unless defined($v[0]); |
|
346 |
next if (abs($v[3]) > $opt_e || |
|
347 |
abs($v[2]-$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[2]) > 0.1); |
|
348 |
||
349 |
$v[0] -= $dta{ENSEMBLE}[$e]->{BT_VELOCITY}[0]; |
|
350 |
$v[1] -= $dta{ENSEMBLE}[$e]->{BT_VELOCITY}[1]; |
|
351 |
||
352 |
my($bin) = int(($dta{ENSEMBLE}[$e]->{DEPTH}+$dz) / $dta{BIN_LENGTH}); |
|
353 |
$minBin = $bin unless ($bin >= $minBin); |
|
354 |
$maxBin = $bin unless ($bin <= $maxBin); |
|
355 |
if (defined($BTn[$bin])) { |
|
356 |
my($f1) = $BTn[$bin] / ($BTn[$bin]+1); |
|
357 |
my($f2) = ($BTn[$bin]-1) / $BTn[$bin]; |
|
358 |
$BTsigu[$bin] = |
|
359 |
$f2*$BTsigu[$bin] + $f1*($v[0]-$BTu[$bin])**2/$BTn[$bin]; |
|
360 |
$BTsigv[$bin] = |
|
361 |
$f2*$BTsigv[$bin] + $f1*($v[1]-$BTv[$bin])**2/$BTn[$bin]; |
|
362 |
$BTn[$bin]++; |
|
363 |
$BTu[$bin] = $f1*$BTu[$bin] + $v[0]/$BTn[$bin]; |
|
364 |
$BTv[$bin] = $f1*$BTv[$bin] + $v[1]/$BTn[$bin]; |
|
365 |
} else { |
|
366 |
$BTu[$bin] = $v[0]; |
|
367 |
$BTv[$bin] = $v[1]; |
|
368 |
$BTn[$bin] = 1; |
|
369 |
} |
|
370 |
} |
|
371 |
} |
|
372 |
||
373 |
#====================================================================== |
|
374 |
# Output Bottom-Referenced Profile |
|
375 |
#====================================================================== |
|
376 |
||
377 |
sub dumpProf($$$) |
|
378 |
{ |
|
379 |
my($db,$wd,$md) = @_; |
|
380 |
my(@sum,@mean); |
|
381 |
||
382 |
for (my($i)=0; $i<=$#listCTDu; $i++) { # CTD vel mean |
|
383 |
$sum[0] += $listCTDu[$i]; |
|
384 |
$sum[1] += $listCTDv[$i]; |
|
385 |
} |
|
386 |
@mean = ($sum[0]/@listCTDu,$sum[1]/@listCTDv); |
|
387 |
@sum = (0,0); # stddev |
|
388 |
for (my($i)=0; $i<=$#listCTDu; $i++) { |
|
389 |
$sum[0] += ($listCTDu[$i]-$mean[0])**2; |
|
390 |
$sum[1] += ($listCTDv[$i]-$mean[1])**2; |
|
391 |
} |
|
392 |
@sigma = ($sum[0]/sqrt($#listCTDu),$sum[1]/sqrt($#listCTDv)); |
|
393 |
@sum = (0,0); # mean speed fluct |
|
394 |
for (my($i)=1; $i<=$#listCTDu; $i++) { # also: list for median |
|
395 |
push(@cfluc,sqrt(($listCTDu[$i]-$listCTDu[$i-1])**2 + |
|
396 |
($listCTDv[$i]-$listCTDv[$i-1])**2)); |
|
397 |
$sum[0] += $cfluc[$#cfluc]; |
|
398 |
} |
|
399 |
||
400 |
printf("#ANTS#PARAMS# LADCP_depth_bias{%.1f} water_depth{%.1f} magnetic_declination{%.1f}\n", |
|
401 |
$db,$wd,$md); |
|
402 |
printf("#ANTS#PARAMS# CTD_u{%.3f} CTD_v{%.3f} CTD_sig_u{%.3f} CTD_sig_v{%.3f} CTD_mean_cfluc{%.4f} CTD_median_cfluc{%.4f}\n", |
|
403 |
@mean,@sigma,$sum[0]/$#listCTDu,(sort{$a<=>$b}@cfluc)[@cfluc/2]); |
|
404 |
printf("#ANTS#PARAMS# good_ens{$good}\n"); |
|
405 |
print("#ANTS#FIELDS# {depth} {u} {v} {sig_u} {sig_v} {n_data}\n"); |
|
406 |
||
407 |
for (my($bin)=$minBin; $bin<=$maxBin; $bin++) { |
|
408 |
next unless defined($BTu[$bin]); |
|
409 |
printf("%d %.3f %.3f %.3f %.3f %d\n", |
|
410 |
($bin+0.5)*$dta{BIN_LENGTH}, |
|
411 |
$BTu[$bin],$BTv[$bin], |
|
412 |
sqrt($BTsigu[$bin]),sqrt($BTsigv[$bin]), |
|
413 |
$BTn[$bin]); |
|
414 |
} |
|
415 |
} |
|
416 |
||
417 |
#====================================================================== |
|
418 |
# STEP 1: Calculate Depth (integrate w) |
|
419 |
#====================================================================== |
|
420 |
||
421 |
for ($e=0; $e<=$#{$dta{ENSEMBLE}}; $e++) { |
|
422 |
$dta{ENSEMBLE}[$e]->{W_REF} = w($e); |
|
423 |
next unless (defined($start_e) || |
|
424 |
defined($dta{ENSEMBLE}[$e]->{W_REF})); |
|
425 |
$start_e = $e unless defined($start_e); |
|
426 |
$end_e = $e if defined($dta{ENSEMBLE}[$e]->{W_REF}); |
|
427 |
$lasttime = $curtime; |
|
428 |
$curtime = $dta{ENSEMBLE}[$e]->{UNIX_TIME}; |
|
429 |
$dta{ENSEMBLE}[$e]->{ELAPSED} = |
|
430 |
$curtime - $dta{ENSEMBLE}[$start_e]->{UNIX_TIME}; |
|
431 |
filterEnsemble(\%dta,$e) |
|
432 |
if (defined($opt_F) && |
|
433 |
$dta{ENSEMBLE}[$e]->{PERCENT_GOOD}[0][3] > 0); |
|
434 |
$z += $dta{ENSEMBLE}[$e]->{W_REF} * |
|
435 |
(defined($lasttime) ? ($curtime - $lasttime) : 0); |
|
436 |
$maxz_e=$e,$maxz = $z unless ($z < $maxz); |
|
437 |
$dta{ENSEMBLE}[$e]->{DEPTH} = $z; |
|
438 |
} |
|
439 |
||
440 |
unless ($opt_R) { |
|
441 |
($w_depth,$swd) = find_seabed(\%dta,$maxz_e,$beamCoords); |
|
442 |
die("$0: can't determine water depth (sigma = $swd)\n") |
|
443 |
unless (defined($w_depth) && $swd < 10); |
|
444 |
||
445 |
if (defined($opt_W)) { # adjust depth |
|
446 |
$zbias = $w_depth - $opt_W; $w_depth = $opt_W; |
|
447 |
for ($e=$start_e; $e<=$end_e; $e++) { |
|
448 |
$dta{ENSEMBLE}[$e]->{DEPTH} -= $zbias; |
|
449 |
} |
|
450 |
} |
|
451 |
} |
|
452 |
||
453 |
# print(STDERR "maxz = $maxz, w_depth = $w_depth\n"); |
|
454 |
||
455 |
#====================================================================== |
|
456 |
# STEP 2: Process BT Data |
|
457 |
#====================================================================== |
|
458 |
||
459 |
for ($e=$start_e; $e<=$end_e; $e++) { |
|
460 |
next unless ($dta{ENSEMBLE}[$e]->{BT_RANGE}[0] && # BT data available |
|
461 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[1] && |
|
462 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[2] && |
|
463 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[3]); |
|
464 |
# die("$0: don't know what to do with non-zero %-good and " . |
|
465 |
# "signal-strength values at ensemble " . |
|
466 |
# "#$dta{ENSEMBLE}[$e]->{NUMBER}\n") |
|
467 |
# if ($dta{ENSEMBLE}[$e]->{BT_PERCENT_GOOD}[0] || |
|
468 |
# $dta{ENSEMBLE}[$e]->{BT_PERCENT_GOOD}[1] || |
|
469 |
# $dta{ENSEMBLE}[$e]->{BT_PERCENT_GOOD}[2] || |
|
470 |
# $dta{ENSEMBLE}[$e]->{BT_PERCENT_GOOD}[3] || |
|
471 |
# $dta{ENSEMBLE}[$e]->{BT_SIGNAL_STRENGHT}[0] || |
|
472 |
# $dta{ENSEMBLE}[$e]->{BT_SIGNAL_STRENGHT}[1] || |
|
473 |
# $dta{ENSEMBLE}[$e]->{BT_SIGNAL_STRENGHT}[2] || |
|
474 |
# $dta{ENSEMBLE}[$e]->{BT_SIGNAL_STRENGHT}[3]); |
|
475 |
||
476 |
if ($opt_R) { # dump raw data |
|
477 |
dumpRaw($e); |
|
478 |
next; |
|
479 |
} |
|
480 |
||
481 |
$dta{ENSEMBLE}[$e]->{HEADING} -= # compass correction |
|
482 |
$CC_amp * sin(rad($dta{ENSEMBLE}[$e]->{HEADING} - $CC_phase)) |
|
483 |
+ $CC_bias |
|
484 |
if defined($opt_C); |
|
485 |
||
486 |
@{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}} = $beamCoords # xform BT vel |
|
487 |
? velInstrumentToEarth(\%dta,$e, |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
14
diff
changeset
|
488 |
velBeamToInstrument(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}})) |
0 | 489 |
: velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}}); |
490 |
||
491 |
$dta{ENSEMBLE}[$e]->{BT_MEAN_RANGE} = # mean vals |
|
492 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[0]/4 + |
|
493 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[1]/4 + |
|
494 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[2]/4 + |
|
495 |
$dta{ENSEMBLE}[$e]->{BT_RANGE}[3]/4; |
|
496 |
$dta{ENSEMBLE}[$e]->{BT_MEAN_CORRELATION} = |
|
497 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[0]/4 + |
|
498 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[1]/4 + |
|
499 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[2]/4 + |
|
500 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[3]/4; |
|
501 |
$dta{ENSEMBLE}[$e]->{BT_MEAN_EVAL_AMPLITUDE} = |
|
502 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[0]/4 + |
|
503 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[1]/4 + |
|
504 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[2]/4 + |
|
505 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[3]/4; |
|
506 |
||
507 |
# next # could add this |
|
508 |
# if ($dta{ENSEMBLE}[$e]->{BT_MEAN_RANGE} < 50); |
|
509 |
||
510 |
$bad_amp++,next |
|
511 |
if ($dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[0] < $opt_a || |
|
512 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[1] < $opt_a || |
|
513 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[2] < $opt_a || |
|
514 |
$dta{ENSEMBLE}[$e]->{BT_EVAL_AMPLITUDE}[3] < $opt_a); |
|
515 |
$bad_corr++,next |
|
516 |
if ($dta{ENSEMBLE}[$e]->{BT_CORRELATION}[0] < $opt_c || |
|
517 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[1] < $opt_c || |
|
518 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[2] < $opt_c || |
|
519 |
$dta{ENSEMBLE}[$e]->{BT_CORRELATION}[3] < $opt_c); |
|
520 |
||
521 |
$bad_w_ref++,next # quality checks |
|
522 |
if (abs($dta{ENSEMBLE}[$e]->{BT_VELOCITY}[2] - |
|
523 |
$dta{ENSEMBLE}[$e]->{W_REF}) > $opt_w); |
|
524 |
$bad_e_vel++,next |
|
525 |
if (abs($dta{ENSEMBLE}[$e]->{BT_VELOCITY}[3]) > $opt_e); |
|
526 |
$bad_depth++,next |
|
527 |
if (abs($dta{ENSEMBLE}[$e]->{BT_MEAN_RANGE} + |
|
528 |
$dta{ENSEMBLE}[$e]->{DEPTH} - $w_depth) > $opt_d); |
|
529 |
||
530 |
$good++; |
|
531 |
push(@listCTDu,-$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[0]); |
|
532 |
push(@listCTDv,-$dta{ENSEMBLE}[$e]->{BT_VELOCITY}[1]); |
|
533 |
||
534 |
if ($opt_E || $opt_B) { |
|
535 |
my(@maxamp) = (0,0,0,0); # water-track range |
|
536 |
my(@btm_e) = (0,0,0,0); |
|
537 |
for ($b=$firstBin; $b<=$lastBin; $b++) { |
|
538 |
for ($i=0; $i<4; $i++) { |
|
539 |
if ($dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][$i] > $maxamp[$i]) { |
|
540 |
$dta{ENSEMBLE}[$e]->{WT_RANGE}[$i] = $b; |
|
541 |
$maxamp[$i] = $dta{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$b][$i]; |
|
542 |
$btm_e[$i] = $e; |
|
543 |
} |
|
544 |
} |
|
545 |
} |
|
546 |
for ($i=0; $i<4; $i++) { |
|
547 |
$dta{ENSEMBLE}[$e]->{WT_RANGE}[$i] *= $dta{BIN_LENGTH}; |
|
548 |
$dta{ENSEMBLE}[$e]->{WT_RANGE}[$i] += $dta{DISTANCE_TO_BIN1_CENTER}; |
|
549 |
} |
|
550 |
$dta{ENSEMBLE}[$e]->{WT_MEAN_RANGE} = |
|
551 |
$dta{ENSEMBLE}[$e]->{WT_RANGE}[0]/4 + |
|
552 |
$dta{ENSEMBLE}[$e]->{WT_RANGE}[1]/4 + |
|
553 |
$dta{ENSEMBLE}[$e]->{WT_RANGE}[2]/4 + |
|
554 |
$dta{ENSEMBLE}[$e]->{WT_RANGE}[3]/4; |
|
555 |
||
556 |
my($btm_e) = int($btm_e[0]/4+$btm_e[1]/4+$btm_e[2]/4+$btm_e[3]/4+0.5); |
|
557 |
@{$dta{ENSEMBLE}[$btm_e]->{BTFWT_VELOCITY}} = $beamCoords # BT from WT |
|
558 |
? velInstrumentToEarth(\%dta,$e, |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
14
diff
changeset
|
559 |
velBeamToInstrument(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}})) |
0 | 560 |
: velApplyHdgBias(\%dta,$e,@{$dta{ENSEMBLE}[$e]->{BT_VELOCITY}}); |
561 |
} |
|
562 |
||
563 |
dumpEns($e) if defined($opt_E); # output BT profiles |
|
564 |
if ($opt_B) { dumpBT($e); } |
|
565 |
else { binEns($e); } |
|
566 |
} |
|
567 |
||
568 |
filterEnsembleStats() if defined($opt_F); |
|
569 |
exit(0) if ($opt_R); |
|
570 |
||
571 |
printf(STDERR "%5d BT records removed due to bad w\n",$bad_w_ref) |
|
572 |
if defined($bad_w_ref); |
|
573 |
printf(STDERR "%5d BT records removed due to bad err vel\n",$bad_e_vel) |
|
574 |
if defined($bad_e_vel); |
|
575 |
printf(STDERR "%5d BT records removed due to bad echo amplitude\n",$bad_amp) |
|
576 |
if defined($bad_amp); |
|
577 |
printf(STDERR "%5d BT records removed due to bad correlation\n",$bad_corr) |
|
578 |
if defined($bad_corr); |
|
579 |
printf(STDERR "%5d BT records removed due to bad depth\n",$bad_depth) |
|
580 |
if defined($bad_depth); |
|
581 |
||
582 |
die("$0: no good BT data\n") unless ($good); |
|
583 |
||
584 |
printf(STDERR "\n%5d BT records remaining\n",$good); |
|
585 |
||
586 |
dumpProf($zbias,$w_depth,-$dta{HEADING_BIAS}) |
|
587 |
unless ($opt_B); |
|
588 |
||
589 |
exit(0); |
|
590 |