author | A.M. Thurnherr <athurnherr@yahoo.com> |
Sat, 24 Jul 2021 10:35:41 -0400 | |
changeset 56 | 8f120b9f795a |
parent 51 | 0f6d9e64cc4f |
child 60 | 74fecc295d85 |
permissions | -rw-r--r-- |
0 | 1 |
#====================================================================== |
2 | 2 |
# T I M E _ S E R I E S . P L |
0 | 3 |
# doc: Sun May 23 16:40:53 2010 |
56 | 4 |
# dlm: Sat Apr 24 11:19:07 2021 |
0 | 5 |
# (c) 2010 A.M. Thurnherr |
56 | 6 |
# uE-Info: 26 27 NIL 0 0 72 2 2 4 NIL ofnI |
0 | 7 |
#====================================================================== |
8 |
||
9 |
# HISTORY: |
|
10 |
# May 23, 2010: - created from [perl-tools/RDI_Utils.pl] |
|
11 |
# Oct 20, 2010: - disabled max_gap profile-restarting code |
|
12 |
# Dec 17, 2010: - re-added {DEPTH} field to ensembles |
|
13 |
# Dec 18, 2010: - max gap re-enabled |
|
14 |
# Dec 20, 2010: - cosmetics |
|
2 | 15 |
# Jul 2, 2011: - tightened gap-detection code |
16 |
# Jul 4, 2011: - added support for $skip_ens |
|
3
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
2
diff
changeset
|
17 |
# Oct 11, 2011: - BUG: {DEPTH} had not been set at start of profile |
4
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
18 |
# Oct 12, 2011: - re-worked ref_lr_w() |
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
19 |
# - stopped depth integration across gaps >= 5s |
13 | 20 |
# Apr 17, 2013: - improved gap message (added ensemble range) |
49 | 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 |
|
51
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
25 |
# Apr 21, 2019: - improved surface gap warning message |
56 | 26 |
# Apr 24, 2021: - output cosmetics |
0 | 27 |
|
28 |
# NOTES: |
|
29 |
# - resulting DEPTH field based on integrated w without any sound speed correction |
|
30 |
# - single-ping ensembles assumed, i.e. no percent-good tests applied |
|
31 |
# - specified bin numbers are 1-relative |
|
32 |
||
49 | 33 |
#---------------------------------------------------------------------- |
34 |
# Reference-Layer Velocities |
|
35 |
#---------------------------------------------------------------------- |
|
36 |
||
0 | 37 |
sub ref_lr_w($$$$) # calc ref-layer vert vels |
38 |
{ |
|
39 |
my($dta,$ens,$rl_b0,$rl_b1) = @_; |
|
4
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
40 |
my(@w); |
0 | 41 |
|
4
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
42 |
for (my($bin)=$rl_b0-1; $bin<=$rl_b1-1; $bin++) { |
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
43 |
push(@w,$dta->{ENSEMBLE}[$ens]->{W}[$bin]) |
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
44 |
if defined($dta->{ENSEMBLE}[$ens]->{W}[$bin]); |
0 | 45 |
} |
4
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
46 |
return unless (@w); |
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
47 |
$dta->{ENSEMBLE}[$ens]->{REFLR_W} = avg(@w); |
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
48 |
$dta->{ENSEMBLE}[$ens]->{REFLR_W_STDDEV} = stddev2($dta->{ENSEMBLE}[$ens]->{REFLR_W},@w); |
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
49 |
$dta->{ENSEMBLE}[$ens]->{REFLR_W_NSAMP} = @w; |
0 | 50 |
} |
51 |
||
49 | 52 |
sub ref_lr_uv($$$$) # calc ref-layer horiz vels |
53 |
{ |
|
54 |
my($dta,$ens,$rl_b0,$rl_b1) = @_; |
|
55 |
my(@u,@v); |
|
56 |
||
57 |
for (my($bin)=$rl_b0-1; $bin<=$rl_b1-1; $bin++) { |
|
58 |
next unless defined($dta->{ENSEMBLE}[$ens]->{U}[$bin]); |
|
59 |
die unless numbersp($dta->{ENSEMBLE}[$ens]->{U}[$bin],$dta->{ENSEMBLE}[$ens]->{V}[$bin]); |
|
60 |
push(@u,$dta->{ENSEMBLE}[$ens]->{U}[$bin]); |
|
61 |
push(@v,$dta->{ENSEMBLE}[$ens]->{V}[$bin]); |
|
62 |
} |
|
63 |
return unless (@u); |
|
64 |
$dta->{ENSEMBLE}[$ens]->{REFLR_U} = avg(@u); $dta->{ENSEMBLE}[$ens]->{REFLR_V} = avg(@v); |
|
65 |
$dta->{ENSEMBLE}[$ens]->{REFLR_UV_NSAMP} = @u; |
|
66 |
} |
|
67 |
||
0 | 68 |
#====================================================================== |
69 |
# ($firstgood,$lastgood,$atbottom,$w_gap_time) = |
|
2 | 70 |
# calcLADCPts($dta,$skip_ens,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap); |
0 | 71 |
#====================================================================== |
72 |
||
73 |
sub calcLADCPts($$$$) |
|
74 |
{ |
|
2 | 75 |
my($dta,$skip_ens,$rl_b0,$rl_b1,$max_gap) = @_; |
0 | 76 |
my($firstgood,$lastgood,$atbottom,$w_gap_time,$max_depth); |
77 |
||
2 | 78 |
for (my($depth)=0,my($e)=$skip_ens; $e<=$#{$dta->{ENSEMBLE}}; $e++) { |
0 | 79 |
|
80 |
ref_lr_w($dta,$e,$rl_b0,$rl_b1); |
|
81 |
||
82 |
if (defined($firstgood)) { |
|
83 |
$dta->{ENSEMBLE}[$e]->{ELAPSED} = # time since start |
|
84 |
$dta->{ENSEMBLE}[$e]->{UNIX_TIME} - |
|
85 |
$dta->{ENSEMBLE}[$firstgood]->{UNIX_TIME}; |
|
86 |
} else { |
|
87 |
if (defined($dta->{ENSEMBLE}[$e]->{REFLR_W})) { # start of prof. |
|
88 |
$firstgood = $lastgood = $e; |
|
89 |
$dta->{ENSEMBLE}[$e]->{ELAPSED} = 0; |
|
3
9c021fdea1ff
Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
2
diff
changeset
|
90 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $depth; |
0 | 91 |
} |
92 |
next; |
|
93 |
} |
|
94 |
||
95 |
unless (defined($dta->{ENSEMBLE}[$e]->{REFLR_W})) { # gap |
|
96 |
$w_gap_time += $dta->{ENSEMBLE}[$e]->{UNIX_TIME} - |
|
97 |
$dta->{ENSEMBLE}[$e-1]->{UNIX_TIME}; |
|
98 |
next; |
|
99 |
} |
|
100 |
||
101 |
my($dt) = $dta->{ENSEMBLE}[$e]->{UNIX_TIME} - # time step since |
|
102 |
$dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME}; # ... last good ens |
|
103 |
||
104 |
if ($dt > $max_gap) { |
|
49 | 105 |
if (($max_depth>50 && abs($depth)<0.1*$max_depth) && # looks like a profile |
106 |
(@{$dta->{ENSEMBLE}}-$e < 0.25*@{$dta->{ENSEMBLE}})) { # in the final quartile of the data |
|
107 |
warning(1,"long gap (%ds) after likely profile (0->%d->%dm) --- finishing at ens#$dta->{ENSEMBLE}[$e]->{NUMBER}\n", |
|
108 |
$dt,$max_depth,$depth); |
|
109 |
last; |
|
110 |
} elsif ((abs($depth) < 10) || # shallow gap at the beginning |
|
111 |
($depth == $max_depth)) { # biased in-air data |
|
51
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
112 |
my($md) = defined($max_depth) ? sprintf('%d',$max_depth) : 'undefined'; |
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
113 |
warning(1,"long surface gap (%ds) --- restarting at ens#$dta->{ENSEMBLE}[$e]->{NUMBER} " . |
56 | 114 |
"[depth = %d m; max_depth = $md m]\n",$dt,$depth); |
49 | 115 |
$firstgood = $lastgood = $e; |
116 |
undef($atbottom); undef($max_depth); |
|
117 |
$depth = 0; |
|
118 |
$dta->{ENSEMBLE}[$e]->{ELAPSED} = 0; |
|
119 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $depth; |
|
120 |
$w_gap_time = 0; |
|
121 |
next; |
|
2 | 122 |
} |
123 |
if ($dta->{ENSEMBLE}[$e]->{ELAPSED} < 200) { |
|
13 | 124 |
warning(1,"long gap (%ds) at ensembles #$dta->{ENSEMBLE}[$lastgood]->{NUMBER}-$dta->{ENSEMBLE}[$e]->{NUMBER}, %ds into the profile\n", |
2 | 125 |
$dt,$dta->{ENSEMBLE}[$e]->{ELAPSED}); |
126 |
} else { |
|
13 | 127 |
warning(1,"long gap (%ds) at ensembles #$dta->{ENSEMBLE}[$lastgood]->{NUMBER}-$dta->{ENSEMBLE}[$e]->{NUMBER}, %.1fmin into the profile\n", |
2 | 128 |
$dt,$dta->{ENSEMBLE}[$e]->{ELAPSED}/60); |
129 |
} |
|
0 | 130 |
} |
131 |
||
4
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
132 |
$depth += $dta->{ENSEMBLE}[$lastgood]->{REFLR_W} * $dt # integrate |
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
133 |
if ($dt < 5); |
0 | 134 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $depth; |
135 |
||
136 |
$atbottom = $e, $max_depth = $depth if ($depth > $max_depth); |
|
137 |
$lastgood = $e; |
|
138 |
} |
|
4
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
139 |
|
49 | 140 |
for (my($e)=$firstgood; $e<=$lastgood; $e++) { # calculate u and v |
141 |
ref_lr_uv($dta,$e,$rl_b0,$rl_b1); |
|
142 |
} |
|
143 |
||
0 | 144 |
return ($firstgood,$lastgood,$atbottom,$w_gap_time); |
145 |
} |
|
146 |
||
49 | 147 |
#---------------------------------------------------------------------- |
148 |
||
0 | 149 |
1; |