edit_data.pl
author A.M. Thurnherr <athurnherr@yahoo.com>
Sat, 24 Jul 2021 10:35:41 -0400
changeset 56 8f120b9f795a
parent 55 2d8e1139acd5
child 57 69e39fcb7f41
permissions -rw-r--r--
V2.0 - lots of bug fixes - major new features: - dropped CTD scans handled correctly (no more apparent clock drifts) - support for data files collected with Nortek Signature instruments - much improved data editing - significant changes: - no minimum limit for eps_VKE - updated for GMT6 - much better data quality information in summary plots
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
#======================================================================
55
2d8e1139acd5 adapted to Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 49
diff changeset
     2
#                    E D I T _ D A T A . P L 
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     3
#                    doc: Sat May 22 21:35:55 2010
56
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
     4
#                    dlm: Fri Jul  9 13:41:36 2021
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
     5
#                    (c) 2010 A.M. Thurnherr
56
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
     6
#                    uE-Info: 597 63 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
#	May 22, 2010: - created
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    11
#	May 24, 2010: - added editSideLobesFromSeabed()
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    12
#	Oct 29, 2010: - added editCorr_Earthcoords
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    13
#	Dec 20, 2010: - BUG: DISTANCE_TO_BIN1_CENTER & BIN_LENGTH had been
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    14
#						 interpreted as along-beam, rather than vertical
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    15
#				  - replaced editPitchRoll by editTilt
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    16
#	Dec 25, 2010: - adapted to changes in [LADCP_w]
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
    17
#	Aug  3, 2011: - added editTruncRange()
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
    18
#	Oct 10, 2011: - added editFalsePositives()
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
    19
#				  - BUG: when earth velocities were edited, all were
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
    20
#						 counted, not just those between first and lastBin
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    21
#	Oct 11, 2011: - moved defaults to [defaults.pl]
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    22
#	Oct 12, 2011: - added &editSurfLayer()
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    23
#				  - BUG: editSideLobes() was slightly loose
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
    24
#	Oct 15, 2011: - added editWOutliers()
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    25
#	Oct 20, 2011: - added editFarBins()
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    26
#	Oct 27, 2011: - adapted editTilt() to new call location
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    27
#				  - added correctAttitude()
10
7e76fdef8953 version prior to carrying out separate dc-/uc- time lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 6
diff changeset
    28
#	Oct 15, 2012: - BUG: editSurfLayer() counted also ensembles without CTD depth
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 10
diff changeset
    29
#	Nov 12, 2013: - added comments on editCorr_Earthcoords()
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
    30
#	Mar  4, 2013: - added support for missing PITCH/ROLL (TILT) & HEADING
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
    31
#	May 20, 2014: - added editPPI()
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
    32
#	May 21, 2014: - got it to work correctly
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 16
diff changeset
    33
#				  - croak -> error
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
    34
#	Sep 26, 2015: - added $vessel_draft to editSideLobes
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
    35
#	Jan 23, 2016: - added &editBadTimeLagging()
45
6d49c7420a6c stable V1.3beta, just before implementing bin interpolation
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 34
diff changeset
    36
#	May 18, 2016: - removed assumption of 1500m/s soundspeed setting
46
cc6c4309828a V1.3beta1
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 45
diff changeset
    37
#   May 24, 2016: - calc_binDepths() -> binDepths()
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
    38
#	May 28, 2016: - added editResiduals_rmsMax, editResiduals_deltaMax
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
    39
#	Jun  2, 2016: - added applyTiltCorrection()
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
    40
#				  - maded editCorr_Earthcoords() less conservative
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
    41
#				  - verified that removed velocities are counted correctly
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
    42
#	Jun  3, 2016: - BUG: applyTiltCorrection() did not use gimbal_pitch
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
    43
#	Jun  6, 2016: - removed applyTiltCorrection()
49
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
    44
#	Oct 13, 2017: - BUG: editPPI() only allowed for nominal transducer frequencies
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
    45
#	May  1, 2018: - added editLargeHSpeeds()
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
    46
#	Nov 17, 2018: - BUG: spurious letter "z" had crept in at some stage
55
2d8e1139acd5 adapted to Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 49
diff changeset
    47
