adapted to SBE files with badly formatted records
authorAndreas Thurnherr <ant@ldeo.columbia.edu>
Mon, 27 Jun 2022 19:06:50 -1000
changeset 58 7688bec6fe87
parent 55 2d8e1139acd5
child 59 4118a8e880de
adapted to SBE files with badly formatted records
LADCP_w_CTD
plot_residual_profs.pl
plot_wprof.pl
--- a/LADCP_w_CTD	Sat Apr 10 06:00:45 2021 -0400
+++ b/LADCP_w_CTD	Mon Jun 27 19:06:50 2022 -1000
@@ -2,9 +2,9 @@
 #======================================================================
 #                    L A D C P _ W _ C T D 
 #                    doc: Mon Nov  3 17:34:19 2014
-#                    dlm: Fri Jun 26 13:07:13 2020
+#                    dlm: Mon Jun 27 19:04:02 2022
 #                    (c) 2014 A.M. Thurnherr
-#                    uE-Info: 144 14 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 213 68 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 $antsSummary = 'pre-process SBE 9plus CTD data for LADCP_w';
@@ -93,6 +93,9 @@
 #	Aug 30, 2019: - renamed -g to -m)odulo error correction (not)
 #				  - added -f)ill missing data
 #	Jun 26, 2020: - added salinity -b)ias correction
+#	Jun 27, 2022: - BUG: fill_gaps code could not deal with format errors (nans)
+#				  - reversed semantics of -m because modulo error correction code has bugs
+# HISTORY END
 
 # NOTES:
 #	w_CTD is positive during the downcast to make the sign of the apparent
@@ -120,7 +123,7 @@
 	'[use -a)lternate sensor pair]',
 	'[correct -S)alinity <bias>]',
 	'[-r)etain all data (no editing)] [allow infinite -o)utliers]',
-	'[suppress CTD -m)odulo error correction]',
+	'[apply CTD -m)odulo error correction]',
 	'[-s)ampling <rate[6Hz]>]',
 	'[lowpass w_CTD -c)utoff <limit[2s]>] [-w)inch-speed <granularity[10s]>]',
 	'[profile -i)d <id>] [station -l)ocation <lat/lon>]',
@@ -207,7 +210,7 @@
 		}
 	}
 
