author | Andreas Thurnherr <ant@ldeo.columbia.edu> |
Sat, 10 Apr 2021 05:52:17 -0400 | |
changeset 58 | 78607e2e8add |
parent 52 | 5b07a9b89aee |
child 60 | 890e267a2d98 |
permissions | -rw-r--r-- |
0 | 1 |
#====================================================================== |
2 |
# R D I _ U T I L S . P L |
|
3 |
# doc: Wed Feb 12 10:21:32 2003 |
|
52
5b07a9b89aee
- adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
49
diff
changeset
|
4 |
# dlm: Mon Apr 13 14:07:54 2020 |
0 | 5 |
# (c) 2003 A.M. Thurnherr |
52
5b07a9b89aee
- adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
49
diff
changeset
|
6 |
# uE-Info: 68 53 NIL 0 0 72 0 2 4 NIL ofnI |
0 | 7 |
#====================================================================== |
8 |
||
9 |
# miscellaneous RDI-specific utilities |
|
10 |
||
11 |
# History: |
|
12 |
# Feb 12, 2003: - created |
|
13 |
# Feb 14, 2003: - added check for short (bad) data files |
|
14 |
# Feb 26, 2004: - added Earth-coordinate support |
|
15 |
# - added ensure_BT_RANGE() |
|
16 |
# Mar 17, 2004: - set bad BT ranges to undef in ensure_BT_RANGE |
|
17 |
# - calc mean/stddev in ensure_BT_RANGE |
|
18 |
# Mar 20, 2004: - BUG: find_seabed() could bomb when not enough |
|
19 |
# bottom guesses passed the mode_width test |
|
20 |
# Mar 30, 2004: - added &soundSpeed() |
|
21 |
# Nov 8, 2005: - WATER_DEPTH => Z_BT |
|
22 |
# Dec 1, 2005: - renamed to RDI_Utils.pl |
|
23 |
# - folded in mk_prof from [mkProfile] |
|
24 |
# Nov 30, 2007: - adapted ref_lr_w() to 3-beam solutions |
|
25 |
# Feb 1, 2008: - added comment |
|
26 |
# Feb 22, 2008: - added ssCorr() |
|
27 |
# Apr 9, 2008: - BUG: duplicate line of code (without effect) in find_seabed() |
|
28 |
# - BUG: seabed < max depth was possible |
|
29 |
# Jan 2010: - fiddled with seabed detection params (no conclusion) |
|
30 |
# May 23, 2010: - renamed Z to DEPTH |
|
2
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
31 |
# Sep 27, 2010: - made sure coord flags are changed correctly when data |
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
32 |
# are transferred to earth coords in mk_prof |
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
33 |
# Sep 29, 2010: - BUG: previous change was wrong, as ref_lr_w does |
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
34 |
# not overwrite velocities |
3 | 35 |
# Oct 20, 2010: - BUG: w is now not integrated any more across gaps longer than 5s |
36 |
# Dec 8, 2010: - changed missing w warning to happen only if gap is longer than 15s |
|
37 |
# Dec 10, 2010: - beautified gap warning |
|
5 | 38 |
# Dec 16, 2010: - BUG: gaps at end caused mk_prof to throw away profile |
6 | 39 |
# May 12, 2011: - added code to skip ensembles with built-in-test errors in mk_prof() |
40 |
# - immediately disabled this code becasue it does appear to make matters worse |
|
8 | 41 |
# Sep 21, 2011: - added calculation of RMS heave acceleration |
10 | 42 |
# Mar 27, 2013: - BUG: 3-beam solutions were not used in ref_lr_w |
43 |
# - disabled apparently unused code |
|
11 | 44 |
# Apr 12, 2013: - added $min_pctg as optional parameter to mk_prof |
12 | 45 |
# May 14, 2013: - added incident-velocity, w12 & w34 to mkProfile |
46 |
# Jun 5, 2013: - BUG: incident-flow warning was printed repeatedly |
|
47 |
# Jun 20, 2013: - BUG: warning had used &antsInfo() |
|
14 | 48 |
# Feb 13, 2014: - replaced {DEPTH_BT} by {seabed} |
49 |
# - added set_range_lim() |
|
17
591779f6df30
changed mkProfile gap heuristics & removed warning
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
14
diff
changeset
|
50 |
# Feb 22, 2014: - changed gap heuristic |
591779f6df30
changed mkProfile gap heuristics & removed warning
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
14
diff
changeset
|
51 |
# - Earth coord beam-pair warning removed |
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
17
diff
changeset
|
52 |
# May 29, 2014: - removed unused code (disabled warning) from ref_lr_w |
23
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
19
diff
changeset
|
53 |
# Mar 22, 2015: - BUG: mk_prof could bomb because of division-by-zero in return statement |
31 | 54 |
# Jan 9, 2016: - renamed ref_lr_w to mk_prof_ref_lr_w because the old name conflicts |
55 |
# with a sub in LADCP_w |
|
34 | 56 |
# May 19, 2016: - adapted to new velBeamToInstrument() usage |
39 | 57 |
# Aug 7, 2017: - added abmiguity velocity |
58 |
# Aug 8, 2017: - changed transducer frequency to kHz |
|
41 | 59 |
# Nov 27, 2017: - BUG: profile-restart heuristic did not work with P6#001 |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset
|
60 |
# Mar 18, 2018: - added -ve dt consistency check |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset
|
61 |
# Jun 9, 2018: - added support for ENV{NO_GAP_WARNINGS} |
48
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
43
diff
changeset
|
62 |
# Jun 16, 2019: - adapted (partiall) to support RTI ADCPs: |
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
43
diff
changeset
|
63 |
# - made ambiguity_velocity() return nan (missing TL_distance) |
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
43
diff
changeset
|
64 |
# - skip missing velocities in reference-layer calculation |
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
43
diff
changeset
|
65 |
# - disable %-good screening with $min_pctg == 0 |
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
43
diff
changeset
|
66 |
# Jun 26, 2019: - increased short-gap in mk_prof from 5s to 6s to allow processing |
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
43
diff
changeset
|
67 |
# of RTi test file with 5s ensembles |
52
5b07a9b89aee
- adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
49
diff
changeset
|
68 |
# Apr 13, 2020: - added $RDI_Utils::No_Gap_Warnings |
0 | 69 |
|
70 |
use strict; |
|
71 |
||
52
5b07a9b89aee
- adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
49
diff
changeset
|
72 |
$RDI_Utils::No_Gap_Warnings = 0; # set to 1 to suppress gap warnings |
5b07a9b89aee
- adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
49
diff
changeset
|
73 |
|
0 | 74 |
#====================================================================== |
75 |
# fake_BT_RANGE(dta ptr) |
|
76 |
#====================================================================== |
|
77 |
||
78 |
# During cruise NBP0204 it was found that one of Visbeck's RDIs consistently |
|
79 |
# returns zero as the bottom-track range, even thought the BT velocities |
|
80 |
# are good. This functions calculates the ranges if they are missing. |
|
81 |
||
82 |
sub cBTR($$$) |
|
83 |
{ |
|
84 |
my($d,$e,$b) = @_; |
|
85 |
my($maxamp) = -9e99; |
|
86 |
my($maxi); |
|
87 |
||
88 |
for (my($i)=0; $i<$d->{N_BINS}; $i++) { |
|
89 |
next unless ($d->{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$i][$b] > $maxamp); |
|
90 |
$maxamp = $d->{ENSEMBLE}[$e]->{ECHO_AMPLITUDE}[$i][$b]; |
|
91 |
$maxi = $i; |
|
92 |
} |
|
93 |
$d->{ENSEMBLE}[$e]->{BT_RANGE}[$b] = |
|
94 |
$d->{DISTANCE_TO_BIN1_CENTER} + $maxi * $d->{BIN_LENGTH}; |
|
95 |
} |
|
96 |
||
97 |
sub ensure_BT_RANGE($) |
|
98 |
{ |
|
99 |
my($d) = @_; |
|
100 |
for (my($e)=0; $e<=$#{$d->{ENSEMBLE}}; $e++) { |
|
101 |
my($sum) = my($n) = 0; |
|
102 |
if (defined($d->{ENSEMBLE}[$e]->{BT_VELOCITY}[0])) { |
|
103 |
for (my($b)=0; $b<4; $b++) { |
|
104 |
cBTR($d,$e,$b) |
|
105 |
unless defined($d->{ENSEMBLE}[$e]->{BT_RANGE}[$b]); |
|
106 |
$sum += $d->{ENSEMBLE}[$e]->{BT_RANGE}[$b]; $n++; |
|
107 |
} |
|
108 |
} else { |
|
109 |
for (my($b)=0; $b<4; $b++) { |
|
110 |
$d->{ENSEMBLE}[$e]->{BT_RANGE}[$b] = undef; |
|
111 |
} |
|
112 |
} |
|
113 |
$d->{ENSEMBLE}[$e]->{BT_MEAN_RANGE} = $sum/$n if ($n == 4); |
|
114 |
} |
|
115 |
} |
|
116 |
||
117 |
#====================================================================== |
|
118 |
# (seabed depth, stddev) = find_seabed(dta ptr, btm ensno, coord flag) |
|
119 |
#====================================================================== |
|
120 |
||
121 |
# NOTE FOR YOYOS: |
|
122 |
# - this routine only detects the BT around the depeest depth! |
|
123 |
# - this is on purpose, because it is used for [listBT] |
|
124 |
||
125 |
# This is a PAIN: |
|
126 |
# if the instrument is too close to the bottom, the BT_RANGE |
|
127 |
# readings are all out; the only solution is to have a sufficiently |
|
128 |
# large search width (around the max(depth) ensemble) so that |
|
129 |
# a part of the up (oops, I forgot to finish this comment one year |
|
130 |
# ago during A0304 and now I don't understand it any more :-) |
|
131 |
||
132 |
my($search_width) = 200; # # of ensembles around bottom to search |
|
133 |
my($mode_width) = 10; # max range of bottom around mode |
|
134 |
my($min_dist) = 20; # min dist to seabed for good data |
|
135 |
my($z_offset) = 10000; # shift z to ensure +ve array indices |
|
136 |
||
137 |
sub find_seabed($$$) |
|
138 |
{ |
|
139 |
my($d,$be,$beamCoords) = @_; |
|
140 |
my($i,$dd,$sd,$nd); |
|
141 |
my(@guesses); |
|
142 |
||
143 |
return undef unless ($be-$search_width >= 0 && |
|
144 |
$be+$search_width <= $#{$d->{ENSEMBLE}}); |
|
145 |
for ($i=$be-$search_width; $i<=$be+$search_width; $i++) { |
|
146 |
next unless (defined($d->{ENSEMBLE}[$i]->{DEPTH}) && |
|
147 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[0]) && |
|
148 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[1]) && |
|
149 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[2]) && |
|
150 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[3])); |
|
34 | 151 |
my(@BT) = $beamCoords ? velBeamToEarth($d,$i,@{$d->{ENSEMBLE}[$i]->{BT_VELOCITY}}) |
152 |
: velApplyHdgBias($d,$i,@{$d->{ENSEMBLE}[$i]->{BT_VELOCITY}}); |
|
0 | 153 |
next unless (abs($BT[3]) < 0.05); |
14 | 154 |
$d->{ENSEMBLE}[$i]->{seabed} = |
0 | 155 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[0]/4 + |
156 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[1]/4 + |
|
157 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[2]/4 + |
|
158 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[3]/4; |
|
14 | 159 |
next |
160 |
unless ($d->{ENSEMBLE}[$i]->{seabed} >= $min_dist); |
|
161 |
$d->{ENSEMBLE}[$i]->{seabed} *= -1 |
|
0 | 162 |
if ($d->{ENSEMBLE}[$i]->{XDUCER_FACING_UP}); |
14 | 163 |
$d->{ENSEMBLE}[$i]->{seabed} += $d->{ENSEMBLE}[$i]->{DEPTH}; |
164 |
if ($d->{ENSEMBLE}[$i]->{seabed} > $d->{ENSEMBLE}[$be]->{DEPTH}) { |
|
165 |
$guesses[int($d->{ENSEMBLE}[$i]->{seabed})+$z_offset]++; |
|
0 | 166 |
$nd++; |
167 |
} else { |
|
14 | 168 |
undef($d->{ENSEMBLE}[$i]->{seabed}); |
0 | 169 |
} |
170 |
} |
|
171 |
return undef unless ($nd>5); |
|
172 |
||
173 |
my($mode,$nmax); |
|
174 |
for ($i=0; $i<=$#guesses; $i++) { # find mode |
|
14 | 175 |
$nmax=$guesses[$i],$mode=$i-$z_offset |
0 | 176 |
if ($guesses[$i] > $nmax); |
177 |
} |
|
178 |
||
179 |
$nd = 0; |
|
180 |
for ($i=$be-$search_width; $i<=$be+$search_width; $i++) { |
|
14 | 181 |
next unless defined($d->{ENSEMBLE}[$i]->{seabed}); |
182 |
if (abs($d->{ENSEMBLE}[$i]->{seabed}-$mode) <= $mode_width) { |
|
183 |
$dd += $d->{ENSEMBLE}[$i]->{seabed}; |
|
0 | 184 |
$nd++; |
185 |
} else { |
|
14 | 186 |
$d->{ENSEMBLE}[$i]->{seabed} = undef; |
0 | 187 |
} |
188 |
} |
|
189 |
return undef unless ($nd >= 2); |
|
190 |
||
191 |
$dd /= $nd; |
|
192 |
for ($i=$be-$search_width; $i<=$be+$search_width; $i++) { |
|
14 | 193 |
next unless defined($d->{ENSEMBLE}[$i]->{seabed}); |
194 |
$sd += ($d->{ENSEMBLE}[$i]->{seabed}-$dd)**2; |
|
0 | 195 |
} |
196 |
||
197 |
return ($dd, sqrt($sd/($nd-1))); |
|
198 |
} |
|
199 |
||
14 | 200 |
#---------------------------------------------------------------------- |
201 |
# set_range_lim(d) |
|
202 |
# - set field range_lim |
|
203 |
#---------------------------------------------------------------------- |
|
204 |
||
205 |
sub set_range_lim($) |
|
206 |
{ |
|
207 |
my($d) = @_; |
|
208 |
||
209 |
for (my($e)=0; $e<=$#{$d->{ENSEMBLE}}; $e++) { |
|
210 |
my($lastGood) = 1; my($b); |
|
211 |
for ($b=0; $b<$d->{N_BINS}; $b++) { |
|
212 |
if (defined($d->{ENSEMBLE}[$e]->{VELOCITY}[$b][0]) && |
|
213 |
defined($d->{ENSEMBLE}[$e]->{VELOCITY}[$b][1]) && |
|
214 |
defined($d->{ENSEMBLE}[$e]->{VELOCITY}[$b][2]) && |
|
215 |
defined($d->{ENSEMBLE}[$e]->{VELOCITY}[$b][3])) { |
|
216 |
$lastGood = 1; |
|
217 |
} elsif ($lastGood) { |
|
218 |
$lastGood = 0; |
|
219 |
} else { |
|
220 |
last; |
|
221 |
} |
|
222 |
} |
|
223 |
||
224 |
next unless ($b>=2) && defined($d->{ENSEMBLE}[$e]->{DEPTH}); |
|
225 |
$d->{ENSEMBLE}[$e]->{range_lim} = |
|
226 |
$d->{DISTANCE_TO_BIN1_CENTER} + ($b-2) * $d->{BIN_LENGTH}; |
|
227 |
$d->{ENSEMBLE}[$e]->{range_lim} *= -1 |
|
228 |
if ($d->{ENSEMBLE}[$e]->{XDUCER_FACING_UP}); |
|
229 |
$d->{ENSEMBLE}[$e]->{range_lim} += $d->{ENSEMBLE}[$e]->{DEPTH}; |
|
230 |
} |
|
231 |
} |
|
232 |
||
0 | 233 |
#====================================================================== |
234 |
# c = soundSpeed($salin,$temp,$depth) |
|
235 |
#====================================================================== |
|
236 |
||
237 |
# Taken from the RDI BroadBand primer manual. The reference given there |
|
238 |
# is Urick (1983). |
|
239 |
||
240 |
sub soundSpeed($$$) |
|
241 |
{ |
|
242 |
my($salin,$temp,$depth) = @_; |
|
243 |
die("ERROR: soundSpeed($salin,$temp,$depth): non-numeric parameter\n") |
|
244 |
unless numberp($salin) && numberp($temp) && numberp($depth); |
|
245 |
return 1449.2 + 4.6*$temp -0.055*$temp**2 + 0.00029*$temp**3 + |
|
246 |
(1.34 - 0.01*$temp) * ($salin - 35) + 0.016*$depth; |
|
247 |
} |
|
248 |
||
249 |
#====================================================================== |
|
250 |
# fac = ssCorr($eRef,$salin,$temp,$depth) |
|
251 |
# $eRef : reference to current ensemble |
|
252 |
# $salin: * -> use instrument salinity |
|
253 |
# $temp : * -> use instrument temperature |
|
254 |
# $depth: * -> use instrument PRESSURE(!) |
|
255 |
#====================================================================== |
|
256 |
||
257 |
{ my($warned); |
|
258 |
sub ssCorr($$$$) |
|
259 |
{ |
|
260 |
my($eRef,$S,$T,$D) = @_; |
|
261 |
$S = $eRef->{SALINITY} if ($S eq '*'); |
|
262 |
$T = $eRef->{TEMPERATURE} if ($T eq '*'); |
|
263 |
if ($D eq '*') { |
|
264 |
print(STDERR "WARNING: soundspeed correction using instrument pressure instead of depth!\n") |
|
265 |
unless ($warned); |
|
266 |
$warned = 1; |
|
267 |
$D = $eRef->{PRESSURE}; |
|
268 |
} |
|
269 |
return soundSpeed($S,$T,$D) / $eRef->{SPEED_OF_SOUND}; |
|
270 |
} |
|
271 |
} |
|
39 | 272 |
|
273 |
#====================================================================== |
|
274 |
# ambiguity_velocity(transducer_freq,beam_angle,sound_speed,transmit_lag_dist) |
|
275 |
# - recipe provied by Jerry Mullison in August 2017 |
|
276 |
# - transducer_freq in kHz |
|
277 |
# - sound speed can vary with ensemble |
|
278 |
#====================================================================== |
|
279 |
||
280 |
sub ambiguity_velocity($$$$) |
|
281 |
{ |
|
282 |
my($xd_freq,$beam_angle,$speed_of_sound,$TL_distance) = @_; |
|
47
494a76548e94
before adapting to read RTI PD0 files
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
43
diff
changeset
|
283 |
return 'nan' unless ($TL_distance > 0); |
39 | 284 |
my($lambda) = $speed_of_sound / (1000*$xd_freq); |
285 |
my($D) = $speed_of_sound * cos(rad($beam_angle)) / 2; |
|
286 |
return $lambda * $D / (4 * $TL_distance); |
|
287 |
} |
|
0 | 288 |
|
289 |
#====================================================================== |
|
290 |
# ($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz) = |
|
291 |
# mk_prof($dta,$check,$filter,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap); |
|
292 |
#====================================================================== |
|
293 |
||
12 | 294 |
# calculate reference-layer vertical and incident velocities |
295 |
||
31 | 296 |
sub mk_prof_ref_lr_w($$$$$$$) |
0 | 297 |
{ |
11 | 298 |
my($dta,$ens,$rl_b0,$rl_b1,$min_corr,$max_e,$min_pctg) = @_; |
12 | 299 |
my($i,@n,@bn,@v,@vi,@vel,@veli,@bv,@w); |
300 |
my($w,$e,$nvi,$vi12,$vi43,@vbp,@velbp,@nbp,$w12,$w34,@w12,@w34); |
|
0 | 301 |
|
302 |
for ($i=$rl_b0; $i<=$rl_b1; $i++) { |
|
48
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
43
diff
changeset
|
303 |
next unless defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]); |
0 | 304 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]) |
305 |
if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][0] < $min_corr); |
|
306 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1]) |
|
307 |
if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][1] < $min_corr); |
|
308 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2]) |
|
309 |
if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][2] < $min_corr); |
|
310 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]) |
|
311 |
if ($dta->{ENSEMBLE}[$ens]->{CORRELATION}[$i][3] < $min_corr); |
|
312 |
if ($dta->{BEAM_COORDINATES}) { |
|
313 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]) |
|
11 | 314 |
if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][0] < $min_pctg); |
0 | 315 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1]) |
11 | 316 |
if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][1] < $min_pctg); |
0 | 317 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2]) |
11 | 318 |
if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] < $min_pctg); |
0 | 319 |
undef($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]) |
11 | 320 |
if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < $min_pctg); |
34 | 321 |
@vi = velBeamToInstrument($dta,$ens,@{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]}); |
12 | 322 |
@v = velInstrumentToEarth($dta,$ens,@vi); |
323 |
@vbp = velBeamToBPEarth($dta,$ens,@{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]}); |
|
0 | 324 |
} else { |
48
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
43
diff
changeset
|
325 |
if ($min_pctg > 0) { |
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
43
diff
changeset
|
326 |
next if ($dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][0] > 0 || |
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
43
diff
changeset
|
327 |
$dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][1] > 0 || |
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
43
diff
changeset
|
328 |
$dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][2] > 0 || |
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
43
diff
changeset
|
329 |
$dta->{ENSEMBLE}[$ens]->{PERCENT_GOOD}[$i][3] < $min_pctg); |
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
43
diff
changeset
|
330 |
} |
0 | 331 |
@v = @{$dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i]}; |
332 |
} |
|
10 | 333 |
next if (defined($v[3]) && abs($v[3]) > $max_e); # allow 3-beam solutions |
0 | 334 |
|
19
e23a5fd2923a
after adapting RDI_Coords to calc w even without valid heading
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
17
diff
changeset
|
335 |
if (defined($v[2])) { # valid vertical velocity |
12 | 336 |
$vel[2] += $v[2]; $n[2]++; # vertical velocity |
337 |
$vel[3] += $v[3], $n[3]++ if defined($v[3]); # error velocity |
|
338 |
push(@w,$v[2]); # save for stderr calculation |
|
339 |
} |
|
340 |
||
341 |
if (defined($vbp[1])) { # beam-pair vertical velocities |
|
342 |
$velbp[0] += $vbp[1]; $nbp[0]++; |
|
343 |
push(@w12,$vbp[1]); |
|
344 |
} |
|
345 |
if (defined($vbp[3])) { |
|
346 |
$velbp[1] += $vbp[3]; $nbp[1]++; |
|
347 |
push(@w34,$vbp[1]); |
|
0 | 348 |
} |
349 |
||
12 | 350 |
if (defined($vi[0])) { # incident velocity |
351 |
$veli[0] += $vi[0]; |
|
352 |
$veli[1] += $vi[1]; |
|
353 |
$nvi++; |
|
354 |
} |
|
355 |
||
10 | 356 |
# The following code calculates beam-averaged ref-lr velocities. |
357 |
# I do not recall what this was implemented for. Disabled Mar 27, 2013. |
|
358 |
# |
|
359 |
# if ($dta->{BEAM_COORDINATES}) { |
|
360 |
# $bv[0] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0], $bn[0]++ |
|
361 |
# if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][0]); |
|
362 |
# $bv[1] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1], $bn[1]++ |
|
363 |
# if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][1]); |
|
364 |
# $bv[2] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2], $bn[2]++ |
|
365 |
# if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][2]); |
|
366 |
# $bv[3] += $dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3], $bn[3]++ |
|
367 |
# if defined($dta->{ENSEMBLE}[$ens]->{VELOCITY}[$i][3]); |
|
368 |
# } |
|
12 | 369 |
} # loop over ref-lr bins |
370 |
||
371 |
$w = ($n[2] > 0) ? $vel[2]/$n[2] : undef; # calc means |
|
372 |
$e = ($n[3] > 0) ? $vel[3]/$n[3] : undef; |
|
373 |
if ($nvi > 0) { |
|
374 |
$vi12 = $veli[0] / $nvi; |
|
375 |
$vi43 = $veli[1] / $nvi; |
|
376 |
} else { |
|
377 |
$vi12 = $vi43 = undef; |
|
378 |
} |
|
379 |
$w12 = ($nbp[0] > 0) ? $velbp[0]/$nbp[0] : undef; |
|
380 |
$w34 = ($nbp[1] > 0) ? $velbp[1]/$nbp[1] : undef; |
|
381 |
||
382 |
if (@w12) { # w uncertainty |
|
383 |
my($sumsq) = 0; |
|
384 |
for ($i=0; $i<=$#w12; $i++) { |
|
385 |
$sumsq += ($w12-$w12[$i])**2; |
|
386 |
} |
|
387 |
$dta->{ENSEMBLE}[$ens]->{W12} = $w12; |
|
388 |
$dta->{ENSEMBLE}[$ens]->{W12_ERR} = sqrt($sumsq)/($nbp[0]-1) |
|
389 |
if ($nbp[0]>=2); |
|
0 | 390 |
} |
391 |
||
12 | 392 |
if (@w34) { # w uncertainty |
393 |
my($sumsq) = 0; |
|
394 |
for ($i=0; $i<=$#w34; $i++) { |
|
395 |
$sumsq += ($w34-$w34[$i])**2; |
|
396 |
} |
|
397 |
$dta->{ENSEMBLE}[$ens]->{W34} = $w34; |
|
398 |
$dta->{ENSEMBLE}[$ens]->{W34_ERR} = sqrt($sumsq)/($nbp[1]-1) |
|
399 |
if ($nbp[1]>=2); |
|
400 |
} |
|
401 |
||
402 |
my($sumsq) = 0; # w uncertainty |
|
0 | 403 |
for ($i=0; $i<=$#w; $i++) { |
404 |
$sumsq += ($w-$w[$i])**2; |
|
405 |
} |
|
406 |
my($stderr) = $n[2]>=2 ? sqrt($sumsq)/($n[2]-1) : undef; |
|
12 | 407 |
|
0 | 408 |
# The following stderr test introduces a huge gap near the bottom of |
409 |
# the profiles. Without it, they seem more reasonable. |
|
410 |
# next if ($stderr > 0.05); |
|
411 |
||
12 | 412 |
if (defined($w)) { # valid velocity |
0 | 413 |
$dta->{ENSEMBLE}[$ens]->{W} = $w; |
414 |
$dta->{ENSEMBLE}[$ens]->{W_ERR} = $stderr; |
|
415 |
} |
|
12 | 416 |
$dta->{ENSEMBLE}[$ens]->{ERR_VEL} = $e if (defined($e)); |
417 |
||
418 |
$dta->{ENSEMBLE}[$ens]->{W12} = $w12 if (defined($w12)); |
|
419 |
$dta->{ENSEMBLE}[$ens]->{W34} = $w34 if (defined($w34)); |
|
420 |
||
421 |
if (defined($vi12)) { |
|
422 |
$dta->{ENSEMBLE}[$ens]->{INCIDENT_VEL_T12} = $vi12; |
|
423 |
$dta->{ENSEMBLE}[$ens]->{INCIDENT_VEL_T43} = $vi43; |
|
424 |
} |
|
425 |
||
10 | 426 |
# The following code calculates beam-averaged ref-lr velocities. |
427 |
# I do not recall what this was implemented for. Disabled Mar 27, 2013. |
|
428 |
# |
|
429 |
# if ($dta->{BEAM_COORDINATES}) { |
|
430 |
# $dta->{ENSEMBLE}[$ens]->{V1} = $bn[0]>=2 ? $bv[0]/$bn[0] : undef; |
|
431 |
# $dta->{ENSEMBLE}[$ens]->{V2} = $bn[1]>=2 ? $bv[1]/$bn[1] : undef; |
|
432 |
# $dta->{ENSEMBLE}[$ens]->{V3} = $bn[2]>=2 ? $bv[2]/$bn[2] : undef; |
|
433 |
# $dta->{ENSEMBLE}[$ens]->{V4} = $bn[3]>=2 ? $bv[3]/$bn[3] : undef; |
|
434 |
# } |
|
12 | 435 |
|
0 | 436 |
} |
437 |
||
438 |
||
11 | 439 |
sub mk_prof(...) # make profile |
0 | 440 |
{ |
11 | 441 |
my($dta,$check,$filter,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap,$min_pctg) = @_; |
0 | 442 |
my($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz); |
8 | 443 |
my($rms_heave_accel_ssq,$rms_heave_accel_nsamp); |
11 | 444 |
|
445 |
$min_pctg = 100 unless defined($min_pctg); |
|
0 | 446 |
|
447 |
for (my($z)=0,my($e)=0; $e<=$#{$dta->{ENSEMBLE}}; $e++) { |
|
448 |
checkEnsemble($dta,$e) if ($check); |
|
6 | 449 |
### The following line of code, which can only have an effect if check is disabled, |
450 |
### seems reasonable but has been found to make matters worse with one particular |
|
451 |
### data file from a BB150. |
|
452 |
### next if ($dta->{ENSEMBLE}[$e]->{BUILT_IN_TEST_ERROR}); |
|
0 | 453 |
|
454 |
filterEnsemble($dta,$e) |
|
455 |
if (defined($filter) && |
|
456 |
$dta->{ENSEMBLE}[$e]->{PERCENT_GOOD}[0][0] > 0); |
|
31 | 457 |
mk_prof_ref_lr_w($dta,$e,$lr_b0,$lr_b1,$min_corr,$max_e,$min_pctg); # ref. layer w |
0 | 458 |
|
459 |
if (defined($firstgood)) { |
|
460 |
$dta->{ENSEMBLE}[$e]->{ELAPSED_TIME} = # time since start |
|
461 |
$dta->{ENSEMBLE}[$e]->{UNIX_TIME} - |
|
462 |
$dta->{ENSEMBLE}[$firstgood]->{UNIX_TIME}; |
|
463 |
} else { |
|
464 |
if (defined($dta->{ENSEMBLE}[$e]->{W})) { # start of prof. |
|
465 |
$firstgood = $lastgood = $e; |
|
466 |
$dta->{ENSEMBLE}[$e]->{ELAPSED_TIME} = 0; |
|
467 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $dta->{ENSEMBLE}[$e]->{DEPTH_ERR} = 0; |
|
468 |
} |
|
469 |
next; |
|
470 |
} |
|
471 |
||
472 |
#-------------------------------------------------- |
|
473 |
# within profile: both $firstgood and $lastgood set |
|
474 |
#-------------------------------------------------- |
|
475 |
||
476 |
if (!defined($dta->{ENSEMBLE}[$e]->{W})) { # gap |
|
477 |
$w_gap_time += $dta->{ENSEMBLE}[$e]->{UNIX_TIME} - |
|
478 |
$dta->{ENSEMBLE}[$e-1]->{UNIX_TIME}; |
|
479 |
next; |
|
480 |
} |
|
481 |
||
482 |
my($dt) = $dta->{ENSEMBLE}[$e]->{UNIX_TIME} - # time step since |
|
483 |
$dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME}; # ... last good ens |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset
|
484 |
|
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset
|
485 |
die(sprintf("PANIC: negative dt = $dt between ensembles %d and %d\n", |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset
|
486 |
$dta->{ENSEMBLE}[$lastgood]->{NUMBER},$dta->{ENSEMBLE}[$e]->{NUMBER})) |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset
|
487 |
if ($dt < 0); |
0 | 488 |
|
489 |
if ($dt > $max_gap) { |
|
41 | 490 |
# 2nd heuristic test added Nov 2017 for P06 profile #001 |
491 |
if ((@{$dta->{ENSEMBLE}}-$e < @{$dta->{ENSEMBLE}}/2) && |
|
492 |
($maxz > 25 && $z < $maxz/2)) { |
|
17
591779f6df30
changed mkProfile gap heuristics & removed warning
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
14
diff
changeset
|
493 |
printf(STDERR "WARNING: %.1f-s gap in 2nd half of profile is too long; profile ended at ensemble $lastgood\n",$dt); |
41 | 494 |
# printf(STDERR "\t[#ens = %d, end-of-gap = $e]\n",scalar(@{$dta->{ENSEMBLE}})); |
5 | 495 |
last; |
496 |
} |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset
|
497 |
printf(STDERR "WARNING: %.1f-s gap beginning at ens#%d in first half of profile is too long; profile restarted at ensemble %d\n", |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset
|
498 |
$dt,$dta->{ENSEMBLE}[$lastgood+1]->{NUMBER},$dta->{ENSEMBLE}[$e]->{NUMBER}); |
0 | 499 |
$firstgood = $lastgood = $e; |
500 |
$dta->{ENSEMBLE}[$e]->{ELAPSED_TIME} = 0; |
|
501 |
$z = $zErr = $maxz = 0; |
|
502 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $dta->{ENSEMBLE}[$e]->{DEPTH_ERR} = 0; |
|
503 |
$w_gap_time = 0; |
|
8 | 504 |
$rms_heave_accel_ssq = $rms_heave_accel_nsamp = 0; |
0 | 505 |
next; |
506 |
} |
|
2
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
507 |
|
0 | 508 |
#----------------------------------- |
509 |
# The current ensemble has a valid w |
|
510 |
#----------------------------------- |
|
8 | 511 |
|
48
cdc74ebada81
after partial adaptation to RTI files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
43
diff
changeset
|
512 |
if ($dt < 6) { # no or short gap |
8 | 513 |
$z += $dta->{ENSEMBLE}[$lastgood]->{W} * $dt; # integrate w to get depth |
2
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
514 |
$zErr += ($dta->{ENSEMBLE}[$lastgood]->{W_ERR} * $dt)**2; |
8 | 515 |
$rms_heave_accel_ssq += (($dta->{ENSEMBLE}[$e]->{W}-$dta->{ENSEMBLE}[$lastgood]->{W})/$dt)**2; |
516 |
$rms_heave_accel_nsamp++; |
|
3 | 517 |
} elsif ($dt > 15) { |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset
|
518 |
printf(STDERR "WARNING: long-ish w gap at ens#%d-%d (dt=%.1fs)\n", |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
41
diff
changeset
|
519 |
$dta->{ENSEMBLE}[$lastgood+1]->{NUMBER},$dta->{ENSEMBLE}[$e-1]->{NUMBER},$dt) |
52
5b07a9b89aee
- adapted to work with IMPed moored ADCP data
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents:
49
diff
changeset
|
520 |
unless defined($ENV{NO_GAP_WARNINGS}) || $RDI_Utils::No_Gap_Warnings; |
2
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
521 |
} |
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
522 |
|
0 | 523 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $z; |
524 |
$dta->{ENSEMBLE}[$e]->{DEPTH_ERR} = sqrt($zErr); |
|
525 |
||
526 |
$atbottom = $e, $maxz = $z if ($z > $maxz); |
|
527 |
||
528 |
$lastgood = $e; |
|
529 |
} |
|
530 |
||
531 |
filterEnsembleStats() if defined($filter); |
|
532 |
||
23
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
19
diff
changeset
|
533 |
return ($firstgood,$lastgood,$atbottom,$w_gap_time,$zErr,$maxz, |
fb0c269b1eaa
V1.2 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
19
diff
changeset
|
534 |
($rms_heave_accel_nsamp>0) ? sqrt($rms_heave_accel_ssq/$rms_heave_accel_nsamp) : 'nan'); |
0 | 535 |
} |
536 |
||
537 |
#---------------------------------------------------------------------- |
|
538 |
# (true|false) = numberp(var) |
|
539 |
#---------------------------------------------------------------------- |
|
540 |
||
541 |
sub numberp(@) |
|
542 |
{ return $_[0] =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/; } |
|
543 |
||
544 |
||
545 |
1; |
|
2
065ea9ce12fc
before DIMES UK2 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
546 |