plot_bin_residuals.pl
changeset 56 8f120b9f795a
parent 54 828e5466391b
equal deleted inserted replaced
55:2d8e1139acd5 56:8f120b9f795a
       
     1 #======================================================================
       
     2 #                    P L O T _ B I N _ R E S I D U A L S . P L 
       
     3 #                    doc: Tue Jul 28 13:21:09 2015
       
     4 #                    dlm: Thu Jul  1 13:23:10 2021
       
     5 #                    (c) 2015 A.M. Thurnherr
       
     6 #                    uE-Info: 23 52 NIL 0 0 72 2 2 4 NIL ofnI
       
     7 #======================================================================
       
     8 
       
     9 # HISTORY:
       
    10 #	Jul 28, 2015: - created from [LWplot_BR]
       
    11 #	Jul 29, 2015: - finished
       
    12 #	Jul 30, 2015: - added bin_tics
       
    13 #				  - added outGrid_* support
       
    14 #	Jan 22, 2015: - many changes
       
    15 #				  - added quality assessment label
       
    16 #	Jan 25, 2016: - added return on no data
       
    17 #	Mar 16, 2016: - adapted to gmt5
       
    18 #   May 18, 2016: - added version
       
    19 #	May 15, 2020: - adapted to bin-residuals separate per beam pair
       
    20 #				  - added orange range
       
    21 #				  - slightly relaxed green range
       
    22 #	Jun 30, 2021: - renamed from plot_mean_residuals.pl
       
    23 #	Jul  1, 2021: - adapted to more standard %PARAMs
       
    24 
       
    25 require "$ANTS/libGMT.pl";
       
    26 
       
    27 sub plot_bin_residuals($)
       
    28 {
       
    29 	my($pfn) = @_;
       
    30 
       
    31 	return unless ($P{'BR_bin.max'});
       
    32 
       
    33 	my($xmin) = -0.05;
       
    34 	my($xmax) =  0.05;
       
    35 	my($ymin) =  0.5;
       
    36 	my($ymax) = $P{'BR_bin.max'} + 0.5;
       
    37 
       
    38 	my($R) = "-R$xmin/$xmax/$ymin/$ymax";
       
    39 	GMT_begin($pfn,'-JX10/-10',$R,'-P');
       
    40 
       
    41 	if ($outGrid_firstBin>$LADCP_firstBin || $outGrid_lastBin<$LADCP_lastBin) {		# mark used bins
       
    42 		GMT_psxy('-G200 -L');
       
    43 		printf(GMT ">\n%f %f\n%f %f\n%f %f\n%f %f\n",
       
    44 			$xmin,$LADCP_firstBin-0.5,
       
    45 			$xmax,$LADCP_firstBin-0.5,
       
    46 			$xmax,$outGrid_firstBin-0.5,
       
    47 			$xmin,$outGrid_firstBin-0.5)
       
    48 				if ($outGrid_firstBin>$LADCP_firstBin);
       
    49 		printf(GMT ">\n%f %f\n%f %f\n%f %f\n%f %f\n",
       
    50 			$xmin,$LADCP_lastBin+0.5,
       
    51 			$xmax,$LADCP_lastBin+0.5,
       
    52 			$xmax,$outGrid_lastBin+0.5,
       
    53 			$xmin,$outGrid_lastBin+0.5)
       
    54 				if ($outGrid_lastBin<$LADCP_lastBin);
       
    55 	}
       
    56 
       
    57 	GMT_psxy('-W1');																# plot zero line
       
    58 	printf(GMT "0 $ymin\n0 $ymax\n");
       
    59 
       
    60 	GMT_psxy('-W2,coral,8_2:0');
       
    61 		for (my($bin)=$LADCP_firstBin; $bin<@dc_bres12; $bin++) {			
       
    62 			next if ($bin+1<$outGrid_firstBin || $bin+1>$outGrid_lastBin);
       
    63 			next unless ($dc_bres12_nsamp[$bin] >= $dc_bres12_max_nsamp/3);
       
    64 			printf(GMT "%f %d\n",$dc_avg_bres12[$bin],$bin+1);
       
    65         }
       
    66 	GMT_psxy('-W2,coral,1_1:0');
       
    67 		for (my($bin)=$LADCP_firstBin; $bin<@dc_bres34; $bin++) {			
       
    68 			next if ($bin+1<$outGrid_firstBin || $bin+1>$outGrid_lastBin);
       
    69 			next unless ($dc_bres34_nsamp[$bin] >= $dc_bres34_max_nsamp/3);
       
    70 			printf(GMT "%f %d\n",$dc_avg_bres34[$bin],$bin+1);
       
    71         }
       
    72 	GMT_psxy('-Ex0.2/2,coral');
       
    73 		for (my($bin)=$LADCP_firstBin-1; $bin<@dc_bres12; $bin++) {
       
    74 			printf(GMT "%f %d %f\n",
       
    75 							$dc_avg_bres12[$bin],
       
    76 							$bin+1,
       
    77 							($dc_bres12_nsamp[$bin] > 1) ?
       
    78 								$dc_sig_bres12[$bin]/sqrt($dc_bres12_nsamp[$bin]-1) : 0);
       
    79 		}
       
    80 		for (my($bin)=$LADCP_firstBin-1; $bin<@dc_bres34; $bin++) {
       
    81 			printf(GMT "%f %d %f\n",
       
    82 							$dc_avg_bres34[$bin],
       
    83 							$bin+1,
       
    84 							($dc_bres34_nsamp[$bin] > 1) ?
       
    85 								$dc_sig_bres34[$bin]/sqrt($dc_bres34_nsamp[$bin]-1) : 0);
       
    86         }
       
    87 	GMT_psxy('-W2,SeaGreen,8_2:0');
       
    88 		for (my($bin)=$LADCP_firstBin; $bin<@uc_bres12; $bin++) {			
       
    89 			next if ($bin+1<$outGrid_firstBin || $bin+1>$outGrid_lastBin);
       
    90 			next unless ($uc_bres12_nsamp[$bin] >= $uc_bres12_max_nsamp/3);
       
    91 			printf(GMT "%f %d\n",$uc_avg_bres12[$bin],$bin+1);
       
    92         }
       
    93 	GMT_psxy('-W2,SeaGreen,1_1:0');
       
    94 		for (my($bin)=$LADCP_firstBin; $bin<@uc_bres34; $bin++) {			
       
    95 			next if ($bin+1<$outGrid_firstBin || $bin+1>$outGrid_lastBin);
       
    96 			next unless ($uc_bres34_nsamp[$bin] >= $uc_bres34_max_nsamp/3);
       
    97 			printf(GMT "%f %d\n",$uc_avg_bres34[$bin],$bin+1);
       
    98         }
       
    99 	GMT_psxy('-Ex0.2/2,SeaGreen');
       
   100 		for (my($bin)=$LADCP_firstBin-1; $bin<@uc_bres12; $bin++) {
       
   101 			printf(GMT "%f %d %f\n",
       
   102 							$uc_avg_bres12[$bin],
       
   103 							$bin+1,
       
   104 							($uc_bres12_nsamp[$bin] > 1) ?
       
   105 								$uc_sig_bres12[$bin]/sqrt($uc_bres12_nsamp[$bin]-1) : 0);
       
   106 		}
       
   107 		for (my($bin)=$LADCP_firstBin-1; $bin<@uc_bres34; $bin++) {
       
   108 			printf(GMT "%f %d %f\n",
       
   109 							$uc_avg_bres34[$bin],
       
   110 							$bin+1,
       
   111 							($uc_bres34_nsamp[$bin] > 1) ?
       
   112 								$uc_sig_bres34[$bin]/sqrt($uc_bres34_nsamp[$bin]-1) : 0);
       
   113         }
       
   114 
       
   115 	GMT_unitcoords();																	# LABELS
       
   116 	GMT_pstext('-F+f9,Helvetica,orange+jTR -N -Gwhite');
       
   117         print(GMT "0.99 0.01 V$VERSION\n");
       
   118         
       
   119 	GMT_pstext('-F+f14,Helvetica,blue+jBL -N');											# profile id
       
   120 		print(GMT "0.0 -0.03 $P{out_basename} $P{run_label}\n");
       
   121 
       
   122 	GMT_pstext('-F+f12,Helvetica-Bold,black+jBL -Gwhite'); 								# rms residuals
       
   123 		print(GMT "0.1 0.88 beams <1,2>\n");
       
   124 	GMT_pstext('-F+f12,Helvetica-Bold,black+jBL -Gwhite');
       
   125 		print(GMT "0.7 0.88 beams <3,4>\n");
       
   126 
       
   127 	GMT_pstext('-F+f12,Helvetica,coral+jBL');											# rms residuals
       
   128 		print(GMT "0.01 0.93 dc\n");
       
   129 	if ($dc_bres12_rms >= 0.005) { 		GMT_pstext('-F+f12,Helvetica,white+jBL -Gred'); }
       
   130 	elsif ($dc_bres12_rms >= 0.003) { 	GMT_pstext('-F+f12,Helvetica,black+jBL -Gorange'); }
       
   131 	elsif ($dc_bres12_rms >= 0.0015) { 	GMT_pstext('-F+f12,Helvetica,black+jBL -Gyellow'); }
       
   132 	else {								GMT_pstext('-F+f12,Helvetica,black+jBL -Ggreen'); }
       
   133 		printf(GMT "0.10 0.93 %.1f mm/s rms\n",1000*$dc_bres12_rms);
       
   134 
       
   135 	if ($dc_bres34_rms >= 0.005) { 		GMT_pstext('-F+f12,Helvetica,white+jBL -Gred'); }
       
   136 	elsif ($dc_bres34_rms >= 0.003) { 	GMT_pstext('-F+f12,Helvetica,black+jBL -Gorange'); }
       
   137 	elsif ($dc_bres34_rms >= 0.0015) { 	GMT_pstext('-F+f12,Helvetica,black+jBL -Gyellow'); }
       
   138 	else {								GMT_pstext('-F+f12,Helvetica,black+jBL -Ggreen'); }
       
   139 		printf(GMT "0.70 0.93 %.1f mm/s rms\n",1000*$dc_bres34_rms);
       
   140 
       
   141 	GMT_pstext('-F+f12,Helvetica,SeaGreen+jBL');
       
   142 		print(GMT "0.01 0.98 uc\n");
       
   143 	if ($uc_bres12_rms >= 0.005) { 		GMT_pstext('-F+f12,Helvetica,white+jBL -Gred'); }
       
   144 	elsif ($uc_bres12_rms >= 0.003) { 	GMT_pstext('-F+f12,Helvetica,black+jBL -Gorange'); }
       
   145 	elsif ($uc_bres12_rms >= 0.0015) { 	GMT_pstext('-F+f12,Helvetica,black+jBL -Gyellow'); }
       
   146 	else {								GMT_pstext('-F+f12,Helvetica,black+jBL -Ggreen'); }
       
   147 		printf(GMT "0.10 0.98 %.1f mm/s rms\n",1000*$uc_bres12_rms);
       
   148 	if ($uc_bres34_rms >= 0.005) { 		GMT_pstext('-F+f12,Helvetica,white+jBL -Gred'); }
       
   149 	elsif ($uc_bres34_rms >= 0.003) { 	GMT_pstext('-F+f12,Helvetica,black+jBL -Gorange'); }
       
   150 	elsif ($uc_bres34_rms >= 0.0015) { 	GMT_pstext('-F+f12,Helvetica,black+jBL -Gyellow'); }
       
   151 	else {								GMT_pstext('-F+f12,Helvetica,black+jBL -Ggreen'); }
       
   152 		printf(GMT "0.70 0.98 %.1f mm/s rms\n",1000*$uc_bres34_rms);
       
   153 
       
   154 	my($bin_tics) = ($ymax <= 20) ? 'f1a1' : 'f1a2';
       
   155 	GMT_setR($R);																		# FINISH PLOT
       
   156 	GMT_end("-Bf0.005a0.02:'Residual Vertical Velocity [m/s]':/$bin_tics:'Bin [#]':WeSn");
       
   157 }
       
   158 
       
   159 1; # return true on require