adapted to Nortek files
authorAndreas Thurnherr <ant@ldeo.columbia.edu>
Sat, 10 Apr 2021 06:00:45 -0400
changeset 55 2d8e1139acd5
parent 54 828e5466391b
child 56 8f120b9f795a
child 58 7688bec6fe87
adapted to Nortek files
LADCP_w_ocean
edit_data.pl
plot_wprof.pl
version.pl
--- a/LADCP_w_ocean	Mon Mar 08 12:07:26 2021 -0500
+++ b/LADCP_w_ocean	Sat Apr 10 06:00:45 2021 -0400
@@ -2,9 +2,9 @@
 #======================================================================
 #                    L A D C P _ W _ O C E A N 
 #                    doc: Fri Dec 17 18:11:13 2010
-#                    dlm: Mon Jun 29 11:03:22 2020
+#                    dlm: Tue Mar 23 09:16:10 2021
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 306 76 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 308 65 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # TODO:
@@ -304,6 +304,8 @@
 #				  - made bin residuals per beam pair
 #	May 16, 2020: - BUG: write_residual_profs() clobbered layout
 #	Jun 22, 2020: - sscorr_w renamed to remove conflict with [RDI_Coords.pl]
+#	Mar 17, 2021: - turned multi-ping error into warning (for Nortek files)
+#	Mar 23, 3021: - adapted to ADCP_tools V2.4 (Nortek PD0 files)
 # HISTORY END
 
 # CTD REQUIREMENTS
@@ -609,12 +611,12 @@
 	progress("\t%d invalid trailing ensembles removed\n",@{$LADCP{ENSEMBLE}}-$ens)
 }
 			   
-error("$LADCP_file: cannot process multi-ping ensembles\n")
+warning(2,"$LADCP_file: multi-ping ensembles\n")
 	unless ($LADCP{PINGS_PER_ENSEMBLE} == 1);
 warning(2,"$LADCP_file: wide-bandwidth setting\n")
 	if ($LADCP{WIDE_BANDWIDTH});
 warning(2,"$LADCP_file: low transmit-power setting\n")
-	unless ($LADCP{TRANSMIT_POWER_HIGH});
+	unless ($LADCP{TRANSMIT_POWER_MAX});
 
 error("$LADCP_file: not enough LADCP bins ($LADCP{N_BINS}) for choice of -r\n")
 	unless ($LADCP{N_BINS} >= $refLr_lastBin);
@@ -1339,30 +1341,49 @@
 	        &antsAddParams('sidelobe_editing','seabed');
 	    }
 
