edit_data.pl
changeset 47 2ccb81b7cea5
parent 46 cc6c4309828a
child 49 5006e9158207
equal deleted inserted replaced
46:cc6c4309828a 47:2ccb81b7cea5
     1 #======================================================================
     1 #======================================================================
     2 #                    E D I T _ D A T A . P L 
     2 #                    E D I T _ D A T A . P L 
     3 #                    doc: Sat May 22 21:35:55 2010
     3 #                    doc: Sat May 22 21:35:55 2010
     4 #                    dlm: Tue May 24 16:36:37 2016
     4 #                    dlm: Mon Jun  6 21:13:28 2016
     5 #                    (c) 2010 A.M. Thurnherr
     5 #                    (c) 2010 A.M. Thurnherr
     6 #                    uE-Info: 374 18 NIL 0 0 72 2 2 4 NIL ofnI
     6 #                    uE-Info: 543 0 NIL 0 0 72 2 2 4 NIL ofnI
     7 #======================================================================
     7 #======================================================================
     8 
     8 
     9 # HISTORY:
     9 # HISTORY:
    10 #	May 22, 2010: - created
    10 #	May 22, 2010: - created
    11 #	May 24, 2010: - added editSideLobesFromSeabed()
    11 #	May 24, 2010: - added editSideLobesFromSeabed()
    33 #				  - croak -> error
    33 #				  - croak -> error
    34 #	Sep 26, 2015: - added $vessel_draft to editSideLobes
    34 #	Sep 26, 2015: - added $vessel_draft to editSideLobes
    35 #	Jan 23, 2016: - added &editBadTimeLagging()
    35 #	Jan 23, 2016: - added &editBadTimeLagging()
    36 #	May 18, 2016: - removed assumption of 1500m/s soundspeed setting
    36 #	May 18, 2016: - removed assumption of 1500m/s soundspeed setting
    37 #   May 24, 2016: - calc_binDepths() -> binDepths()
    37 #   May 24, 2016: - calc_binDepths() -> binDepths()
    38 
    38 #	May 28, 2016: - added editResiduals_rmsMax, editResiduals_deltaMax
    39 # NOTES:
    39 #	Jun  2, 2016: - added applyTiltCorrection()
    40 #	- editCorr_Earthcoords() is overly conservative and removed most
    40 #				  - maded editCorr_Earthcoords() less conservative
    41 #	  or all 3-beam solutions
    41 #				  - verified that removed velocities are counted correctly
       
    42 #	Jun  3, 2016: - BUG: applyTiltCorrection() did not use gimbal_pitch
       
    43 #	Jun  6, 2016: - removed applyTiltCorrection()
       
    44 
       
    45 # NOTES:
    42 #	- all bins must be edited (not just the ones between $LADCP_firstBin
    46 #	- all bins must be edited (not just the ones between $LADCP_firstBin
    43 #	  and $LADCP_lastBin to allow reflr calculations to use bins outside
    47 #	  and $LADCP_lastBin to allow reflr calculations to use bins outside
    44 #	  this range (ONLY FOR BEAM-COORD EDITS)
    48 #	  this range (ONLY FOR BEAM-COORD EDITS)
    45 #	- however, to make the stats work, only the edited velocities
    49 #	- however, to make the stats work, only the edited velocities
    46 #	  inside the bin range are counted
    50 #	  inside the bin range are counted for those edit functions that
       
    51 #	  report their stats wrt $nvw (for those which use $nvv,
       
    52 #	  all velocities must be counted)
    47 
    53 
    48 #======================================================================
    54 #======================================================================
    49 # correctAttitude($ens,$pitch_bias,$roll_bias,$heading_bias)
    55 # correctAttitude($ens,$pitch_bias,$roll_bias,$heading_bias)
       
    56 #	- this is called before gimbal_pitch is calculated
    50 #======================================================================
    57 #======================================================================
    51 
    58 
    52 sub correctAttitude($$$$)
    59 sub correctAttitude($$$$)
    53 {
    60 {
    54 	my($ens,$pitch_bias,$roll_bias,$heading_bias) = @_;
    61 	my($ens,$pitch_bias,$roll_bias,$heading_bias) = @_;
    57 	$LADCP{ENSEMBLE}[$ens]->{HEADING} -= $heading_bias	if defined($LADCP{ENSEMBLE}[$ens]->{HEADING});
    64 	$LADCP{ENSEMBLE}[$ens]->{HEADING} -= $heading_bias	if defined($LADCP{ENSEMBLE}[$ens]->{HEADING});
    58 }
    65 }
    59 
    66 
    60 #======================================================================
    67 #======================================================================
    61 # $vv = countValidVels($ens)
    68 # $vv = countValidVels($ens)
       
    69 #
       
    70 # NOTES:
       
    71 #	- in case of Earth coords, this counts the velocity components
       
    72 #	  (including errvel)
    62 #======================================================================
    73 #======================================================================
    63 
    74 
    64 sub countValidBeamVels($)
    75 sub countValidBeamVels($)
    65 {
    76 {
    66 	my($ens) = @_;
    77 	my($ens) = @_;
    77 
    88 
    78 #======================================================================
    89 #======================================================================
    79 # $removed = editCorr($ens,$threshold)
    90 # $removed = editCorr($ens,$threshold)
    80 #
    91 #
    81 # NOTES:
    92 # NOTES:
    82 #	- called before Earth vels have been calculated
    93 #	- called before Earth vels are calculated
       
    94 #	- count removed velocities in all bins
    83 #======================================================================
    95 #======================================================================
    84 
    96 
    85 sub editCorr($$)
    97 sub editCorr($$)
    86 {
    98 {
    87 	my($ens,$lim) = @_;
    99 	my($ens,$lim) = @_;
   100 
   112 
   101 #======================================================================
   113 #======================================================================
   102 # $removed = editCorr_Earthcoords($ens,$threshold)
   114 # $removed = editCorr_Earthcoords($ens,$threshold)
   103 #
   115 #
   104 # NOTES:
   116 # NOTES:
   105 #	- if any of the 4 beam correlations is below the threshold,
   117 #	- if any of the used correlations is below the threshold,
   106 #	  the entire velocity is removed
   118 #	  the entire velocity is removed
   107 #	- this implies that (most? all?) three-beam solutions will
   119 #	- for three-beam solutions two correlations must fail the
   108 #	  be edited out, which is overly conserative
   120 #	  test
   109 #	- a potentially better algorithm (used in LADCPproc) ignores the
   121 #	- count velocities in all bins
   110 #	  lowest correlation in all 3-beam solutions
       
   111 #======================================================================
   122 #======================================================================
   112 
   123 
   113 sub editCorr_Earthcoords($$)
   124 sub editCorr_Earthcoords($$)
   114 {
   125 {
   115 	my($ens,$lim) = @_;
   126 	my($ens,$lim) = @_;
   116 
   127 
   117 	my($nrm) = 0;
   128 	my($nrm) = 0;
   118 	for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
   129 	for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) {
   119 		my($beam);
   130 		my($nBad) = 0;
   120 		for ($beam=0; $beam<4; $beam++) {
   131 		for (my($beam)=0; $beam<4; $beam++) {
   121 			last unless ($LADCP{ENSEMBLE}[$ens]->{CORRELATION}[$bin][$beam] >= $lim);
   132 			$nBad++ unless ($LADCP{ENSEMBLE}[$ens]->{CORRELATION}[$bin][$beam] > $lim);
   122 		}
   133 		}
   123 		if ($beam < 4) {
   134 		if ($nBad-$LADCP{ENSEMBLE}[$ens]->{THREE_BEAM}[$bin] > 0) {
   124 			for (my($c)=0; $c<4; $c++) {
   135 			for (my($beam)=0; $beam<4; $beam++) {
   125 				next unless defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$c]);
   136 				next unless defined($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$beam]);
   126 				undef($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$c]);
   137 				undef($LADCP{ENSEMBLE}[$ens]->{VELOCITY}[$bin][$beam]);
   127 				$nrm++;
   138 				$nrm++;
   128 			}
   139 			}
   129 		}
   140 		}
   130 	}
   141 	}
   131 	return $nrm;
   142 	return $nrm;
   135 # $removed = editTilt($ens,$threshold)
   146 # $removed = editTilt($ens,$threshold)
   136 #
   147 #
   137 # NOTES:
   148 # NOTES:
   138 #	- called after Earth vels have been calculated
   149 #	- called after Earth vels have been calculated
   139 #	- sets TILT field for each ensemble as a side-effect
   150 #	- sets TILT field for each ensemble as a side-effect
       
   151 #	- count all removed velocities
   140 #======================================================================
   152 #======================================================================
   141 
   153 
   142 sub editTilt($$)
   154 sub editTilt($$)
   143 {
   155 {
   144 	my($ens,$lim) = @_;
   156 	my($ens,$lim) = @_;
   207 #======================================================================
   219 #======================================================================
   208 # $removed = editTruncRange($ens,$nbins)
   220 # $removed = editTruncRange($ens,$nbins)
   209 #
   221 #
   210 # NOTES:
   222 # NOTES:
   211 #	- call after Earth vels have been calculated
   223 #	- call after Earth vels have been calculated
       
   224 #	- count only removed vels in selected bin range
   212 #======================================================================
   225 #======================================================================
   213 
   226 
   214 sub editTruncRange($$)
   227 sub editTruncRange($$)
   215 {
   228 {
   216 	my($ens,$nbins) = @_;
   229 	my($ens,$nbins) = @_;
   230 # NOTES:
   243 # NOTES:
   231 #	- call after Earth vels have been calculated
   244 #	- call after Earth vels have been calculated
   232 #	- remove data from far bins
   245 #	- remove data from far bins
   233 #	- only bins in valid range are considered here, because
   246 #	- only bins in valid range are considered here, because
   234 #	  $per_bin_nsamp is only defined for those
   247 #	  $per_bin_nsamp is only defined for those
       
   248 #	- only velocities from bins in valid range are counted
   235 #======================================================================
   249 #======================================================================
   236 
   250 
   237 sub editFarBins($$)
   251 sub editFarBins($$)
   238 {
   252 {
   239 	my($ens,$first_bad_bin) = @_;
   253 	my($ens,$first_bad_bin) = @_;
   253 # NOTES:
   267 # NOTES:
   254 #	1) When this code is executed the sound speed is known. No attempt is made to correct for
   268 #	1) When this code is executed the sound speed is known. No attempt is made to correct for
   255 #	   along-beam soundspeed variation, but the soundspeed at the transducer is accounted for.
   269 #	   along-beam soundspeed variation, but the soundspeed at the transducer is accounted for.
   256 #	2) for surface sidelobes, water_depth == undef; surface sidelobes include the
   270 #	2) for surface sidelobes, water_depth == undef; surface sidelobes include the
   257 #	   vessel draft
   271 #	   vessel draft
       
   272 #	- all velocities are counted, even those outside valid bin range,
       
   273 #	  because the %age is not reported
   258 #======================================================================
   274 #======================================================================
   259 
   275 
   260 sub editSideLobes($$$)
   276 sub editSideLobes($$$)
   261 {
   277 {
   262 	my($fe,$te,$wd) = @_;	# first & last ens to process, water depth for sidelobes near seabed
   278 	my($fe,$te,$wd) = @_;	# first & last ens to process, water depth for sidelobes near seabed
   288 
   304 
   289 #======================================================================
   305 #======================================================================
   290 # ($nvrm,$nerm) = editPPI($fromEns,$toEns,$water_depth)
   306 # ($nvrm,$nerm) = editPPI($fromEns,$toEns,$water_depth)
   291 #
   307 #
   292 # NOTES:
   308 # NOTES:
       
   309 #	- only velocities in good bin range are removed/counted
   293 #	- for UL, water_depth == undef; for DL water_depth is always defined,
   310 #	- for UL, water_depth == undef; for DL water_depth is always defined,
   294 #	  or else editPPI is not called
   311 #	  or else editPPI is not called
   295 #	- when this code is executed a suitable UL or DL depth-average-soundspeed
   312 #	- when this code is executed a suitable UL or DL depth-average-soundspeed
   296 #	  profile (@DASSprof at 1m resolution) is available
   313 #	  profile (@DASSprof at 1m resolution) is available
   297 #	- PPI layer is defined by the shortest and longest acoustic paths
   314 #	- PPI layer is defined by the shortest and longest acoustic paths
   420 }
   437 }
   421 
   438 
   422 
   439 
   423 #===============================================================================
   440 #===============================================================================
   424 # $nerm = editBadTimeLagging($fromEns,$toEns,$good_from_elapsed1,$good_to_elapsed1,...)
   441 # $nerm = editBadTimeLagging($fromEns,$toEns,$good_from_elapsed1,$good_to_elapsed1,...)
       
   442 #
       
   443 # NOTES:
       
   444 #	- deleted velocities are not counted
   425 #===============================================================================
   445 #===============================================================================
   426 
   446 
   427 sub editBadTimeLagging($$@)
   447 sub editBadTimeLagging($$@)
   428 {
   448 {
   429 	my($fe,$te,@elim) = @_;
   449 	my($fe,$te,@elim) = @_;
   456 		}
   476 		}
   457 	}
   477 	}
   458 	return $nerm;
   478 	return $nerm;
   459 }
   479 }
   460 
   480 
       
   481 #======================================================================
       
   482 # $nerm = editResiduals_rmsMax($fe,$te,$max_val)
       
   483 #
       
   484 # NOTES:
       
   485 #	- removed velocities are not counted
       
   486 #======================================================================
       
   487 
       
   488 sub editResiduals_rmsMax($$$)
       
   489 {
       
   490 	my($fe,$te,$limit) = @_;
       
   491 	my($nerm) = 0;
       
   492 	for (my($ens)=$fe; $ens<=$te; $ens++) {
       
   493 		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
       
   494 		my($sum) = my($n) = 0;														# calculate rms residual
       
   495 		my(@bindepth) = binDepths($ens);
       
   496 		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
       
   497 			next unless ($bin+1>=$outGrid_firstBin && $bin+1<=$outGrid_lastBin);
       
   498 		  	next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
       
   499 		  	my($bi) = $bindepth[$bin]/$opt_o;
       
   500 			my($res) = ($ens < $LADCP_atbottom) ? 
       
   501 						$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] - $DNCAST{MEDIAN_W}[$bi] :
       
   502 						$LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W}[$bin] - $UPCAST{MEDIAN_W}[$bi];
       
   503 			$sum += &SQR($res); $n++;						
       
   504 		}
       
   505 		if ($n == 0 || sqrt($sum/$n) > $limit) {									# ensemble is bad
       
   506 			undef($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
       
   507 			$nerm++;
       
   508 		}
       
   509 	}
       
   510 	return $nerm;
       
   511 }
       
   512 
       
   513 #======================================================================
       
   514 # $nerm = editResiduals_deltaMax($fe,$te,$max_val)
       
   515 #	- delta residual = delta beampair w => equal to scaled error velocity?
       
   516 #	- sharp cutoff near 5cm/s for std parameters (0.1 m/s error velocity
       
   517 #	  filter) in several data sets
       
   518 #	- samples with large residuals differences are clear outliers in
       
   519 # 	  the residuals vs tilt plots => obvious to remove
       
   520 #	- how are large delta res possible given the errvel limit???
       
   521 #	- only valid bin range is edited/counted
       
   522 #======================================================================
       
   523 
       
   524 sub editResiduals_deltaMax($$$)
       
   525 {
       
   526 	my($fe,$te,$limit) = @_;
       
   527 	my($nvrm) = 0;
       
   528 	for (my($ens)=$fe; $ens<=$te; $ens++) {
       
   529 		next unless numberp($LADCP{ENSEMBLE}[$ens]->{CTD_DEPTH});
       
   530 		for ($bin=$LADCP_firstBin-1; $bin<=$LADCP_lastBin-1; $bin++) {
       
   531 			next unless ($bin+1>=$outGrid_firstBin && $bin+1<=$outGrid_lastBin);
       
   532 			next unless numberp($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
       
   533 			my($Dr) = abs($LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W12}[$bin] -
       
   534 						  $LADCP{ENSEMBLE}[$ens]->{SSCORRECTED_OCEAN_W34}[$bin]);
       
   535 			if ($Dr > $limit) {
       
   536 				undef($LADCP{ENSEMBLE}[$ens]->{W}[$bin]);
       
   537 				$nvrm++;
       
   538 			}
       
   539 		}
       
   540     }
       
   541     return $nvrm;
       
   542 }
       
   543 
       
   544 #======================================================================
   461 
   545 
   462 1;
   546 1;