author | A.M. Thurnherr <athurnherr@yahoo.com> |
Mon, 08 Mar 2021 12:07:26 -0500 | |
changeset 54 | 828e5466391b |
parent 51 | 0f6d9e64cc4f |
child 56 | 8f120b9f795a |
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 |
51
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
4 |
# dlm: Sun Apr 21 14:13:05 2019 |
0 | 5 |
# (c) 2010 A.M. Thurnherr |
51
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
6 |
# uE-Info: 25 56 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 |
0 | 26 |
|
27 |
# NOTES: |
|
28 |
# - resulting DEPTH field based on integrated w without any sound speed correction |
|
29 |
# - single-ping ensembles assumed, i.e. no percent-good tests applied |
|
30 |
# - specified bin numbers are 1-relative |
|
31 |
||
49 | 32 |
#---------------------------------------------------------------------- |
33 |
# Reference-Layer Velocities |
|
34 |
#---------------------------------------------------------------------- |
|
35 |
||
0 | 36 |
sub ref_lr_w($$$$) # calc ref-layer vert vels |
37 |
{ |
|
38 |
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
|
39 |
my(@w); |
0 | 40 |
|
4
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
41 |
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
|
42 |
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
|
43 |
if defined($dta->{ENSEMBLE}[$ens]->{W}[$bin]); |
0 | 44 |
} |
4
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
45 |
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
|
46 |
$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
|
47 |
$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
|
48 |
$dta->{ENSEMBLE}[$ens]->{REFLR_W_NSAMP} = @w; |
0 | 49 |
} |
50 |
||
49 | 51 |
sub ref_lr_uv($$$$) # calc ref-layer horiz vels |
52 |
{ |
|
53 |
my($dta,$ens,$rl_b0,$rl_b1) = @_; |
|
54 |
my(@u,@v); |
|
55 |
||
56 |
for (my($bin)=$rl_b0-1; $bin<=$rl_b1-1; $bin++) { |
|
57 |
next unless defined($dta->{ENSEMBLE}[$ens]->{U}[$bin]); |
|
58 |
die unless numbersp($dta->{ENSEMBLE}[$ens]->{U}[$bin],$dta->{ENSEMBLE}[$ens]->{V}[$bin]); |
|
59 |
push(@u,$dta->{ENSEMBLE}[$ens]->{U}[$bin]); |
|
60 |
push(@v,$dta->{ENSEMBLE}[$ens]->{V}[$bin]); |
|
61 |
} |
|
62 |
return unless (@u); |
|
63 |
$dta->{ENSEMBLE}[$ens]->{REFLR_U} = avg(@u); $dta->{ENSEMBLE}[$ens]->{REFLR_V} = avg(@v); |
|
64 |
$dta->{ENSEMBLE}[$ens]->{REFLR_UV_NSAMP} = @u; |
|
65 |
} |
|
66 |
||
0 | 67 |
#====================================================================== |
68 |
# ($firstgood,$lastgood,$atbottom,$w_gap_time) = |
|
2 | 69 |
# calcLADCPts($dta,$skip_ens,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap); |
0 | 70 |
#====================================================================== |
71 |
||
72 |
sub calcLADCPts($$$$) |
|
73 |
{ |
|
2 | 74 |
my($dta,$skip_ens,$rl_b0,$rl_b1,$max_gap) = @_; |
0 | 75 |
my($firstgood,$lastgood,$atbottom,$w_gap_time,$max_depth); |
76 |
||
2 | 77 |
for (my($depth)=0,my($e)=$skip_ens; $e<=$#{$dta->{ENSEMBLE}}; $e++) { |
0 | 78 |
|
79 |
ref_lr_w($dta,$e,$rl_b0,$rl_b1); |
|
80 |
||
81 |
if (defined($firstgood)) { |
|
82 |
$dta->{ENSEMBLE}[$e]->{ELAPSED} = # time since start |
|
83 |
$dta->{ENSEMBLE}[$e]->{UNIX_TIME} - |
|
84 |
$dta->{ENSEMBLE}[$firstgood]->{UNIX_TIME}; |
|
85 |
} else { |
|
86 |
if (defined($dta->{ENSEMBLE}[$e]->{REFLR_W})) { # start of prof. |
|
87 |
$firstgood = $lastgood = $e; |
|
88 |
$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
|
89 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $depth; |
0 | 90 |
} |
91 |
next; |
|
92 |
} |
|
93 |
||
94 |
unless (defined($dta->{ENSEMBLE}[$e]->{REFLR_W})) { # gap |
|
95 |
$w_gap_time += $dta->{ENSEMBLE}[$e]->{UNIX_TIME} - |
|
96 |
$dta->{ENSEMBLE}[$e-1]->{UNIX_TIME}; |
|
97 |
next; |
|
98 |
} |
|
99 |
||
100 |
my($dt) = $dta->{ENSEMBLE}[$e]->{UNIX_TIME} - # time step since |
|
101 |
$dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME}; # ... last good ens |
|
102 |
||
103 |
if ($dt > $max_gap) { |
|
49 | 104 |
if (($max_depth>50 && abs($depth)<0.1*$max_depth) && # looks like a profile |
105 |
(@{$dta->{ENSEMBLE}}-$e < 0.25*@{$dta->{ENSEMBLE}})) { # in the final quartile of the data |
|
106 |
warning(1,"long gap (%ds) after likely profile (0->%d->%dm) --- finishing at ens#$dta->{ENSEMBLE}[$e]->{NUMBER}\n", |
|
107 |
$dt,$max_depth,$depth); |
|
108 |
last; |
|
109 |
} elsif ((abs($depth) < 10) || # shallow gap at the beginning |
|
110 |
($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
|
111 |
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
|
112 |
warning(1,"long surface gap (%ds) --- restarting at ens#$dta->{ENSEMBLE}[$e]->{NUMBER} " . |
0f6d9e64cc4f
before adding dropped-scan correction to LADCP_w_CTD
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
49
diff
changeset
|
113 |
"[depth = %d m; max_depth = $md]\n",$dt,$depth); |
49 | 114 |
$firstgood = $lastgood = $e; |
115 |
undef($atbottom); undef($max_depth); |
|
116 |
$depth = 0; |
|
117 |
$dta->{ENSEMBLE}[$e]->{ELAPSED} = 0; |
|
118 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $depth; |
|
119 |
$w_gap_time = 0; |
|
120 |
next; |
|
2 | 121 |
} |
122 |
if ($dta->{ENSEMBLE}[$e]->{ELAPSED} < 200) { |
|
13 | 123 |
warning(1,"long gap (%ds) at ensembles #$dta->{ENSEMBLE}[$lastgood]->{NUMBER}-$dta->{ENSEMBLE}[$e]->{NUMBER}, %ds into the profile\n", |
2 | 124 |
$dt,$dta->{ENSEMBLE}[$e]->{ELAPSED}); |
125 |
} else { |
|
13 | 126 |
warning(1,"long gap (%ds) at ensembles #$dta->{ENSEMBLE}[$lastgood]->{NUMBER}-$dta->{ENSEMBLE}[$e]->{NUMBER}, %.1fmin into the profile\n", |
2 | 127 |
$dt,$dta->{ENSEMBLE}[$e]->{ELAPSED}/60); |
128 |
} |
|
0 | 129 |
} |
130 |
||
4
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
131 |
$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
|
132 |
if ($dt < 5); |
0 | 133 |
$dta->{ENSEMBLE}[$e]->{DEPTH} = $depth; |
134 |
||
135 |
$atbottom = $e, $max_depth = $depth if ($depth > $max_depth); |
|
136 |
$lastgood = $e; |
|
137 |
} |
|
4
e681262d0fd7
yay! first version I am really happy with. With plots 'n all.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
3
diff
changeset
|
138 |
|
49 | 139 |
for (my($e)=$firstgood; $e<=$lastgood; $e++) { # calculate u and v |
140 |
ref_lr_uv($dta,$e,$rl_b0,$rl_b1); |
|
141 |
} |
|
142 |
||
0 | 143 |
return ($firstgood,$lastgood,$atbottom,$w_gap_time); |
144 |
} |
|
145 |
||
49 | 146 |
#---------------------------------------------------------------------- |
147 |
||
0 | 148 |
1; |