time_series.pl
changeset 49 5006e9158207
parent 13 2788bf1bf1de
child 51 0f6d9e64cc4f
equal deleted inserted replaced
48:d9309804b6cf 49:5006e9158207
     1 #======================================================================
     1 #======================================================================
     2 #                    T I M E _ S E R I E S . P L 
     2 #                    T I M E _ S E R I E S . P L 
     3 #                    doc: Sun May 23 16:40:53 2010
     3 #                    doc: Sun May 23 16:40:53 2010
     4 #                    dlm: Wed Apr 17 17:05:16 2013
     4 #                    dlm: Wed May  2 11:23:48 2018
     5 #                    (c) 2010 A.M. Thurnherr
     5 #                    (c) 2010 A.M. Thurnherr
     6 #                    uE-Info: 20 63 NIL 0 0 72 2 2 4 NIL ofnI
     6 #                    uE-Info: 24 57 NIL 0 0 72 2 2 4 NIL ofnI
     7 #======================================================================
     7 #======================================================================
     8 
     8 
     9 # HISTORY:
     9 # HISTORY:
    10 #	May 23, 2010: - created from [perl-tools/RDI_Utils.pl]
    10 #	May 23, 2010: - created from [perl-tools/RDI_Utils.pl]
    11 #	Oct 20, 2010: - disabled max_gap profile-restarting code
    11 #	Oct 20, 2010: - disabled max_gap profile-restarting code
    16 #	Jul  4, 2011: - added support for $skip_ens
    16 #	Jul  4, 2011: - added support for $skip_ens
    17 #	Oct 11, 2011: - BUG: {DEPTH} had not been set at start of profile
    17 #	Oct 11, 2011: - BUG: {DEPTH} had not been set at start of profile
    18 #	Oct 12, 2011: - re-worked ref_lr_w()
    18 #	Oct 12, 2011: - re-worked ref_lr_w()
    19 #				  - stopped depth integration across gaps >= 5s
    19 #				  - stopped depth integration across gaps >= 5s
    20 #	Apr 17, 2013: - improved gap message (added ensemble range)
    20 #	Apr 17, 2013: - improved gap message (added ensemble range)
       
    21 #	Nov 27, 2017: - BUG: gap heuristic could not deal with P06#001
       
    22 #				  - BUG: gap heuristic could not deal with P06#025
       
    23 #	May  1, 2018: - added reflr u and v calculations
       
    24 #				  - BUG: reflr u and v calcs did not work
    21 
    25 
    22 # NOTES:
    26 # NOTES:
    23 #	- resulting DEPTH field based on integrated w without any sound speed correction
    27 #	- resulting DEPTH field based on integrated w without any sound speed correction
    24 #	- single-ping ensembles assumed, i.e. no percent-good tests applied
    28 #	- single-ping ensembles assumed, i.e. no percent-good tests applied
    25 #	- specified bin numbers are 1-relative
    29 #	- specified bin numbers are 1-relative
       
    30 
       
    31 #----------------------------------------------------------------------
       
    32 # Reference-Layer Velocities
       
    33 #----------------------------------------------------------------------
    26 
    34 
    27 sub ref_lr_w($$$$)										# calc ref-layer vert vels
    35 sub ref_lr_w($$$$)										# calc ref-layer vert vels
    28 {
    36 {
    29 	my($dta,$ens,$rl_b0,$rl_b1) = @_;
    37 	my($dta,$ens,$rl_b0,$rl_b1) = @_;
    30 	my(@w);
    38 	my(@w);
    35 	}
    43 	}
    36 	return unless (@w);
    44 	return unless (@w);
    37 	$dta->{ENSEMBLE}[$ens]->{REFLR_W} = avg(@w);
    45 	$dta->{ENSEMBLE}[$ens]->{REFLR_W} = avg(@w);
    38 	$dta->{ENSEMBLE}[$ens]->{REFLR_W_STDDEV} = stddev2($dta->{ENSEMBLE}[$ens]->{REFLR_W},@w);
    46 	$dta->{ENSEMBLE}[$ens]->{REFLR_W_STDDEV} = stddev2($dta->{ENSEMBLE}[$ens]->{REFLR_W},@w);
    39 	$dta->{ENSEMBLE}[$ens]->{REFLR_W_NSAMP} = @w;
    47 	$dta->{ENSEMBLE}[$ens]->{REFLR_W_NSAMP} = @w;
       
    48 }
       
    49 
       
    50 sub ref_lr_uv($$$$)										# calc ref-layer horiz vels
       
    51 {
       
    52 	my($dta,$ens,$rl_b0,$rl_b1) = @_;
       
    53 	my(@u,@v);
       
    54 
       
    55 	for (my($bin)=$rl_b0-1; $bin<=$rl_b1-1; $bin++) {
       
    56 		next unless defined($dta->{ENSEMBLE}[$ens]->{U}[$bin]);
       
    57 		die unless numbersp($dta->{ENSEMBLE}[$ens]->{U}[$bin],$dta->{ENSEMBLE}[$ens]->{V}[$bin]);
       
    58 		push(@u,$dta->{ENSEMBLE}[$ens]->{U}[$bin]);
       
    59 		push(@v,$dta->{ENSEMBLE}[$ens]->{V}[$bin]);
       
    60 	}
       
    61 	return unless (@u);
       
    62 	$dta->{ENSEMBLE}[$ens]->{REFLR_U} = avg(@u); $dta->{ENSEMBLE}[$ens]->{REFLR_V} = avg(@v);
       
    63 	$dta->{ENSEMBLE}[$ens]->{REFLR_UV_NSAMP} = @u;
    40 }
    64 }
    41 
    65 
    42 #======================================================================
    66 #======================================================================
    43 # ($firstgood,$lastgood,$atbottom,$w_gap_time) =
    67 # ($firstgood,$lastgood,$atbottom,$w_gap_time) =
    44 #	calcLADCPts($dta,$skip_ens,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap);
    68 #	calcLADCPts($dta,$skip_ens,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap);
    74 	
    98 	
    75 		my($dt) = $dta->{ENSEMBLE}[$e]->{UNIX_TIME} -		# time step since
    99 		my($dt) = $dta->{ENSEMBLE}[$e]->{UNIX_TIME} -		# time step since
    76 				  $dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME}; # ... last good ens
   100 				  $dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME}; # ... last good ens
    77 	
   101 	
    78 		if ($dt > $max_gap) {
   102 		if ($dt > $max_gap) {
    79 			if ($max_depth>50 && $depth<0.1*$max_depth) {
   103 			if (($max_depth>50 && abs($depth)<0.1*$max_depth) &&					# looks like a profile
    80 				warning(1,"long gap (%ds) near end of profile --- terminated at ensemble #$dta->{ENSEMBLE}[$e]->{NUMBER}\n",$dt);
   104 				(@{$dta->{ENSEMBLE}}-$e < 0.25*@{$dta->{ENSEMBLE}})) {				# in the final quartile of the data
    81 				last;				
   105 					warning(1,"long gap (%ds) after likely profile (0->%d->%dm) --- finishing at ens#$dta->{ENSEMBLE}[$e]->{NUMBER}\n",
    82             }
   106 						$dt,$max_depth,$depth);
    83             if ($depth < 10) {
   107 					last;				
    84 				warning(1,"long gap (%ds) near beginning of profile --- restarted at ensemble #$dta->{ENSEMBLE}[$e]->{NUMBER}\n",$dt);
   108             } elsif ((abs($depth) < 10) ||											# shallow gap at the beginning
    85 				$firstgood = $lastgood = $e;
   109             		 ($depth == $max_depth)) {										# biased in-air data
    86 				undef($atbottom); undef($max_depth);
   110 						warning(1,"long surface gap (%ds) --- restarting at ens#$dta->{ENSEMBLE}[$e]->{NUMBER}\n",$dt);
    87 				$depth = 0;
   111 						warning(1,"[depth = $depth, max_depth = $max_depth]\n");
    88 				$dta->{ENSEMBLE}[$e]->{ELAPSED} = 0;
   112 						$firstgood = $lastgood = $e;
    89 				$dta->{ENSEMBLE}[$e]->{DEPTH} = $depth;
   113 						undef($atbottom); undef($max_depth);
    90 				$w_gap_time = 0;
   114 						$depth = 0;
    91 				next;
   115 						$dta->{ENSEMBLE}[$e]->{ELAPSED} = 0;
       
   116 						$dta->{ENSEMBLE}[$e]->{DEPTH} = $depth;
       
   117 						$w_gap_time = 0;
       
   118 						next;
    92 			}
   119 			}
    93 			if ($dta->{ENSEMBLE}[$e]->{ELAPSED} < 200) {
   120 			if ($dta->{ENSEMBLE}[$e]->{ELAPSED} < 200) {
    94 				warning(1,"long gap (%ds) at ensembles #$dta->{ENSEMBLE}[$lastgood]->{NUMBER}-$dta->{ENSEMBLE}[$e]->{NUMBER}, %ds into the profile\n",
   121 				warning(1,"long gap (%ds) at ensembles #$dta->{ENSEMBLE}[$lastgood]->{NUMBER}-$dta->{ENSEMBLE}[$e]->{NUMBER}, %ds into the profile\n",
    95 					$dt,$dta->{ENSEMBLE}[$e]->{ELAPSED});
   122 					$dt,$dta->{ENSEMBLE}[$e]->{ELAPSED});
    96 			} else {
   123 			} else {
   105 	
   132 	
   106 		$atbottom = $e, $max_depth = $depth if ($depth > $max_depth); 
   133 		$atbottom = $e, $max_depth = $depth if ($depth > $max_depth); 
   107 		$lastgood = $e;
   134 		$lastgood = $e;
   108 	}
   135 	}
   109 
   136 
       
   137 	for (my($e)=$firstgood; $e<=$lastgood; $e++) {						# calculate u and v
       
   138 		ref_lr_uv($dta,$e,$rl_b0,$rl_b1);
       
   139 	}
       
   140 
   110 	return ($firstgood,$lastgood,$atbottom,$w_gap_time);
   141 	return ($firstgood,$lastgood,$atbottom,$w_gap_time);
   111 }
   142 }
   112 
   143 
       
   144 #----------------------------------------------------------------------
       
   145 
   113 1;
   146 1;