--- a/edit_data.pl Wed May 25 12:14:29 2016 -0400
+++ b/edit_data.pl Fri Aug 05 11:02:51 2016 -0400
@@ -1,9 +1,9 @@
#======================================================================
# E D I T _ D A T A . P L
# doc: Sat May 22 21:35:55 2010
-# dlm: Tue May 24 16:36:37 2016
+# dlm: Mon Jun 6 21:13:28 2016
# (c) 2010 A.M. Thurnherr
-# uE-Info: 374 18 NIL 0 0 72 2 2 4 NIL ofnI
+# uE-Info: 543 0 NIL 0 0 72 2 2 4 NIL ofnI
#======================================================================
# HISTORY:
@@ -35,18 +35,25 @@
# Jan 23, 2016: - added &editBadTimeLagging()
# May 18, 2016: - removed assumption of 1500m/s soundspeed setting
# May 24, 2016: - calc_binDepths() -> binDepths()
+# May 28, 2016: - added editResiduals_rmsMax, editResiduals_deltaMax
+# Jun 2, 2016: - added applyTiltCorrection()
+# - maded editCorr_Earthcoords() less conservative
+# - verified that removed velocities are counted correctly
+# Jun 3, 2016: - BUG: applyTiltCorrection() did not use gimbal_pitch
+# Jun 6, 2016: - removed applyTiltCorrection()
# NOTES:
-# - editCorr_Earthcoords() is overly conservative and removed most
-# or all 3-beam solutions
# - all bins must be edited (not just the ones between $LADCP_firstBin
# and $LADCP_lastBin to allow reflr calculations to use bins outside
# this range (ONLY FOR BEAM-COORD EDITS)
# - however, to make the stats work, only the edited velocities
-# inside the bin range are counted
+# inside the bin range are counted for those edit functions that
+# report their stats wrt $nvw (for those which use $nvv,
+# all velocities must be counted)
#======================================================================
# correctAttitude($ens,$pitch_bias,$roll_bias,$heading_bias)
+# - this is called before gimbal_pitch is calculated
#======================================================================
sub correctAttitude($$$$)
@@ -59,6 +66,10 @@
#======================================================================
# $vv = countValidVels($ens)
+#
+# NOTES:
+# - in case of Earth coords, this counts the velocity components
+# (including errvel)
#======================================================================
sub countValidBeamVels($)
@@ -79,7 +90,8 @@
# $removed = editCorr($ens,$threshold)
#
# NOTES:
-# - called before Earth vels have been calculated
+# - called before Earth vels are calculated
+# - count removed velocities in all bins
#======================================================================
sub editCorr($$)
@@ -102,12 +114,11 @@
# $removed = editCorr_Earthcoords($ens,$threshold)
#
# NOTES:
-# - if any of the 4 beam correlations is below the threshold,
+# - if any of the used correlations is below the threshold,
# the entire velocity is removed
-# - this implies that (most? all?) three-beam solutions will
-# be edited out, which is overly conserative
-# - a potentially better algorithm (used in LADCPproc) ignores the
-# lowest correlation in all 3-beam solutions
+# - for three-beam solutions two correlations must fail the
+# test
+# - count velocities in all bins
#======================================================================
sub editCorr_Earthcoords($$)
@@ -116,14 +127,14 @@
my($nrm) = 0;
for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
- my($beam);
- for ($beam=0; $beam<4; $beam++) {
- last unless ($LADCP{ENSEMBLE}[$ens]->{CORRELATION}[$bin][$beam] >= $lim);
+ my($nBad) = 0;
+ for (my($beam)=0; $beam<4; $beam++) {
+ $nBad++ unless ($LADCP{ENSEMBLE}[$ens]->{CORRELATION}[$bin][$beam] > $lim);
}
- if ($beam < 4) {
- for (my($c)=0; $c<4; $c++) {
- next unless defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$c]);
- undef($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$c]);
+ if ($nBad-$LADCP{ENSEMBLE}[$ens]->{THREE_BEAM}[$bin] > 0) {
+ for (my($beam)=0; $beam<4; $beam++) {
+ next unless defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$beam]);
+ undef($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$beam]);
$nrm++;
}
}
@@ -137,6 +148,7 @@
# NOTES:
# - called after Earth vels have been calculated
# - sets TILT field for each ensemble as a side-effect
+# - count all removed velocities
#======================================================================
sub editTilt($$)
@@ -209,6 +221,7 @@
#
# NOTES:
# - call after Earth vels have been calculated
+# - count only removed vels in selected bin range
#======================================================================
sub editTruncRange($$)
@@ -232,6 +245,7 @@
# - remove data from far bins
# - only bins in valid range are considered here, because
# $per_bin_nsamp is only defined for those
+# - only velocities from bins in valid range are counted
#======================================================================
sub editFarBins($$)
@@ -255,6 +269,8 @@
# along-beam soundspeed variation, but the soundspeed at the transducer is accounted for.
# 2) for surface sidelobes, water_depth == undef; surface sidelobes include the
# vessel draft
+# - all velocities are counted, even those outside valid bin range,
+# because the %age is not reported
#======================================================================
sub editSideLobes($$$)
@@ -290,6 +306,7 @@
# ($nvrm,$nerm) = editPPI($fromEns,$toEns,$water_depth)
#
# NOTES:
+# - only velocities in good bin range are removed/counted
# - for UL, water_depth == undef; for DL water_depth is always defined,
# or else editPPI is not called
# - when this code is executed a suitable UL or DL depth-average-soundspeed
@@ -422,6 +439,9 @@
#===============================================================================
# $nerm = editBadTimeLagging($fromEns,$toEns,$good_from_elapsed1,$good_to_elapsed1,...)
+#
+# NOTES:
+# - deleted velocities are not counted
#===============================================================================
sub editBadTimeLagging($$@)
@@ -458,5 +478,69 @@
return $nerm;
}
+#======================================================================
+# $nerm = editResiduals_rmsMax($fe,$te,$max_val)
+#
+# NOTES:
+# - removed velocities are not counted
+#======================================================================
+
+sub editResiduals_rmsMax($$$)
+{
+ my($fe,$te,$limit) = @_;
+ my($nerm) = 0;
+ for (my($ens)=$fe; $ens<=$te; $ens++) {
+ next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
+ my($sum) = my($n) = 0; # calculate rms residual
+ my(@bindepth) = binDepths($ens);
+ for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
+ next unless ($bin+1>=$outGrid_firstBin && $bin+1<=$outGrid_lastBin);
+ next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
+ my($bi) = $bindepth[$bin]/$opt_o;
+ my($res) = ($ens < $LADCP_atbottom) ?
+ $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] - $DNCAST{MEDIAN_W}[$bi] :
+ $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] - $UPCAST{MEDIAN_W}[$bi];
+ $sum += &SQR($res); $n++;
+ }
+ if ($n == 0 || sqrt($sum/$n) > $limit) { # ensemble is bad
+ undef($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
+ $nerm++;
+ }
+ }
+ return $nerm;
+}
+
+#======================================================================
+# $nerm = editResiduals_deltaMax($fe,$te,$max_val)
+# - delta residual = delta beampair w => equal to scaled error velocity?
+# - sharp cutoff near 5cm/s for std parameters (0.1 m/s error velocity
+# filter) in several data sets
+# - samples with large residuals differences are clear outliers in
+# the residuals vs tilt plots => obvious to remove
+# - how are large delta res possible given the errvel limit???
+# - only valid bin range is edited/counted
+#======================================================================
+
+sub editResiduals_deltaMax($$$)
+{
+ my($fe,$te,$limit) = @_;
+ my($nvrm) = 0;
+ for (my($ens)=$fe; $ens<=$te; $ens++) {
+ next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
+ for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
+ next unless ($bin+1>=$outGrid_firstBin && $bin+1<=$outGrid_lastBin);
+ next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
+ my($Dr) = abs($LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin] -
+ $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin]);
+ if ($Dr > $limit) {
+ undef($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
+ $nvrm++;
+ }
+ }
+ }
+ return $nvrm;
+}
+
+#======================================================================
1;