2
|
1 |
#======================================================================
|
|
2 |
# F I N D _ S E A B E D . P L
|
|
3 |
# doc: Sun May 23 20:26:11 2010
|
|
4 |
# dlm: Thu Dec 30 21:45:02 2010
|
|
5 |
# (c) 2010 A.M. Thurnherr
|
|
6 |
# uE-Info: 12 0 NIL 0 0 72 0 2 4 NIL ofnI
|
|
7 |
#======================================================================
|
|
8 |
|
|
9 |
# HISTORY:
|
|
10 |
# May 23, 2010: - adapted from [perl-tools/RDI_Utils.pl]
|
|
11 |
# Dec 25, 2010: - adapted to changes in [LADCP_w]
|
|
12 |
|
|
13 |
# NOTES:
|
|
14 |
# 1) BT range is corrected for sound speed at the transducer. This is not
|
|
15 |
# accurate, but unlikely to be very wrong, at least for deep casts,
|
|
16 |
# because the vertical sound speed variability near the seabed tends
|
|
17 |
# to be small. The seabed depth is only used for sidelobe editing,
|
|
18 |
# which is done with a generous safety margin (from the UH shear
|
|
19 |
# method implementation).
|
|
20 |
# 2) Acquisition sound speed of 1500m/s assumed.
|
|
21 |
# 3) To be reasonably accurate, DEPTH must be from the CTD at this stage.
|
|
22 |
|
|
23 |
#======================================================================
|
|
24 |
# (seabed median depth, mad) = find_seabed(dta ptr, btm ensno, coord flag)
|
|
25 |
#======================================================================
|
|
26 |
|
|
27 |
my($search_width) = 200; # # of ensembles around bottom to search
|
|
28 |
my($mode_width) = 10; # max range of bottom around mode
|
|
29 |
my($min_dist) = 20; # min dist to seabed for good data
|
|
30 |
my($z_offset) = 10000; # shift z to ensure +ve array indices
|
|
31 |
|
|
32 |
sub find_seabed($$$)
|
|
33 |
{
|
|
34 |
my($d,$be,$beamCoords) = @_;
|
|
35 |
my($i,$dd,$sd,$nd);
|
|
36 |
my(@guesses);
|
|
37 |
|
|
38 |
return undef unless ($be-$search_width >= 0 &&
|
|
39 |
$be+$search_width <= $#{$d->{ENSEMBLE}});
|
|
40 |
for ($i=$be-$search_width; $i<=$be+$search_width; $i++) {
|
|
41 |
next unless (defined($d->{ENSEMBLE}[$i]->{CTD_DEPTH}) &&
|
|
42 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[0]) &&
|
|
43 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[1]) &&
|
|
44 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[2]) &&
|
|
45 |
defined($d->{ENSEMBLE}[$i]->{BT_RANGE}[3]));
|
|
46 |
my(@BT) = $beamCoords
|
|
47 |
? velInstrumentToEarth($d,$i,
|
|
48 |
velBeamToInstrument($d,
|
|
49 |
@{$d->{ENSEMBLE}[$i]->{BT_VELOCITY}}))
|
|
50 |
: velApplyHdgBias($d,$i,@{$d->{ENSEMBLE}[$i]->{BT_VELOCITY}});
|
|
51 |
next unless (abs($BT[3]) < 0.05);
|
|
52 |
$d->{ENSEMBLE}[$i]->{DEPTH_BT} =
|
|
53 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[0]/4 +
|
|
54 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[1]/4 +
|
|
55 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[2]/4 +
|
|
56 |
$d->{ENSEMBLE}[$i]->{BT_RANGE}[3]/4;
|
|
57 |
$d->{ENSEMBLE}[$i]->{DEPTH_BT} *= cos(rad($d->{BEAM_ANGLE}));
|
|
58 |
$d->{ENSEMBLE}[$i]->{DEPTH_BT} *= $CTD{SVEL}[$d->{ENSEMBLE}[$i]->{CTD_SCAN}]/1500;
|
|
59 |
next unless ($d->{ENSEMBLE}[$i]->{DEPTH_BT} >= $min_dist);
|
|
60 |
$d->{ENSEMBLE}[$i]->{DEPTH_BT} *= -1
|
|
61 |
if ($d->{ENSEMBLE}[$i]->{XDUCER_FACING_UP});
|
|
62 |
$d->{ENSEMBLE}[$i]->{DEPTH_BT} += $d->{ENSEMBLE}[$i]->{CTD_DEPTH};
|
|
63 |
if ($d->{ENSEMBLE}[$i]->{DEPTH_BT} > $d->{ENSEMBLE}[$be]->{CTD_DEPTH}) {
|
|
64 |
$guesses[int($d->{ENSEMBLE}[$i]->{DEPTH_BT})+$z_offset]++;
|
|
65 |
$nd++;
|
|
66 |
} else {
|
|
67 |
undef($d->{ENSEMBLE}[$i]->{DEPTH_BT});
|
|
68 |
}
|
|
69 |
}
|
|
70 |
return undef unless ($nd>5);
|
|
71 |
|
|
72 |
my($mode,$nmax);
|
|
73 |
for ($i=0; $i<=$#guesses; $i++) { # find mode
|
|
74 |
$nmax=$guesses[$i],$mode=$i-$z_offset
|
|
75 |
if ($guesses[$i] > $nmax);
|
|
76 |
}
|
|
77 |
|
|
78 |
$nd = 0;
|
|
79 |
for ($i=$be-$search_width; $i<=$be+$search_width; $i++) {
|
|
80 |
next unless defined($d->{ENSEMBLE}[$i]->{DEPTH_BT});
|
|
81 |
if (abs($d->{ENSEMBLE}[$i]->{DEPTH_BT}-$mode) <= $mode_width) {
|
|
82 |
$dd += $d->{ENSEMBLE}[$i]->{DEPTH_BT};
|
|
83 |
$nd++;
|
|
84 |
} else {
|
|
85 |
undef($d->{ENSEMBLE}[$i]->{DEPTH_BT});
|
|
86 |
}
|
|
87 |
}
|
|
88 |
return undef unless ($nd >= 2);
|
|
89 |
|
|
90 |
$dd /= $nd;
|
|
91 |
for ($i=$be-$search_width; $i<=$be+$search_width; $i++) {
|
|
92 |
next unless defined($d->{ENSEMBLE}[$i]->{DEPTH_BT});
|
|
93 |
$sd += ($d->{ENSEMBLE}[$i]->{DEPTH_BT}-$dd)**2;
|
|
94 |
}
|
|
95 |
|
|
96 |
return ($dd, sqrt($sd/($nd-1)));
|
|
97 |
}
|
|
98 |
|