acoustic_backscatter.pl
author A.M. Thurnherr <athurnherr@yahoo.com>
Mon, 20 Apr 2015 14:04:04 +0000
changeset 28 b07b23485336
parent 27 2053d8de8d6b
child 29 c1ff35103176
permissions -rw-r--r--
after folding in EGU flight mods (empirical Sv correction)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     1
#======================================================================
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     2
#                    A C O U S T I C _ B A C K S C A T T E R . P L 
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     3
#                    doc: Wed Oct 20 13:02:27 2010
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
     4
#                    dlm: Mon Apr 20 13:56:56 2015
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     5
#                    (c) 2010 A.M. Thurnherr
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
     6
#                    uE-Info: 24 71 NIL 0 0 72 0 2 4 NIL ofnI
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     7
#======================================================================
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     8
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     9
# HISTORY:
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    10
#	Oct 20, 2010: - created
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    11
#	Dec 10, 2010: - BUG: backscatter above sea surface made code bomb
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    12
#						 when run with uplooker data
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    13
#	Dec 30, 2010: - adapted for use with [LADCP_w]
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
    14
#	Oct 19, 2011: - added support for $SS_{min,max}_allowed_range
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
    15
#				  - BUG: acoustic-backscatter assumed 0 deg C
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
    16
#				  - SV now saved in ensemble
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
    17
#	Oct 21, 2011: - BUG: made code work for uplooker again
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    18
#	Mar  4, 2014: - added support for missing PITCH/ROLL (TILT)
18
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 15
diff changeset
    19
#	Apr 17, 2014: - BUG: missing ;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 15
diff changeset
    20
#	Nov  7, 2014: - BUG: calc_binDepths() was called without valid CTD depth
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
    21
#				  - added $SS_use_BT, $SS_min_signal, $SS_min_samp
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
    22
#	Apr 20, 2015: - added comments
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
    23
#				  - removed SS_{min,max}_allowed_range from calc_backscatter_profs()
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
    24
#				  - added correct_backscatter() & linterp() from laptop
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    25
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    26
#----------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    27
# Volume Scattering Coefficient, following Deines (IEEE 1999)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    28
# NOTES:
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    29
#	- instrument specific! (300kHz Workhorse)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    30
#   - no sound-speed correction applied
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    31
#   - R in bin center, instead of last quarter
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    32
#   - transmit power assumes 33V batteries
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
    33
# EMPIRICAL FINDINGS (after applying the empirical correction)
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
    34
#  - Sv(WH300) ~ Sv(WH150)/1.4-34
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
    35
#      - based on DoMORE-1: 004, 005
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
    36
#      - identical instrument setup (0/8/8m)
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
    37
#      - 003, with higher scattering is somewhat different
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    38
#----------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    39
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    40
# NB:
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    41
#	- correction seems to work for a subset of bins (~bins 3-9 for 
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    42
#	  2010 P403 station 46) 
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    43
#	- this may imply that noise level depends on bin
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    44
# 	- far bins are important for seabed detection, i.e. cannot simply
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    45
#	  be discarded at this stage
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    46
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    47
sub Sv($$$$$)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    48
{
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    49
    my($temp,$PL,$Er,$R,$EA) = @_;
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
    50
    my($C)      = -143;                 # RDI WHM300 (from Deines)
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    51
    my($Ldbm)   = 10 * log10($PL);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    52
    my($PdbW)   = 14.0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    53
    my($alpha)  = 0.069;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    54
    my($Kc)     = 0.45;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    55
    
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    56
    return $C + 10*log10(($temp+273)*$R**2) - $Ldbm - $PdbW
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    57
              + 2*$alpha*$R + $Kc*($EA-$Er);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    58
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    59
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    60
#----------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    61
# Calculate per-bin backscatter profiles
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    62
#	input: 	first and last valid LADCP ensemble
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    63
#	output:	sSv[$depth][$bin]	sum of volume scattering coefficients
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    64
#			nSv[$depth][$bin]	number of samples in bin
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    65
#----------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    66
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    67
my(@sSv,@nSv);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    68
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    69
sub calc_backscatter_profs($$)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    70
{
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    71
	my($LADCP_start,$LADCP_end) = @_;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    72
	
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    73
	my(@Er) = (1e99,1e99,1e99,1e99);						# echo intensity reference level
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    74
	for (my($ens)=$LADCP_start; $ens<=$LADCP_end; $ens++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    75
		$Er[0] = $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$LADCP{N_BINS}-1][0]
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    76
			if ($LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$LADCP{N_BINS}-1][0] < $Er[0]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    77
		$Er[1] = $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$LADCP{N_BINS}-1][1]
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    78
			if ($LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$LADCP{N_BINS}-1][1] < $Er[1]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    79
		$Er[2] = $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$LADCP{N_BINS}-1][2]
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    80
			if ($LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$LADCP{N_BINS}-1][2] < $Er[2]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    81
		$Er[3] = $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$LADCP{N_BINS}-1][3]
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    82
			if ($LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$LADCP{N_BINS}-1][3] < $Er[3]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    83
    }
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    84
	debugmsg("per-beam noise levels = @Er\n");
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    85
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    86
	my($cosBeamAngle) = cos(rad($LADCP{BEAM_ANGLE}));
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    87
	for (my($ens)=$LADCP_start; $ens<=$LADCP_end; $ens++) {
18
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 15
diff changeset
    88
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    89
		my(@bd) = calc_binDepths($ens);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    90
		for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    91
			my($depth) = int($bd[$bin]);
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    92
			next if ($depth<0 || !defined($LADCP{ENSEMBLE}[$ens]->{TILT}));
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
    93
			my($range_to_bin) = abs($bd[$bin] - $LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH})
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    94
									/ cos(rad($LADCP{ENSEMBLE}[$ens]->{TILT}))
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    95
									/ $cosBeamAngle;
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
    96
