1 #====================================================================== |
1 #====================================================================== |
2 # E D I T _ D A T A . P L |
2 # E D I T _ D A T A . P L |
3 # doc: Sat May 22 21:35:55 2010 |
3 # doc: Sat May 22 21:35:55 2010 |
4 # dlm: Sat Oct 15 20:59:38 2011 |
4 # dlm: Thu Oct 20 15:58:08 2011 |
5 # (c) 2010 A.M. Thurnherr |
5 # (c) 2010 A.M. Thurnherr |
6 # uE-Info: 163 0 NIL 0 0 72 2 2 4 NIL ofnI |
6 # uE-Info: 207 0 NIL 0 0 72 2 2 4 NIL ofnI |
7 #====================================================================== |
7 #====================================================================== |
8 |
8 |
9 # HISTORY: |
9 # HISTORY: |
10 # May 22, 2010: - created |
10 # May 22, 2010: - created |
11 # May 24, 2010: - added editSideLobesFromSeabed() |
11 # May 24, 2010: - added editSideLobesFromSeabed() |
20 # counted, not just those between first and lastBin |
20 # counted, not just those between first and lastBin |
21 # Oct 11, 2011: - moved defaults to [defaults.pl] |
21 # Oct 11, 2011: - moved defaults to [defaults.pl] |
22 # Oct 12, 2011: - added &editSurfLayer() |
22 # Oct 12, 2011: - added &editSurfLayer() |
23 # - BUG: editSideLobes() was slightly loose |
23 # - BUG: editSideLobes() was slightly loose |
24 # Oct 15, 2011: - added editWOutliers() |
24 # Oct 15, 2011: - added editWOutliers() |
|
25 # Oct 20, 2011: - added editFarBins() |
25 |
26 |
26 # NOTES: |
27 # NOTES: |
27 # - all bins must be edited (not just the ones between $LADCP_firstBin |
28 # - all bins must be edited (not just the ones between $LADCP_firstBin |
28 # and $LADCP_lastBin to allow reflr calculations to use bins outside |
29 # and $LADCP_lastBin to allow reflr calculations to use bins outside |
29 # this range |
30 # this range (ONLY FOR BEAM-COORD EDITS) |
30 # - however, to make the stats work, only the edited velocities |
31 # - however, to make the stats work, only the edited velocities |
31 # inside the bin range are counted |
32 # inside the bin range are counted |
32 |
33 |
33 #====================================================================== |
34 #====================================================================== |
34 # $vv = countValidVels($ens) |
35 # $vv = countValidVels($ens) |
47 } |
48 } |
48 return $vv; |
49 return $vv; |
49 } |
50 } |
50 |
51 |
51 #====================================================================== |
52 #====================================================================== |
52 # $edited = editCorr($ens,$threshold) |
53 # $removed = editCorr($ens,$threshold) |
53 # |
54 # |
54 # NOTES: |
55 # NOTES: |
55 # - called before Earth vels have been calculated |
56 # - called before Earth vels have been calculated |
56 #====================================================================== |
57 #====================================================================== |
57 |
58 |
91 } |
92 } |
92 return $nrm; |
93 return $nrm; |
93 } |
94 } |
94 |
95 |
95 #====================================================================== |
96 #====================================================================== |
96 # $edited = editTilt($ens,$threshold) |
97 # $removed = editTilt($ens,$threshold) |
97 # |
98 # |
98 # NOTES: |
99 # NOTES: |
99 # - called before Earth vels have been calculated |
100 # - called before Earth vels have been calculated |
100 # - sets TILT field for each ensemble as a side-effect |
101 # - sets TILT field for each ensemble as a side-effect |
101 # - for consistency with editCorr() the individual velocities are counted |
102 # - for consistency with editCorr() the individual velocities are counted |
120 } |
121 } |
121 return $nrm; |
122 return $nrm; |
122 } |
123 } |
123 |
124 |
124 #====================================================================== |
125 #====================================================================== |
125 # $edited = editErrVel($ens,$threshold) |
126 # $removed = editErrVel($ens,$threshold) |
126 # |
127 # |
127 # NOTES: |
128 # NOTES: |
128 # - call after Earth vels have been calculated |
129 # - call after Earth vels have been calculated |
129 # - count only edited vels in selected bin range |
130 # - count only removed vels in selected bin range |
130 #====================================================================== |
131 #====================================================================== |
131 |
132 |
132 sub editErrVel($$) |
133 sub editErrVel($$) |
133 { |
134 { |
134 my($ens,$lim) = @_; |
135 my($ens,$lim) = @_; |
142 } |
143 } |
143 return $nrm; |
144 return $nrm; |
144 } |
145 } |
145 |
146 |
146 #====================================================================== |
147 #====================================================================== |
147 # $edited = editWOutliers($ens) |
148 # $removed = editWOutliers($ens,$lim) |
148 # |
149 # |
149 # NOTES: |
150 # NOTES: |
150 # - call after Earth vels have been calculated |
151 # - call after Earth vels have been calculated |
151 # - count only edited vels in selected bin range |
152 # - count only removed vels in selected bin range |
152 # - $DE_outliers_mad_limit determines what is an outlier |
153 # - lim determines how many times the mad an outlier has to be from median |
153 #====================================================================== |
154 #====================================================================== |
154 |
155 |
155 sub editWOutliers($) |
156 sub editWOutliers($$) |
156 { |
157 { |
157 my($ens) = @_; |
158 my($ens,$lim) = @_; |
158 my($medw) = median(@{$LADCP{ENSEMBLE}[$ens]->{W}}); |
159 my($medw) = median(@{$LADCP{ENSEMBLE}[$ens]->{W}}); |
159 my($madw) = mad2($medw,@{$LADCP{ENSEMBLE}[$ens]->{W}}); |
160 my($madw) = mad2($medw,@{$LADCP{ENSEMBLE}[$ens]->{W}}); |
160 |
161 |
161 my($nrm) = 0; |
162 my($nrm) = 0; |
162 for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) { |
163 for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) { |
163 next unless defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]); |
164 next unless defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]); |
164 next if (abs($LADCP{ENSEMBLE}[$ens]->{W}[$bin]-$medw) <= $DE_outliers_mad_limit*$madw); |
165 next if (abs($LADCP{ENSEMBLE}[$ens]->{W}[$bin]-$medw) <= $lim*$madw); |
165 undef($LADCP{ENSEMBLE}[$ens]->{W}[$bin]); |
166 undef($LADCP{ENSEMBLE}[$ens]->{W}[$bin]); |
166 $nrm++ if ($bin>=$LADCP_firstBin-1 && $bin<=$LADCP_lastBin-1); |
167 $nrm++ if ($bin>=$LADCP_firstBin-1 && $bin<=$LADCP_lastBin-1); |
167 } |
168 } |
168 return $nrm; |
169 return $nrm; |
169 } |
170 } |
170 |
171 |
171 #====================================================================== |
172 #====================================================================== |
172 # $edited = editTruncRange($ens,$nbins) |
173 # $removed = editTruncRange($ens,$nbins) |
173 # |
174 # |
174 # NOTES: |
175 # NOTES: |
175 # - call after Earth vels have been calculated |
176 # - call after Earth vels have been calculated |
176 #====================================================================== |
177 #====================================================================== |
177 |
178 |
187 } |
188 } |
188 return $nrm; |
189 return $nrm; |
189 } |
190 } |
190 |
191 |
191 #====================================================================== |
192 #====================================================================== |
192 # $edited = editFalsePositives($ens,$nbins) |
193 # $removed = editFarBins($ens,$first_bad_bin) |
193 # |
194 # |
194 # NOTES: |
195 # NOTES: |
195 # - call after Earth vels have been calculated |
196 # - call after Earth vels have been calculated |
196 # - "false positives" are filtered in 2 stages: |
197 # - remove data from far bins |
197 # 1) invalidate any valid velocity bracketed by invalid ones |
198 # - only bins in valid range are considered here, because |
198 # 2) invalidate any remaining valid velocity following gap of |
199 # $per_bin_nsamp is only defined for those |
199 # length >= $FP_BAD_GAP; initial gap is not counted as such |
200 #====================================================================== |
200 #====================================================================== |
201 |
201 |
202 sub editFarBins($$) |
202 sub editFalsePositives($) |
203 { |
203 { |
204 my($ens,$first_bad_bin) = @_; |
204 my($ens) = @_; |
205 |
205 |
206 my($nrm) = 0; |
206 my($nrm) = 0; |
207 for (my($bin)=$first_bad_bin; $bin<=$LADCP_lastBin-1; $bin++) { |
207 for (my($bin)=1; $bin<$LADCP{N_BINS}; $bin++) { |
208 next unless defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]); |
208 next if defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin-1]) |
209 undef($LADCP{ENSEMBLE}[$ens]->{W}[$bin]); |
209 || !defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]) |
210 $nrm++; |
210 || defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin+1]); |
211 } |
211 undef($LADCP{ENSEMBLE}[$ens]->{W}[$bin]); |
|
212 $nrm++ if ($bin>=$LADCP_firstBin-1 && $bin<=$LADCP_lastBin-1); |
|
213 } |
|
214 my($s) = 9; # FINITE STATE MACHINE |
|
215 for (my($bin)=0; $bin<$LADCP{N_BINS}; $bin++) { |
|
216 if ($s == 9) { # skip initial gap |
|
217 $s = 0 if defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]); |
|
218 } elsif ($s == $DE_falsepositives_max_gap) { # gap too long => delete |
|
219 next unless defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]); |
|
220 undef($LADCP{ENSEMBLE}[$ens]->{W}[$bin]); |
|
221 $nrm++ if ($bin>=$LADCP_firstBin-1 && $bin<=$LADCP_lastBin-1); |
|
222 } else { # short-enough gap |
|
223 $s = defined($LADCP{ENSEMBLE}[$ens]->{W}[$bin]) ? 0 : $s+1; |
|
224 } |
|
225 } |
|
226 return $nrm; |
212 return $nrm; |
227 } |
213 } |
228 |
214 |
229 #====================================================================== |
215 #====================================================================== |
230 # ($nvrm,$nerm) = editSideLobes($fromEns,$toEns,$range) |
216 # ($nvrm,$nerm) = editSideLobes($fromEns,$toEns,$range) |