author | A.M. Thurnherr <athurnherr@yahoo.com> |
Fri, 05 Aug 2016 11:02:51 -0400 | |
changeset 47 | 2ccb81b7cea5 |
parent 46 | cc6c4309828a |
child 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 |
|
46 | 4 |
# dlm: Tue May 24 16:44:07 2016 |
0 | 5 |
# (c) 2010 A.M. Thurnherr |
46 | 6 |
# uE-Info: 116 64 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 |
|
3
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
22 |
|
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
23 |
# NOTES: |
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
24 |
# 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
|
25 |
# simplified soundspeed correction methods: |
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
0
diff
changeset
|
26 |
# 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
|
27 |
# 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
|
28 |
# 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
|
29 |
|
45
6d49c7420a6c
stable V1.3beta, just before implementing bin interpolation
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
15
diff
changeset
|
30 |
sub sscorr_w($$$$$) # sound-speed correction for w |
0 | 31 |
{ # 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
|
32 |
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
|
33 |
return nan unless numberp($wObs); |
0 | 34 |
my($tanSqBeamAngle) = tan(rad($LADCP{BEAM_ANGLE}))**2; |
35 |
||
36 |
$dADCP = int($dADCP); # @sVelProf is binned to 1m |
|
37 |
$dBin = int($dBin); |
|
38 |
||
39 |
while (!numberp($sVelProf[$dADCP])) { $dADCP--; } # skip gaps & bottom of profile |
|
40 |
while (!numberp($sVelProf[$dBin ])) { $dBin--; } |
|
41 |
||
42 |
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
|
43 |
return ($wObs*$sVelProf[$dBin]/$ssADCP - $wCTD) / $Kn; # full correction |
0 | 44 |
} |
45 |
||
46 | 46 |
sub binDepths($) # see RDI Coord Trans manual sec. 4.2 |
0 | 47 |
{ |
48 |
my($ens) = @_; |
|
46 | 49 |
|
50 |
return @{$LADCP{ENSEMBLE}[$ens]->{BIN_DEPTHS}} # cached result |
|
51 |
if (@{$LADCP{ENSEMBLE}[$ens]->{BIN_DEPTHS}}); |
|
52 |
||
53 |
my(@bindz); # if not cached => calculate |
|
0 | 54 |
|
15 | 55 |
# if the following assertion fails, the entire code needs to be searched for |
56 |
# each call of calc_binDepths() needs to be protected by a test |
|
57 |
die("ensemble $ens") unless defined($LADCP{ENSEMBLE}[$ens]->{TILT}); |
|
58 |
||
0 | 59 |
my($tanSqBeamAngle) = tan(rad($LADCP{BEAM_ANGLE}))**2; |
60 |
my($curdz) = 0; # calc avg sndspeed btw transducer & 1st bin |
|
61 |
$curdz-- until numberp($sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)]); |
|
62 |
my($avgss) = my($ADCPss) = $sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)]; |
|
63 |
||
64 |
my($sumss) = my($nss) = 0; |
|
65 |
if ($LADCP{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}) { |
|
66 |
while ($curdz >= -$LADCP{DISTANCE_TO_BIN1_CENTER}*cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT}))) { |
|
67 |
if (numberp($sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)])) { |
|
68 |
$sumss += $sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)]; $nss++; |
|
69 |
} |
|
70 |
$curdz--; |
|
71 |
} |
|
72 |
} else { |
|
73 |
while ($curdz <= $LADCP{DISTANCE_TO_BIN1_CENTER}*cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT}))) { |
|
74 |
if (numberp($sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)])) { |
|
75 |
$sumss += $sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)]; $nss++; |
|
76 |
} |
|
77 |
$curdz++; |
|
78 |
} |
|
79 |
} |
|
80 |
$avgss = $sumss/$nss if ($nss>0); |
|
81 |
||
82 |
my($Kn) = sqrt(1 + (1 - $avgss/$ADCPss)**2 * $tanSqBeamAngle); |
|
83 |
$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
|
84 |
- $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
|
85 |
+ $LADCP{DISTANCE_TO_BIN1_CENTER}*$Kn*$avgss/$LADCP{ENSEMBLE}[$ens]->{SPEED_OF_SOUND}*cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT})); |
0 | 86 |
|
87 |
for (my($bin)=1; $bin<=$LADCP_lastBin-1; $bin++) { |
|
88 |
$sumss = $nss = 0; |
|
89 |
if ($LADCP{ENSEMBLE}[$ens]->{XDUCER_FACING_UP}) { |
|
90 |
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
|
91 |
last unless (int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz) >= 0); |
0 | 92 |
if (numberp($sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)])) { |
93 |
$sumss += $sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)]; $nss++; |
|
94 |
} |
|
95 |
$curdz--; |
|
96 |
} |
|
97 |
} else { |
|
98 |
while ($curdz <= $bindz[$bin-1]+$LADCP{BIN_LENGTH}*cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT}))) { |
|
99 |
if (numberp($sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)])) { |
|
100 |
$sumss += $sVelProf[int($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH}+$curdz)]; $nss++; |
|
101 |
} |
|
102 |
$curdz++; |
|
103 |
} |
|
104 |
} |
|
105 |
$avgss = $sumss/$nss if ($nss > 0); # otherwise, leave avgss as is |
|
106 |
||
107 |
$Kn = sqrt(1 + (1 - $avgss/$ADCPss)**2 * $tanSqBeamAngle); |
|
108 |
$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
|
109 |
$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
|
110 |
$bindz[$bin-1] + $LADCP{BIN_LENGTH}*$Kn*$avgss/$LADCP{ENSEMBLE}[$ens]->{SPEED_OF_SOUND}*cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT})); |
0 | 111 |
} |
112 |
||
46 | 113 |
for (my($i)=0; $i<@bindz; $i++) { # cache result |
114 |
$LADCP{ENSEMBLE}[$ens]->{BIN_DEPTHS}[$i] = $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH} + $bindz[$i]; |
|
0 | 115 |
} |
46 | 116 |
return @{$LADCP{ENSEMBLE}[$ens]->{BIN_DEPTHS}}; # return result |
0 | 117 |
} |
118 |
||
119 |
1; |