#	Mar 23, 2021: - updated PPI doc
56
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
    48
#	Jul  9, 2021: - added editHighResidualLayers()
55
2d8e1139acd5 adapted to Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 49
diff changeset
    49
# END OF HISTORY
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    50
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    51
# NOTES:
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
    52
#	- all bins must be edited (not just the ones between $LADCP_firstBin
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
    53
#	  and $LADCP_lastBin to allow reflr calculations to use bins outside
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    54
#	  this range (ONLY FOR BEAM-COORD EDITS)
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
    55
#	- however, to make the stats work, only the edited velocities
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
    56
#	  inside the bin range are counted for those edit functions that
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
    57
#	  report their stats wrt $nvw (for those which use $nvv,
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
    58
#	  all velocities must be counted)
0
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
#======================================================================
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    61
# correctAttitude($ens,$pitch_bias,$roll_bias,$heading_bias)
49
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
    62
#	- attitude bias correction
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
    63
#	- this is called before gimbal_pitch is calculated
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    64
#======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    65
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    66
sub correctAttitude($$$$)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    67
{
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    68
	my($ens,$pitch_bias,$roll_bias,$heading_bias) = @_;
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
    69
	$LADCP{ENSEMBLE}[$ens]->{PITCH}   -= $pitch_bias 	if defined($LADCP{ENSEMBLE}[$ens]->{PITCH});
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
    70
	$LADCP{ENSEMBLE}[$ens]->{ROLL}    -= $roll_bias		if defined($LADCP{ENSEMBLE}[$ens]->{ROLL});
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
    71
	$LADCP{ENSEMBLE}[$ens]->{HEADING} -= $heading_bias	if defined($LADCP{ENSEMBLE}[$ens]->{HEADING});
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    72
}
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    73
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
    74
#======================================================================
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    75
# $vv = countValidVels($ens)
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
    76
#
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
    77
# NOTES:
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
    78
#	- in case of Earth coords, this counts the velocity components
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
    79
#	  (including errvel)
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    80
#======================================================================
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    81
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    82
sub countValidBeamVels($)
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
	my($ens) = @_;
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($vv) = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    87
	for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    88
		$vv += defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][0]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    89
		$vv += defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][1]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    90
		$vv += defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][2]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    91
		$vv += defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][3]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    92
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    93
	return $vv;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    94
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    95
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    96
#======================================================================
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
    97
# $removed = editCorr($ens,$threshold)
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    98
#
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
    99
# NOTES:
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   100
#	- called before Earth vels are calculated
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   101
#	- count removed velocities in all bins
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   102
#======================================================================
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   103
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   104
sub editCorr($$)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   105
{
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   106
	my($ens,$lim) = @_;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   107
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   108
	my($nrm) = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   109
	for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   110
		for (my($beam)=0; $beam<4; $beam++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   111
			next if ($LADCP{ENSEMBLE}[$ens]->{CORRELATION}[$bin][$beam] >= $lim ||
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   112
					 !defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$beam]));
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   113
			undef($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$beam]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   114
			$nrm++;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   115
		}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   116
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   117
	return $nrm;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   118
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   119
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 10
diff changeset
   120
#======================================================================
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 10
diff changeset
   121
# $removed = editCorr_Earthcoords($ens,$threshold)
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 10
diff changeset
   122
#
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 10
diff changeset
   123
# NOTES:
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   124
#	- if any of the used correlations is below the threshold,
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 10
diff changeset
   125
#	  the entire velocity is removed
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   126
#	- for three-beam solutions two correlations must fail the
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   127
#	  test
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   128
#	- count velocities in all bins
13
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 10
diff changeset
   129