#			next
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
    97
#				if ($range_to_bin < $SS_min_allowed_range ||
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
    98
#					$range_to_bin > $SS_max_allowed_range);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
    99
			my($temp) = defined($CTD_temp)
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   100
					  ? $CTD{TEMP}[$LADCP{ENSEMBLE}[$ens]->{CTD_SCAN}]
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   101
					  : $LADCP{ENSEMBLE}[$ens]->{TEMPERATURE};
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   102
			$LADCP{ENSEMBLE}[$ens]->{SV}[$bin] =
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   103
				median(
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   104
					Sv($temp,$LADCP{TRANSMITTED_PULSE_LENGTH},$Er[0],$range_to_bin,
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   105
					   $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][0]
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   106
				    ),
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   107
				    Sv($temp,$LADCP{TRANSMITTED_PULSE_LENGTH},$Er[1],$range_to_bin,
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   108
					   $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][1]
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   109
					),
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   110
					Sv($temp,$LADCP{TRANSMITTED_PULSE_LENGTH},$Er[2],$range_to_bin,
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   111
					   $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][2]
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   112
					),
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   113
					Sv($temp,$LADCP{TRANSMITTED_PULSE_LENGTH},$Er[3],$range_to_bin,
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   114
	     			   $LADCP{ENSEMBLE}[$ens]->{ECHO_AMPLITUDE}[$bin][3]
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   115
					)
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   116
				);
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   117
    		$sSv[$depth][$bin] += $LADCP{ENSEMBLE}[$ens]->{SV}[$bin];
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   118
			$nSv[$depth][$bin]++;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   119
		}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   120
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   121
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   122
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   123
#----------------------------------------------------------------------
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   124
# empirically adjust Sv in far bins for consistency with nearest
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   125
# valid bin
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   126
#	- based on bin-to-bin differences of 100m vertically averaged Sv
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   127
#	  profiles
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   128
#	- algorithm can leave artifacts in the near bins near bottom
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   129
#	  turn-around (DM1#001)
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   130
#----------------------------------------------------------------------
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   131
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   132
sub linterp($$$$$)
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   133
{
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   134
	my($x,$mix,$max,$miy,$may) = @_;
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   135
	return $miy + ($x-$mix)/($max-$mix)*($may-$miy);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   136
}
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   137
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   138
$Sv_ref_bin = 1;  # bin 2 is slightly better than bin 5 => use closest bin as reference as originally intended
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   139
				  # default setting choses first bin with data; do not set to values below 1
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   140
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   141
sub correct_backscatter($$)
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   142
{
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   143
	my($LADCP_start,$LADCP_end) = @_;
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   144
	my($bin) = $LADCP_firstBin-1;
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   145
	my(@refSvProf,@refSvSamp,$depth,$i);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   146
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   147
RETRY:
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   148
	for ($depth=0; $depth<@nSv; $depth++) {						# create reference profile
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   149
		next unless ($nSv[$depth][$Sv_ref_bin-1] > 0);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   150
		$refSvProf[int($depth/100)] += $sSv[$depth][$Sv_ref_bin-1] / $nSv[$depth][$Sv_ref_bin-1];
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   151
		$refSvSamp[int($depth/100)]++;
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   152
    }
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   153
    $Sv_ref_bin++,goto RETRY
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   154
    	unless (@refSvSamp);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   155
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   156
	for ($i=0; $i<@refSvSamp; $i++) {
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   157
		next unless ($refSvSamp[$i] > 0);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   158
		$refSvProf[$i] /= $refSvSamp[$i];
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   159
	}
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   160
	for ($i=0; $i<5; $i++) {									# extrapolate bottom value by 500m
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   161
		push(@refSvProf,$refSvProf[$#refSvProf]);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   162
		push(@refSvSamp,$refSvSamp[$#refSvSamp]);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   163
	}
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   164
	info("\tusing bin %d as reference\n",$Sv_ref_bin);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   165
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   166
	my(@dSvProf);												# create profiles for all bins
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   167
	for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {	
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   168
		my(@dSvSamp);									
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   169
		for ($depth=0; $depth<@nSv; $depth++) {					# create Sv-difference profile for current bin
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   170
			next unless ($nSv[$depth][$bin] > 0);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   171
			$dSvProf[int($depth/100)][$bin] += $sSv[$depth][$bin] / $nSv[$depth][$bin];
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   172
			$dSvSamp[int($depth/100)]++;
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   173
		}
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   174
		for ($i=0; $i<@dSvSamp; $i++) {
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   175
			next unless ($refSvSamp[$i] > 0) && ($dSvSamp[$i] > 0);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   176
			$dSvProf[$i][$bin] = $dSvProf[$i][$bin]/$dSvSamp[$i] - $refSvProf[$i];
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   177
		}
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   178
		$dSvProf[$i][$bin] = $dSvProf[$i-1][$bin];				# extrapolate 100m
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   179
	}
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   180
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   181
    for (my($ens)=$LADCP_start; $ens<=$LADCP_end; $ens++) {		# correct Sv data
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   182
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   183
		my(@bd) = calc_binDepths($ens);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   184
		for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   185
			next unless numberp($LADCP{ENSEMBLE}[$ens]->{SV}[$bin]);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   186
			my($depth) = int($bd[$bin]);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   187
			$LADCP{ENSEMBLE}[$ens]->{SV}[$bin] -= $dSvProf[int($depth/100)][$bin];
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   188
				linterp($depth,100*int($depth/100),100*int($depth/100)+100,
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   189
						$dSvProf[int($depth/100)][$bin],$dSvProf[int($depth/100)+1][$bin]);
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   190
		}
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   191
	}
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   192
}
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   193
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   194
#----------------------------------------------------------------------
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   195
# determine location of seabed from backscatter profiles
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 18
diff changeset
   196
#	input:	depth below which seabed can possibly be (e.g. max CTD depth)
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   197
#	output:	median/mad of estimated water depth
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   198
#----------------------------------------------------------------------
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   199
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   200
sub find_backscatter_seabed($)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   201
{
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   202
	my($search_below) = int($_[0]);										# grid index to begin search
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   203
	my(@wdepth,@Sv_rng);												# list of water_depth indices
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   204
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   205
	for (my($bin)=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) { 	# find backscatter min/max below $search_below in each bin
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   206
		my($minSv,$maxSv,$depthmaxSv,$lastvalid) = (1e99,-1e99,-1,-1);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   207
		for (my($depth)=$search_below; $depth<@nSv; $depth++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   208
			next unless ($nSv[$depth][$bin] > 0);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   209
			my($Sv) = $sSv[$depth][$bin] / $nSv[$depth][$bin];
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   210
			$lastvalid = $depth;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   211
			$minSv = $Sv if ($Sv < $minSv);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   212
			$maxSv = $Sv, $depthmaxSv = $depth if ($Sv > $maxSv);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   213
		}
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   214
		if ($maxSv-$minSv >= $SS_min_signal) { 							# ignore scatter
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   215
			push(@Sv_rng,round($maxSv-$minSv));
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   216
			push(@wdepth,$depthmaxSv);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   217
		}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   218
	}
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 18
diff changeset
   219
28
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   220
	if (@wdepth) {
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   221
		info("%d bins with seabed signatures found (\@Sv_rng: @Sv_rng)\n",scalar(@wdepth));
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   222
    } else {
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   223
		info("no bins with seabed signatures found\n");
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   224
    }
b07b23485336 after folding in EGU flight mods (empirical Sv correction)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   225
	return (undef,undef) if (scalar(@wdepth) < $SS_min_samp);			# require min number of samples
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   226
	
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   227
	my($wd) = median(@wdepth);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   228
	return ($wd,mad2($wd,@wdepth));
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   229
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   230
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   231
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   232
1;