-		if (&PPI_seabed_editing_required()) {
-			&antsAddParams('PPI_editing','seabed');
+		# Setting $DEBUG_DL_SURFACE_PPI_EDITING to 1 enables sea-surface PPI editing for
+		# downlookers (but disabled seabed editing). This was used on 2021 A20 for testing.
+		
+		if ($DEBUG_DL_SURFACE_PPI_EDITING) {
+			&antsAddParams('PPI_editing','surface');
 			&antsAddParams('PPI_extend_upper_limit',$PPI_extend_upper_limit)
 				if numberp($PPI_extend_upper_limit);
-			progress("Editing data to remove PPI from seabed...\n");
-			progress("\tConstructing depth-average soundspeed profile...\n");
-			die("assertion failed") unless defined($water_depth);
-			my($dz) = $water_depth - $#sVelProf;							# $#sVelProf = max_depth(profile) in meters
-			my($sum) = $dz * $sVelProf[$#sVelProf];
-			if ($dz == 0) {													# water-depth <= max CTD depth
-				warning(1,"inferred water depth very close to max(CTD depth)\n");
-				$DASSprof[$#sVelProf] = $sVelProf[$#sVelProf];
-            } else {
-				die("assertion failed") unless defined($dz > 0);
-				$DASSprof[$#sVelProf] = $sum/$dz;
-            }
-			for (my($d)=$#sVelProf-1; $d>=0; $d--) {
-				die("assertion failed (d=$d, #sVelProf=$#sVelProf)") unless numberp($sVelProf[$d]);
+			progress("Editing data to remove PPI from sea surface...\n");
+			  progress("\tConstructing depth-average soundspeed profile...\n");
+			  $DASSprof[0] = my($sum) = 0;
+			  for (my($d)=1; $d<=$#sVelProf; $d++) {
+				die("assertion failed") unless numberp($sVelProf[$d]);
 				$sum += $sVelProf[$d];
-			  	$dz++;
-				$DASSprof[$d] = $sum/$dz;
-			}
-			($nvrm,$nerm) = editPPI($firstGoodEns,$lastGoodEns,$water_depth);
+				$DASSprof[$d] = $sum/$d;
+			  }
+			($nvrm,$nerm) = editPPI($firstGoodEns,$lastGoodEns,undef);
 	        progress("\t$nvrm velocities from $nerm ensembles removed\n");
+	    } else {
+			if (&PPI_seabed_editing_required()) {
+				&antsAddParams('PPI_editing','seabed');
+				&antsAddParams('PPI_extend_upper_limit',$PPI_extend_upper_limit)
+					if numberp($PPI_extend_upper_limit);
+				progress("Editing data to remove PPI from seabed...\n");
+				progress("\tConstructing depth-average soundspeed profile...\n");
+				die("assertion failed") unless defined($water_depth);
+				my($dz) = $water_depth - $#sVelProf;							# $#sVelProf = max_depth(profile) in meters
+				my($sum) = $dz * $sVelProf[$#sVelProf];
+				if ($dz == 0) { 												# water-depth <= max CTD depth
+					warning(1,"inferred water depth very close to max(CTD depth)\n");
+					$DASSprof[$#sVelProf] = $sVelProf[$#sVelProf];
+				} else {
+					die("assertion failed") unless defined($dz > 0);
+					$DASSprof[$#sVelProf] = $sum/$dz;
+				}
+				for (my($d)=$#sVelProf-1; $d>=0; $d--) {
+					die("assertion failed (d=$d, #sVelProf=$#sVelProf)") unless numberp($sVelProf[$d]);
+					$sum += $sVelProf[$d];
+					$dz++;
+					$DASSprof[$d] = $sum/$dz;
+				}
+				($nvrm,$nerm) = editPPI($firstGoodEns,$lastGoodEns,$water_depth);
+				progress("\t$nvrm velocities from $nerm ensembles removed\n");
+	        }
 	    }
 	}
 	
--- a/edit_data.pl	Mon Mar 08 12:07:26 2021 -0500
+++ b/edit_data.pl	Sat Apr 10 06:00:45 2021 -0400
@@ -1,9 +1,9 @@
 #======================================================================
-#                    / D A T A / S R C / O C E A N O G R A P H Y / L A D C P _ V E R T I C A L _ V E L O C I T Y / E D I T _ D A T A . P L 
+#                    E D I T _ D A T A . P L 
 #                    doc: Sat May 22 21:35:55 2010
-#                    dlm: Tue Nov 27 11:07:33 2018
+#                    dlm: Tue Mar 23 05:29:53 2021
 #                    (c) 2010 A.M. Thurnherr
-#                    uE-Info: 46 71 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 409 100 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -44,6 +44,8 @@
 #	Oct 13, 2017: - BUG: editPPI() only allowed for nominal transducer frequencies
 #	May  1, 2018: - added editLargeHSpeeds()
 #	Nov 17, 2018: - BUG: spurious letter "z" had crept in at some stage
+#	Mar 23, 2021: - updated PPI doc
+# END OF HISTORY
 
 # NOTES:
 #	- all bins must be edited (not just the ones between $LADCP_firstBin
@@ -310,11 +312,13 @@
 # ($nvrm,$nerm) = editPPI($fromEns,$toEns,$water_depth)
 #
 # NOTES:
-#	- only velocities in good bin range are removed/counted
-#	- for UL, water_depth == undef; for DL water_depth is always defined,
-#	  or else editPPI is not called
-#	- when this code is executed a suitable UL or DL depth-average-soundspeed
+#	- only velocities in valid-bin-range are edited (and counted)
+#	- 3rd argument (water_depth) determines whether surface or 
+#	  seabed PPI editing is required
+#	- when this code is executed a suitable depth-average-soundspeed
 #	  profile (@DASSprof at 1m resolution) is available
+#		- water_depth defined: DASSprof average is to seabed
+#		- water_depth not defined: DASSprof average is to sea surface
 #	- PPI layer is defined by the shortest and longest acoustic paths
 #	  between transducer and seabed that contribute significantly to the
 #	  backscatter
@@ -400,9 +404,9 @@
 		my($dirty) = 0;
 		for (my($bin)=$LADCP_firstBin-1; $bin<$LADCP_lastBin; $bin++) {
 			next unless (defined($LADCP{ENSEMBLE}[$e]->{W}[$bin]));
-			if (defined($wd)) {															# DL
+			if (defined($wd)) {															# surface PPI
 				next unless ($bd[$bin] >= $wd-$dz_max && $bd[$bin] <= $wd-$dz_min);
-			} else {																	# UL
+			} else {																	# seabed PPI
 				next unless ($bd[$bin] <= $dz_max && $bd[$bin] >= $dz_min);
 			}
 			$dirty = 1;
--- a/plot_wprof.pl	Mon Mar 08 12:07:26 2021 -0500
+++ b/plot_wprof.pl	Sat Apr 10 06:00:45 2021 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    P L O T _ W P R O F . P L 
 #                    doc: Sun Jul 26 11:08:50 2015
-#                    dlm: Sat May 23 11:11:42 2020
+#                    dlm: Tue Mar 23 08:28:12 2021
 #                    (c) 2015 A.M. Thurnherr
-#                    uE-Info: 89 108 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 25 39 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -22,6 +22,7 @@
 #				  - added blue background for likely in-ice package accelerations
 #	May 16, 2020: - added residual profile data to background
 #	May 23, 2020: - BUG: windows without samples made program bomb
+#	Mar 23, 2021: - BUG: instrument frequency was rounded to 100kHz
 
 # Tweakables:
 #
@@ -231,7 +232,7 @@
 
 	GMT_pstext('-F+f9,Helvetica,CornFlowerBlue+jTL -N');
 		printf(GMT "0.64 1.020 %d kHz $LADCP{INSTRUMENT_TYPE} $P{ADCP_orientation}\n",
-				round($LADCP{BEAM_FREQUENCY},100));
+				round($LADCP{BEAM_FREQUENCY},50));
 		printf(GMT "0.64 1.055 %s [%.1fm/%1.fm/%1.fm]\n",
 			$LADCP{BEAM_COORDINATES} ? 'beam vels' : 'Earth vels',
 			$LADCP{BLANKING_DISTANCE},$LADCP{TRANSMITTED_PULSE_LENGTH},$LADCP{BIN_LENGTH});
--- a/version.pl	Mon Mar 08 12:07:26 2021 -0500
+++ b/version.pl	Sat Apr 10 06:00:45 2021 -0400
@@ -1,9 +1,9 @@
 #======================================================================
 #                    V E R S I O N . P L 
 #                    doc: Tue Oct 13 10:40:57 2015
-#                    dlm: Thu Sep 12 12:27:38 2019
+#                    dlm: Tue Mar 23 09:15:39 2021
 #                    (c) 2015 A.M. Thurnherr
-#                    uE-Info: 36 29 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 29 46 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -26,6 +26,7 @@
 #	Nov 27, 2018: - updated ANTS lib to V7.1
 #			      - updated ADCP tools to V2.2
 #	Sep 12, 2019: - updated to V1.5 because of CTD gap correction
+#	Mar 23, 2021: - updated ADCP_tools to V2.4
 
 #$VERSION = '1.1';				# Jan  4, 2016
 #$VERSION = '1.2';				# May 12, 2016
@@ -34,7 +35,7 @@
 $VERSION = '1.5';				# Sep 12, 2018
 
 $antsMinLibVersion 		= 7.1;
-$ADCP_tools_minVersion 	= 2.2;
+$ADCP_tools_minVersion 	= 2.4;
 
 use lib '.';