author | A.M. Thurnherr <athurnherr@yahoo.com> |
Fri, 09 Sep 2022 12:38:20 -0400 | |
changeset 62 | 9f3282aa7b9b |
parent 54 | 828e5466391b |
permissions | -rw-r--r-- |
0 | 1 |
#====================================================================== |
2 |
# S V E L _ C O R R E C T I O N S . P L |
|
3 |
# doc: Thu Dec 30 01:35:18 2010 |
|
54 | 4 |
# dlm: Mon Jun 29 11:02:08 2020 |
0 | 5 |
# (c) 2010 A.M. Thurnherr |
54 | 6 |
# uE-Info: 22 74 NIL 0 0 72 0 2 4 NIL ofnI |
0 | 7 |
#====================================================================== |
8 |
||
3
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
9 |
# HISTORY: |
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
10 |
# Dec 30, 2010: - created |
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
11 |
# Oct 5, 2011: - sscorr_w temporarily disabled |
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
12 |
# - re-enabled |
5
509cc9966b68
======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
13 |
# Oct 26, 2011: - BUG? in calc_binDepth() on very shallow station 38 in |
509cc9966b68
======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
14 |
# 2010 Gom Spill data set the uplooker code did not stop |
509cc9966b68
======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
15 |
# at the surface, requiring additon of another test |
15 | 16 |
# Mar 4, 2014: - added support for missing TILT (PITCH/ROLL) |
45
6d49c7420a6c
stable V1.3beta, just before implementing bin interpolation
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
15
diff
changeset
|
17 |
# May 12, 2016: - removed unused lines of code |
6d49c7420a6c
stable V1.3beta, just before implementing bin interpolation
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
15
diff
changeset
|
18 |
# May 18, 2016: - removed assumption of 1500m/s soundspeed setting |
6d49c7420a6c
stable V1.3beta, just before implementing bin interpolation
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
15
diff
changeset
|
19 |
# - made sscorr_w return nan on undef'd input vel |
46 | 20 |
# May 24, 2016: - calc_binDepths() -> binDepths() |
21 |
# - added caching to binDepths |
|
54 | 22 |
# Jun 29, 2020: - renamed sscorr_w to remove conflict with RDI_Coords.pl |
3
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
23 |
|
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
24 |
# NOTES: |
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
25 |
# In an effort to track down the scale bias, NBP0901 stn 160 was reprocessed with various |
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
26 |
# simplified soundspeed correction methods: |
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
27 |
# 1) no sscorr: bias is depth dependent and disappears btw 2500 and 3000m |
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
28 |
# 2) simplified (dBin/dADCP): very similar to full correction, esp. when dBin is used |
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
29 |
# 3) hacked correction (1450m/s vs 1500m/s assumed soundspeed) => bias largely disappears |
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
30 |
|
54 | 31 |
sub sscorr_LADCP_w($$$$$) # sound-speed correction for w |
0 | 32 |
{ # see RDI Coord. Trans. manual sec. 4.1, ... |
45
6d49c7420a6c
stable V1.3beta, just before implementing bin interpolation
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
15
diff
changeset
|
33 |
my($wObs,$wCTD,$ssADCP,$dADCP,$dBin) = @_; # but there is an error: the ^2 applies to the [] |
6d49c7420a6c
stable V1.3beta, just before implementing bin interpolation
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
15
diff
changeset
|
34 |
return nan unless numberp($wObs); |
0 | 35 |
my($tanSqBeamAngle) = tan(rad($LADCP{BEAM_ANGLE}))**2; |
36 |
||
37 |
$dADCP = int($dADCP); # @sVelProf is binned to 1m |
|
38 |
$dBin = int($dBin); |
|
39 |
||
40 |
while (!numberp($sVelProf[$dADCP])) { $dADCP--; } # skip gaps & bottom of profile |
|
41 |
while (!numberp($sVelProf[$dBin ])) { $dBin--; } |
|
42 |
||
43 |
my($Kn) = sqrt(1 + (1 - $sVelProf[$dBin]/$sVelProf[$dADCP])**2 * $tanSqBeamAngle); |
|
45
6d49c7420a6c
stable V1.3beta, just before implementing bin interpolation
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
15
diff
changeset
|
44 |
return ($wObs*$sVelProf[$dBin]/$ssADCP - $wCTD) / $Kn; # full correction |
0 | 45 |
} |
46 |
||
46 | 47 |
sub binDepths($) # see RDI Coord Trans manual sec. 4.2 |
0 | 48 |
{ |
49 |
my($ens) = @_; |
|
46 | 50 |
|
51 |
return @{$LADCP{ENSEMBLE}[$ens]->{BIN_DEPTHS}} # cached result |
|
52 |
if (@{$LADCP{ENSEMBLE}[$ens]->{BIN_DEPTHS}}); |
|
53 |
||
54 |
my(@bindz); # if not cached => calculate |
|
0 | 55 |
|
15 | 56 |
# if the following assertion fails, the entire code needs to be searched for |
57 |
# each call of calc_binDepths() needs to be protected by a test |
|
58 |
die("ensemble $ens") unless defined($LADCP{ENSEMBLE}[$ens]->{TILT}); |
|
59 |
||
0 | 60 |
my($tanSqBeamAngle) = tan(rad($LADCP{BEAM_ANGLE}))**2; |
61 |
my($curdz) = 0; # calc avg sndspeed btw transducer & 1st bin |
|
62 |
$curdz-- until numberp($sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)]); |
|
63 |
my($avgss) = my($ADCPss) = $sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)]; |
|
64 |
||
65 |
my($sumss) = my($nss) = 0; |
|
66 |
if ($LADCP{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}) { |
|
67 |
while ($curdz >= -$LADCP{DISTANCE_TO_BIN1_CENTER}*cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT}))) { |
|
68 |
if (numberp($sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)])) { |
|
69 |
$sumss += $sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)]; $nss++; |
|
70 |
} |
|
71 |
$curdz--; |
|
72 |
} |
|
73 |
} else { |
|
74 |
while ($curdz <= $LADCP{DISTANCE_TO_BIN1_CENTER}*cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT}))) { |
|
75 |
if (numberp($sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)])) { |
|
76 |
$sumss += $sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)]; $nss++; |
|
77 |
} |
|
78 |
$curdz++; |
|
79 |
} |
|
80 |
} |
|
81 |
$avgss = $sumss/$nss if ($nss>0); |
|
82 |
||
83 |
my($Kn) = sqrt(1 + (1 - $avgss/$ADCPss)**2 * $tanSqBeamAngle); |
|
84 |
$bindz[0] = $LADCP{ENSEMBLE}[$ens]->{XDUCER_FACING_UP} ? |
|
45
6d49c7420a6c
stable V1.3beta, just before implementing bin interpolation
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
15
diff
changeset
|
85 |
- $LADCP{DISTANCE_TO_BIN1_CENTER}*$Kn*$avgss/$LADCP{ENSEMBLE}[$ens]->{SPEED_OF_SOUND}*cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT})) : |
6d49c7420a6c
stable V1.3beta, just before implementing bin interpolation
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
15
diff
changeset
|
86 |
+ $LADCP{DISTANCE_TO_BIN1_CENTER}*$Kn*$avgss/$LADCP{ENSEMBLE}[$ens]->{SPEED_OF_SOUND}*cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT})); |
0 | 87 |
|
88 |
for (my($bin)=1; $bin<=$LADCP_lastBin-1; $bin++) { |
|
89 |
$sumss = $nss = 0; |
|
90 |
if ($LADCP{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}) { |
|
91 |
while ($curdz >= $bindz[$bin-1]-$LADCP{BIN_LENGTH}*cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT}))) { |
|
5
509cc9966b68
======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
92 |
last unless (int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz) >= 0); |
0 | 93 |
if (numberp($sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)])) { |
94 |
$sumss += $sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)]; $nss++; |
|
95 |
} |
|
96 |
$curdz--; |
|
97 |
} |
|
98 |
} else { |
|
99 |
while ($curdz <= $bindz[$bin-1]+$LADCP{BIN_LENGTH}*cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT}))) { |
|
100 |
if (numberp($sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)])) { |
|
101 |
$sumss += $sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)]; $nss++; |
|
102 |
} |
|
103 |
$curdz++; |
|
104 |
} |
|
105 |
} |
|
106 |
$avgss = $sumss/$nss if ($nss > 0); # otherwise, leave avgss as is |
|
107 |
||
108 |
$Kn = sqrt(1 + (1 - $avgss/$ADCPss)**2 * $tanSqBeamAngle); |
|
109 |
$bindz[$bin] = $LADCP{ENSEMBLE}[$ens]->{XDUCER_FACING_UP} ? |
|
45
6d49c7420a6c
stable V1.3beta, just before implementing bin interpolation
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
15
diff
changeset
|
110 |
$bindz[$bin-1] - $LADCP{BIN_LENGTH}*$Kn*$avgss/$LADCP{ENSEMBLE}[$ens]->{SPEED_OF_SOUND}*cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT})) : |
6d49c7420a6c
stable V1.3beta, just before implementing bin interpolation
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
15
diff
changeset
|
111 |
$bindz[$bin-1] + $LADCP{BIN_LENGTH}*$Kn*$avgss/$LADCP{ENSEMBLE}[$ens]->{SPEED_OF_SOUND}*cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT})); |
0 | 112 |
} |
113 |
||
46 | 114 |
for (my($i)=0; $i<@bindz; $i++) { # cache result |
115 |
$LADCP{ENSEMBLE}[$ens]->{BIN_DEPTHS}[$i] = $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH} + $bindz[$i]; |
|
0 | 116 |
} |
46 | 117 |
return @{$LADCP{ENSEMBLE}[$ens]->{BIN_DEPTHS}}; # return result |
0 | 118 |
} |
119 |
||
120 |
1; |