#======================================================================
2788bf1bf1de after DIMES US5
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 10
diff changeset
   130
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   131
sub editCorr_Earthcoords($$)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   132
{
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   133
	my($ens,$lim) = @_;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   134
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   135
	my($nrm) = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   136
	for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   137
		my($nBad) = 0;
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   138
		for (my($beam)=0; $beam<4; $beam++) {
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   139
			$nBad++ unless ($LADCP{ENSEMBLE}[$ens]->{CORRELATION}[$bin][$beam] > $lim);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   140
		}
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   141
		if ($nBad-$LADCP{ENSEMBLE}[$ens]->{THREE_BEAM}[$bin] > 0) {
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   142
			for (my($beam)=0; $beam<4; $beam++) {
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   143
				next unless defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$beam]);
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   144
				undef($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$beam]);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   145
				$nrm++;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   146
			}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   147
		}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   148
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   149
	return $nrm;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   150
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   151
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   152
#======================================================================
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   153
# $removed = editTilt($ens,$threshold)
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   154
#
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   155
# NOTES:
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   156
#	- called after Earth vels have been calculated
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   157
#	- sets TILT field for each ensemble as a side-effect
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   158
#	- count all removed velocities
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   159
#======================================================================
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   160
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   161
sub editTilt($$)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   162
{
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   163
	my($ens,$lim) = @_;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   164
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   165
	$LADCP{ENSEMBLE}[$ens]->{TILT} =
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   166
		&angle_from_vertical($LADCP{ENSEMBLE}[$ens]->{PITCH},$LADCP{ENSEMBLE}[$ens]->{ROLL});
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   167
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   168
	return 0 unless ($LADCP{ENSEMBLE}[$ens]->{TILT} > $lim);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   169
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   170
	my($nrm) = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   171
	for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
6
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   172
		next unless defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   173
		undef($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 5
diff changeset
   174
		$nrm++;
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   175
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   176
	return $nrm;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   177
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   178
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   179
#======================================================================
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   180
# $removed = editErrVel($ens,$threshold)
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   181
#
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   182
# NOTES:
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   183
#	- call after Earth vels have been calculated
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   184
#	- count only removed vels in selected bin range
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   185
#======================================================================
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   186
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   187
sub editErrVel($$)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   188
{
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   189
	my($ens,$lim) = @_;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   190
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   191
	my($nrm) = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   192
	for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   193
		next unless defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   194
		next if (abs($LADCP{ENSEMBLE}[$ens]->{ERRVEL}[$bin]) <= $lim);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   195
		undef($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   196
		$nrm++ if ($bin>=$LADCP_firstBin-1 && $bin<=$LADCP_lastBin-1);
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   197
	}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   198
	return $nrm;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   199
}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   200
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   201
#======================================================================
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   202
# $removed = editWOutliers($ens,$lim)
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   203
#
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   204
# NOTES:
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   205
#	- call after Earth vels have been calculated
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   206
#	- count only removed vels in selected bin range
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   207
#	- lim determines how many times the mad an outlier has to be from median
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   208
#======================================================================
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   209
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   210
sub editWOutliers($$)
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   211
{
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   212
	my($ens,$lim) = @_;
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   213
	my($medw) = median(@{$LADCP{ENSEMBLE}[$ens]->{W}});
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   214
	my($madw) = mad2($medw,@{$LADCP{ENSEMBLE}[$ens]->{W}});
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   215
	
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   216
	my($nrm) = 0;
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   217
	for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   218
		next unless defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   219
		next if (abs($LADCP{ENSEMBLE}[$ens]->{W}[$bin]-$medw) <= $lim*$madw);
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   220
		undef($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   221
		$nrm++ if ($bin>=$LADCP_firstBin-1 && $bin<=$LADCP_lastBin-1);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   222
	}
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   223
	return $nrm;
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   224
}
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   225
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   226
#======================================================================
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   227
# $removed = editTruncRange($ens,$nbins)
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   228
#
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   229
# NOTES:
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   230
#	- call after Earth vels have been calculated
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   231
#	- count only removed vels in selected bin range
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   232
#======================================================================
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   233
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   234
sub editTruncRange($$)
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   235
{
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   236
	my($ens,$nbins) = @_;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   237
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   238
	my($nrm) = 0;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   239
	for (my($bin)=$LADCP{N_BINS}-1; $bin>=0 && $nrm<$nbins; $bin--) {
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   240
		next unless defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   241
		undef($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   242
		$nrm++ if ($bin>=$LADCP_firstBin-1 && $bin<=$LADCP_lastBin-1);
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   243
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   244
	return $nrm;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   245
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   246
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   247
#======================================================================
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   248
# $removed = editFarBins($ens,$first_bad_bin)
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   249
#
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   250
# NOTES:
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   251
#	- call after Earth vels have been calculated
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   252
#	- remove data from far bins
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   253
#	- only bins in valid range are considered here, because
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   254
#	  $per_bin_nsamp is only defined for those
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   255
#	- only velocities from bins in valid range are counted
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   256
#======================================================================
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   257
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   258
sub editFarBins($$)
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   259
{
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   260
	my($ens,$first_bad_bin) = @_;
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   261
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   262
	my($nrm) = 0;
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   263
	for (my($bin)=$first_bad_bin; $bin<=$LADCP_lastBin-1; $bin++) {
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   264
		next unless defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   265
		undef($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
5
509cc9966b68 ======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 4
diff changeset
   266
		$nrm++;
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   267
	}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   268
	return $nrm;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   269
}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   270
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 0
diff changeset
   271
#======================================================================
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   272
# ($nvrm,$nerm) = editSideLobes($fromEns,$toEns,$water_depth)
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   273
#
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   274
# NOTES:
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   275
#	1) When this code is executed the sound speed is known. No attempt is made to correct for
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   276
#	   along-beam soundspeed variation, but the soundspeed at the transducer is accounted for.
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   277
#	2) for surface sidelobes, water_depth == undef; surface sidelobes include the
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   278
#	   vessel draft
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   279
#	- all velocities are counted, even those outside valid bin range,
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   280
#	  because the %age is not reported
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   281
#======================================================================
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   282
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   283
sub editSideLobes($$$)
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   284
{
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   285
	my($fe,$te,$wd) = @_;	# first & last ens to process, water depth for sidelobes near seabed
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   286
	my($nvrm) = 0;			# of velocities removed
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   287
	my($nerm) = 0;			# of ensembles affected
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   288
	for (my($e)=$fe; $e<=$te; $e++) {
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   289
		next unless numberp($LADCP{ENSEMBLE}[$e]->{CTD_DEPTH});
32
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   290
		my($range) = defined($wd) ? $wd - $LADCP{ENSEMBLE}[$e]->{CTD_DEPTH} 
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   291
								  : $LADCP{ENSEMBLE}[$e]->{CTD_DEPTH} - $vessel_draft;
6041a20feb39 V1.0 release candidate
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 27
diff changeset
   292
		$range = 0 if ($range < 0);								  
45
6d49c7420a6c stable V1.3beta, just before implementing bin interpolation
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 34
diff changeset
   293
		my($sscorr) = $CTD{SVEL}[$LADCP{ENSEMBLE}[$e]->{CTD_SCAN}] / $LADCP{ENSEMBLE}[$e]->{SPEED_OF_SOUND};
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   294
		my($goodBins) =   ($range - $sscorr*$LADCP{DISTANCE_TO_BIN1_CENTER}) * cos(rad($LADCP{BEAM_ANGLE}))
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   295
						/ ($sscorr*$LADCP{BIN_LENGTH})
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   296
						- 1.5;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   297
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   298
		my($dirty) = 0;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   299
		for (my($bin)=int($goodBins); $bin<$LADCP{N_BINS}; $bin++) { 	# NB: 2 good bins implies that bin 2 is bad
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   300
			next unless ($bin>=0 && defined($LADCP{ENSEMBLE}[$e]->{W}[$bin]));
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   301
			$dirty = 1;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   302
			$nvrm++;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   303
			undef($LADCP{ENSEMBLE}[$e]->{W}[$bin]);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   304
		}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   305
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   306
		$nerm += $dirty;
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   307
	}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   308
	return ($nvrm,$nerm);
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   309
}
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   310
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   311
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   312
#======================================================================
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   313
# ($nvrm,$nerm) = editPPI($fromEns,$toEns,$water_depth)
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   314
#
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   315
# NOTES:
55
2d8e1139acd5 adapted to Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 49
diff changeset
   316
#	- only velocities in valid-bin-range are edited (and counted)
2d8e1139acd5 adapted to Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 49
diff changeset
   317
#	- 3rd argument (water_depth) determines whether surface or 
2d8e1139acd5 adapted to Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 49
diff changeset
   318
#	  seabed PPI editing is required
2d8e1139acd5 adapted to Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 49
diff changeset
   319
#	- when this code is executed a suitable depth-average-soundspeed
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   320
#	  profile (@DASSprof at 1m resolution) is available
55
2d8e1139acd5 adapted to Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 49
diff changeset
   321
#		- water_depth defined: DASSprof average is to seabed
2d8e1139acd5 adapted to Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 49
diff changeset
   322
#		- water_depth not defined: DASSprof average is to sea surface
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   323
#	- PPI layer is defined by the shortest and longest acoustic paths
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   324
#	  between transducer and seabed that contribute significantly to the
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   325
#	  backscatter
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   326
#		- shortest path (shallow limit):
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   327
#			- distance to seabed => sidelobe
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   328
#			- min_lim = water_depth - DASSprof[CTD_depth]*DeltaT/2
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   329
#		- longest path (deep limit):
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   330
#			- outer edge of main lobe of one of the beams (depending on 
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   331
#			  instrument tilt)
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   332
#			- nominal half-beam apertures at half peak signal strength
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   333
#			  (-3dB), RDI BB Primer, pp. 35f (2ND COLUMN)
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   334
#				WH1200	1.4		2.4
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   335
#				WH600	1.5		2.5
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   336
#				WH300	2.2		3.7
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   337
#				WH150	4.0		6.7
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   338
#				WH75	5.0	    8.4
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   339
#			- for WH150, Fig. 23 indicates that half-beam-width 
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   340
#			  at -5dB (<1% peak signal strength) is about 5/3 of same
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   341
#			  at -3dB => PPI limit choice (3rd column above)
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   342
#		- [Plots/2014_P16_043.eps]:
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   343
#			- mean tilt of 2 degrees included in effects
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   344
#			- finite pulse length means that there actually
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   345
#			  is less elapsed time between the end of the sending
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   346
#			  and the beginning of the reception than the ping
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   347
#			  interval suggests; without it, the PPI peak depth
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   348
#			  does not agree with the prediction
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   349
#			- note that there is no PPI effect possible above
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   350
#			  the dark blue line --- this is a hard limit
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   351
#			  (I checked ping interval to within 0.001,
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   352
#			  water depth is known better than 2m, sound
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   353
#			  speed is accurately accounted for (as indicated
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   354
#			  by the cyan line), so the variability above
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   355
#			  is due to background variability, which is
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   356
#			  consistent with the shape of the curve outside
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   357
#			  the PPI layer
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   358
#		  	=> PPI peak can be tightly bracketed but care has to
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   359
#			   be taken to account for finite beam width & 
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   360
#			   instrument beam_tilt = max(|pitch|,|roll|)
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   361
#	- while the upper limit of the PPI layer is unambiguous, this
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   362
#	  is only true if the recorded ping intervals are accurate
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   363
#		- 2014 CLIVAR P16 #47 shows a slight discontinuity in dc_w near
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   364
#		  the middle of the upper PPI layer (4000m)
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   365
#		- the discontinuity is slightly more pronounced with PPI editing
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   366
#	      enabled
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   367
#		- setting $PPI_extend_upper_limit = 1.03 (or 1.04, 1.05, 1.1)
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   368
#		  reduces the discontinuity to the level without PPI filtering, but
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   369
#		  not any better
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   370
#		- overall I am not convinced that the discontinuity is related
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   371
#		  to PPI; therefore, $PPI_extend_upper_limit is not set by default
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   372
#======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   373
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   374
{ my($bha);					# beam half aperture (static scope)
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   375
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   376
sub editPPI($$$)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   377
{
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   378
	my($fe,$te,$wd) = @_;	# first & last ens to process, water depth for downlooker
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   379
	my($nvrm) = 0;			# of velocities removed
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   380
	my($nerm) = 0;			# of ensembles affected
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   381
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   382
	unless (defined($bha)) {
49
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   383
		if    (abs($LADCP{BEAM_FREQUENCY}-1200)/1200 <= 0.1) { $bha = 2.4; }
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   384
		elsif (abs($LADCP{BEAM_FREQUENCY}-600) / 600 <= 0.1) { $bha = 2.5; }
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   385
		elsif (abs($LADCP{BEAM_FREQUENCY}-300) / 300 <= 0.1) { $bha = 3.7; }
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   386
		elsif (abs($LADCP{BEAM_FREQUENCY}-150) / 150 <= 0.1) { $bha = 6.7; }
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   387
		elsif (abs($LADCP{BEAM_FREQUENCY}-75)  /  75 <= 0.1) { $bha = 8.4; }
27
2053d8de8d6b updated plots & seabed code; GoM data process correctly
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 16
diff changeset
   388
		else { error("$0: unexpected transducer frequency $LADCP{BEAM_FREQUENCY}\n"); }
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   389
	}
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   390
	
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   391
	for (my($e)=$fe; $e<=$te; $e++) {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   392
		next unless numberp($LADCP{ENSEMBLE}[$e]->{CTD_DEPTH});
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   393
		next unless ($e > 0);
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   394
		
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   395
		my($delta_t)   = $LADCP{ENSEMBLE}[$e]->{UNIX_TIME} - $LADCP{ENSEMBLE}[$e-1]->{UNIX_TIME};
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   396
		my($dz_max)    = $DASSprof[int($LADCP{ENSEMBLE}[$e]->{CTD_DEPTH})]*$delta_t / 2;
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   397
		my($beam_tilt) = max(abs($LADCP{ENSEMBLE}[$e]->{GIMBAL_PITCH}),
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   398
							 abs($LADCP{ENSEMBLE}[$e]->{ROLL}));
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   399
		my($dz_min)    = $dz_max * cos(rad($LADCP{BEAM_ANGLE} + $beam_tilt + $bha));
46
cc6c4309828a V1.3beta1
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 45
diff changeset
   400
		my(@bd) = binDepths($e);
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   401
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   402
		$dz_max *= $PPI_extend_upper_limit
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   403
			if numberp($PPI_extend_upper_limit);
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   404
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   405
		my($dirty) = 0;
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   406
		for (my($bin)=$LADCP_firstBin-1; $bin<$LADCP_lastBin; $bin++) {
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   407
			next unless (defined($LADCP{ENSEMBLE}[$e]->{W}[$bin]));
55
2d8e1139acd5 adapted to Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 49
diff changeset
   408
			if (defined($wd)) {															# surface PPI
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   409
				next unless ($bd[$bin] >= $wd-$dz_max && $bd[$bin] <= $wd-$dz_min);
55
2d8e1139acd5 adapted to Nortek files
Andreas Thurnherr <ant@ldeo.columbia.edu>
parents: 49
diff changeset
   410
			} else {																	# seabed PPI
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   411
				next unless ($bd[$bin] <= $dz_max && $bd[$bin] >= $dz_min);
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   412
			}
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   413
			$dirty = 1;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   414
			$nvrm++;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   415
			undef($LADCP{ENSEMBLE}[$e]->{W}[$bin]);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   416
		}
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   417
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   418
		$nerm += $dirty;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   419
	}
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   420
	return ($nvrm,$nerm);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   421
}
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   422
16
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   423
} # static scope for $bha
29e867b3e070 whoosher version at beginning of FZ1
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents: 15
diff changeset
   424
15
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   425
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 13
diff changeset
   426
#======================================================================
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   427
# $nerm = editSurfLayer($fromEns,$toEns,$surface_layer_depth)
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   428
#
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   429
# NOTES:
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   430
#	1) When this code is executed the fully corrected instrument and
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   431
#	   bin depths are known
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   432
#	2) This code was inspired by 2011_IWISE station 8
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   433
#	3) No point in counting the deleted velocities
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   434
#======================================================================
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   435
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   436
sub editSurfLayer($$$)
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   437
{
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   438
	my($fe,$te,$sld) = @_;		# first & last ens to process
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   439
	my($nerm) = 0;				# of ensembles affected
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   440
	for (my($e)=$fe; $e<=$te; $e++) {
10
7e76fdef8953 version prior to carrying out separate dc-/uc- time lagging
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 6
diff changeset
   441
		next unless numberp($LADCP{ENSEMBLE}[$e]->{CTD_DEPTH});
4
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   442
		undef($LADCP{ENSEMBLE}[$e]->{CTD_DEPTH}),$nerm++
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   443
			if ($LADCP{ENSEMBLE}[$e]->{CTD_DEPTH} <= $sld);
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   444
	}
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   445
	return $nerm;
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   446
}
e681262d0fd7 yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 3
diff changeset
   447
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   448
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   449
#===============================================================================
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   450
# $nerm = editBadTimeLagging($fromEns,$toEns,$good_from_elapsed1,$good_to_elapsed1,...)
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   451
#
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   452
# NOTES:
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   453
#	- deleted velocities are not counted
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   454
#===============================================================================
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   455
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   456
sub editBadTimeLagging($$@)
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   457
{
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   458
	my($fe,$te,@elim) = @_;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   459
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   460
	my($nerm) = 0;													# of ensembles removed
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   461
	my($i) = 0;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   462
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   463
	if ($elim[0] < 0) {												# entire piece is bad
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   464
		for (my($e)=$fe; $e<=$te; $e++) {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   465
			undef($LADCP{ENSEMBLE}[$e]->{REFLR_W});
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   466
			$nerm++;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   467
		}
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   468
	} elsif (defined($elim[1])) {									# limits in elim
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   469
		my($e);
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   470
		for ($e=$fe; @elim; shift(@elim),shift(@elim)) {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   471
#			print(STDERR "deleting to $elim[0]\n");
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   472
			while ($LADCP{ENSEMBLE}[$e]->{ELAPSED} < $elim[0]) {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   473
				undef($LADCP{ENSEMBLE}[$e]->{REFLR_W});
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   474
				$nerm++;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   475
				$e++;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   476
			}
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   477
#			print(STDERR "keeping to $elim[1]\n");
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   478
			while ($LADCP{ENSEMBLE}[$e]->{ELAPSED} < $elim[1]) { $e++; }
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   479
	    }
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   480
#		print(STDERR "deleting to $LADCP{ENSEMBLE}[$te]->{ELAPSED}\n");
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   481
		while ($e <= $te) {
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   482
			undef($LADCP{ENSEMBLE}[$e]->{REFLR_W});
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   483
			$nerm++;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   484
			$e++;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   485
		}
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   486
	}
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   487
	return $nerm;
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   488
}
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   489
47
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   490
#======================================================================
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   491
# $nerm = editResiduals_rmsMax($fe,$te,$max_val)
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   492
#
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   493
# NOTES:
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   494
#	- removed velocities are not counted
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   495
#======================================================================
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   496
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   497
sub editResiduals_rmsMax($$$)
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   498
{
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   499
	my($fe,$te,$limit) = @_;
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   500
	my($nerm) = 0;
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   501
	for (my($ens)=$fe; $ens<=$te; $ens++) {
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   502
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   503
		my($sum) = my($n) = 0;														# calculate rms residual
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   504
		my(@bindepth) = binDepths($ens);
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   505
		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   506
			next unless ($bin+1>=$outGrid_firstBin && $bin+1<=$outGrid_lastBin);
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   507
		  	next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   508
		  	my($bi) = $bindepth[$bin]/$opt_o;
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   509
			my($res) = ($ens < $LADCP_atbottom) ? 
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   510
						$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] - $DNCAST{MEDIAN_W}[$bi] :
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   511
						$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] - $UPCAST{MEDIAN_W}[$bi];
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   512
			$sum += &SQR($res); $n++;						
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   513
		}
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   514
		if ($n == 0 || sqrt($sum/$n) > $limit) {									# ensemble is bad
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   515
			undef($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   516
			$nerm++;
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   517
		}
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   518
	}
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   519
	return $nerm;
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   520
}
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   521
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   522
#======================================================================
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   523
# $nerm = editResiduals_deltaMax($fe,$te,$max_val)
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   524
#	- delta residual = delta beampair w => equal to scaled error velocity?
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   525
#	- sharp cutoff near 5cm/s for std parameters (0.1 m/s error velocity
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   526
#	  filter) in several data sets
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   527
#	- samples with large residuals differences are clear outliers in
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   528
# 	  the residuals vs tilt plots => obvious to remove
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   529
#	- how are large delta res possible given the errvel limit???
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   530
#	- only valid bin range is edited/counted
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   531
#======================================================================
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   532
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   533
sub editResiduals_deltaMax($$$)
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   534
{
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   535
	my($fe,$te,$limit) = @_;
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   536
	my($nvrm) = 0;
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   537
	for (my($ens)=$fe; $ens<=$te; $ens++) {
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   538
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   539
		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   540
			next unless ($bin+1>=$outGrid_firstBin && $bin+1<=$outGrid_lastBin);
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   541
			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   542
			my($Dr) = abs($LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin] -
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   543
						  $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin]);
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   544
			if ($Dr > $limit) {
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   545
				undef($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   546
				$nvrm++;
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   547
			}
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   548
		}
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   549
    }
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   550
    return $nvrm;
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   551
}
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   552
2ccb81b7cea5 version found on whoosher after repair
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 46
diff changeset
   553
#======================================================================
49
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   554
# $nerm = editLargeHSpeeds($fe,$te,$max_hspeed)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   555
#	- filter based on 2018 GO-SHIP LADCP profile #106, where UL 
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   556
#	  velocities become bad when ship starts dragging rosette
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   557
#	- only valid bin range is edited/counted
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   558
#======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   559
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   560
sub editLargeHSpeeds($$$)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   561
{
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   562
	my($fe,$te,$limit) = @_;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   563
	my($nerm) = 0;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   564
	for (my($ens)=$fe; $ens<=$te; $ens++) {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   565
		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   566
		next unless (vel_speed($LADCP{ENSEMBLE}[$ens]->{REFLR_U},
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   567
							   $LADCP{ENSEMBLE}[$ens]->{REFLR_U}) > $limit);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   568
		undef($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   569
		$nerm++;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   570
	}
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   571
    return $nerm;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   572
}
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   573
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 47
diff changeset
   574
#======================================================================
56
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   575
# $nbrm = editHighResidualLayers($max_lr_res)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   576
#	- filter applied after gridding
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   577
#	- filter based on observation that profiles of beam-pair residuals
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   578
#	  are good indicators of bad data, but very noisy
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   579
#	- current version uses estimates in 5-bin-thick layers (200m by
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   580
#	  default) 
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   581
#	- filter cutoff based on 2021 A20 cruise which crossed region with
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   582
#	  very weak backscatter
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   583
#======================================================================
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   584
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   585
sub editHighResidualLayers($)
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   586
{
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   587
	my($limit) = @_;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   588
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   589
	my($nbrm) = 0;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   590
	for (my($bi)=0; $bi<=$#{$DNCAST{LR_RMS_BP_RESIDUAL}}; $bi++) {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   591
		next unless ($DNCAST{LR_RMS_BP_RESIDUAL}[$bi] > $limit);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   592
		$DNCAST{MEDIAN_W}[$bi] = $DNCAST{MEDIAN_W12}[$bi] = $DNCAST{MEDIAN_W34}[$bi] = nan;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   593
		$nbrm++;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   594
	}
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   595
	for (my($bi)=0; $bi<=$#{$UPCAST{LR_RMS_BP_RESIDUAL}}; $bi++) {
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   596
		next unless ($UPCAST{LR_RMS_BP_RESIDUAL}[$bi] > $limit);
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   597
		$UPCAST{MEDIAN_W}[$bi] = $UPCAST{MEDIAN_W12}[$bi] = $UPCAST{MEDIAN_W34}[$bi] = nan;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   598
		$nbrm++;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   599
	}
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   600
    return $nbrm;
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   601
}
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   602
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 55
diff changeset
   603
#======================================================================
34
e550db661c17 pre-Tampa
A.M. Thurnherr <athurnherr@yahoo.com>
parents: 32
diff changeset
   604
0
3365828b1004 after DIMES UK2
A.M. Thurnherr <ant@ldeo.columbia.edu>
parents:
diff changeset
   605
1;