-	unless ($opt_m) {												# set up correction for dropped scans
+	if ($opt_m) {													# set up correction for dropped scans
 		$systimeF = &fnrNoErr('timeY');
 		$xmerrF  = &fnrNoErr('modError');
 		if (defined($systimeF) && defined($xmerrF)) {
@@ -269,7 +272,16 @@
 	my($scans_replaced) = 0;
 	my($scans_deleted) = 0;
 
-	for (my($scan)=30; $scan<@ants_; $scan++) {										# start a bit more than 1 second into the cast
+	printf("BEFORE: %d scans\n",scalar(@ants_));
+	for (my($scan)=my($scani)=0; $scan<@ants_; $scan++,$scani++) {					# remove scans with incomplete information
+		next if numbersp($ants_[$scan][$systimeF],$ants_[$scan][$xmerrF]);
+		printf(STDERR "scani#%d removed\n",$scani+1);
+		splice(@ants_,$scan,1);
+		$scan--; $scans_deleted++;
+    }
+	printf("AFTER: %d scans\n",scalar(@ants_));
+
+	for (my($scan) = 30; $scan<@ants_; $scan++) {									# start a bit more than 1 second into the cast	
 		next if ($ants_[$scan][$systimeF] == $ants_[$scan-1][$systimeF]);			# skip forward to next systime second
 
 		if ($ants_[$scan][$systimeF] > $ants_[$scan-1][$systimeF]+1) {				# gap spans at least one full second
@@ -344,7 +356,7 @@
 		}
 
 		my($scans_this_sec) = 0;
-		die("$ants_[$second_start][$systimeF]==$ants_[$second_start-1][$systimeF]+1")
+		die("scan#$second_start+1: $ants_[$second_start][$systimeF]==$ants_[$second_start-1][$systimeF]+1: assertion failed")
 			unless ($ants_[$second_start][$systimeF]==$ants_[$second_start-1][$systimeF]+1);
 		for (my($i)=0; $ants_[$second_start+$i][$systimeF]==$ants_[$second_start-1][$systimeF]+1; $i++) {
 			$scans_this_sec++;
--- a/plot_residual_profs.pl	Sat Apr 10 06:00:45 2021 -0400
+++ b/plot_residual_profs.pl	Mon Jun 27 19:06:50 2022 -1000
@@ -1,14 +1,15 @@
 #======================================================================
 #                    P L O T _ R E S I D U A L _ P R O F S . P L 
 #                    doc: Wed May 18 18:43:33 2016
-#                    dlm: Tue May 24 22:02:28 2016
+#                    dlm: Sun Apr 11 06:52:26 2021
 #                    (c) 2016 A.M. Thurnherr
-#                    uE-Info: 77 0 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 62 52 NIL 0 0 72 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
 #   May 18, 2016: - created from [plot_mean_residuals.pl]
 #	May 24, 2016: - improved
+#	Apr 11, 2021: - halved x-axis range
 
 require "$ANTS/libGMT.pl";
 
@@ -49,8 +50,8 @@
 	my($yellow_light) = 0.004;
 	my($red_light)	  = 0.01;
 
-	my($xmin) = -0.05;
-	my($xmax) =  0.05;
+	my($xmin) = -0.01;
+	my($xmax) =  0.01;
 	my($ymin) = round(antsParam('min_depth')-25,50);
 	my($ymax) = ($P{water_depth} > 0) ?
 				round($P{water_depth}+25,50) :
@@ -58,7 +59,7 @@
 	                                              
 	my($R) = "-R$xmin/$xmax/$ymin/$ymax";
 	my($depth_tics) = ($ymax < 1000 ) ? 'f10a100g100' : 'f100a500g500';
-	GMT_begin($pfn,'-JX10/-10',$R,"-P -Bf0.005a0.02g0.01:'Residual Vertical Velocity [m/s]':/$depth_tics:'Depth [m]':WeSn");
+	GMT_begin($pfn,'-JX10/-10',$R,"-P -Bf0.001a0.005g0.005:'Residual Vertical Velocity [m/s]':/$depth_tics:'Depth [m]':WeSn");
 
 	GMT_psxy('-W2,CornflowerBlue');													# zero line
 		printf(GMT "0 $ymin\n0 $ymax\n");
--- a/plot_wprof.pl	Sat Apr 10 06:00:45 2021 -0400
+++ b/plot_wprof.pl	Mon Jun 27 19:06:50 2022 -1000
@@ -1,9 +1,9 @@
 #======================================================================
 #                    P L O T _ W P R O F . P L 
 #                    doc: Sun Jul 26 11:08:50 2015
-#                    dlm: Tue Mar 23 08:28:12 2021
+#                    dlm: Mon Apr 12 08:44:01 2021
 #                    (c) 2015 A.M. Thurnherr
-#                    uE-Info: 25 39 NIL 0 0 72 0 2 4 NIL ofnI
+#                    uE-Info: 26 61 NIL 0 0 72 0 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -23,6 +23,7 @@
 #	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
+#	Apr 12, 2021: - added documentation on background shading
 
 # Tweakables:
 #
@@ -73,6 +74,12 @@
     }
 }
 
+# plot red \\\\ //// patterns (for dc and uc) in background 
+#	- based on rms residual (like residual profiles)
+#	- 100-m-thick layers
+#	- white (no pattern) for rms residual <= 0.002
+#	- red (max saturation) for rms residual >= 0.012
+
 sub plotRes()
 {
 	my($last_depth,$dc_sumsq_res,$dc_n,$uc_sumsq_res,$uc_n);
@@ -80,15 +87,15 @@
 		my($depth) = ($bi+0.5) * $opt_o;
 		if ($depth > $last_depth+100 || $bi == $#{$DNCAST{MEDIAN_W}}) {
 			if ($dc_n==0 || sqrt($dc_sumsq_res/$dc_n) > 0.002) {
-				my($green) = $dc_n ? round(100*max(0.01-max(sqrt($dc_sumsq_res/$dc_n)-0.002,0),0) * 255) : 0;
-				GMT_psxy("-Gp300/12:F255/$green/${green}B-");
+				my($lightness) = $dc_n ? round(100*max(0.01-max(sqrt($dc_sumsq_res/$dc_n)-0.002,0),0) * 255) : 0;
+				GMT_psxy("-Gp300/12:F255/$lightness/${lightness}B-");
 				printf(GMT "%g %g\n%g %g\n%g %g\n%g %g\n",
 								-0.1,$last_depth,0,$last_depth,
 								0,$depth,-0.1,$depth);
 			}
 			if ($uc_n==0 || sqrt($uc_sumsq_res/$uc_n) > 0.002) {
-				my($green) = $uc_n ? round(100*max(0.01-max(sqrt($uc_sumsq_res/$uc_n)-0.002,0),0) * 255) : 0;
-				GMT_psxy("-Gp300/9:F255/$green/${green}B-");
+				my($lightness) = $uc_n ? round(100*max(0.01-max(sqrt($uc_sumsq_res/$uc_n)-0.002,0),0) * 255) : 0;
+				GMT_psxy("-Gp300/9:F255/$lightness/${lightness}B-");
 				printf(GMT "%g %g\n%g %g\n%g %g\n%g %g\n",
 								0,$last_depth,0.07,$last_depth,
 								0.07,$depth,0,$depth);