11
|
1 |
#======================================================================
|
|
2 |
# U T I L I T I E S / P O S T _ M E R G E _ T L _ C H E C K . P L
|
|
3 |
# doc: Wed Oct 12 10:23:58 2011
|
|
4 |
# dlm: Wed Oct 17 12:06:02 2012
|
|
5 |
# (c) 2011 A.M. Thurnherr
|
|
6 |
# uE-Info: 33 15 NIL 0 0 72 2 2 4 NIL ofnI
|
|
7 |
#======================================================================
|
|
8 |
|
|
9 |
# HISTORY:
|
|
10 |
# Oct 12, 2012: - created as an experimental time-lagging filter
|
|
11 |
# Oct 17, 2012: - turned into this utility
|
|
12 |
|
|
13 |
#----------------------------------------------------------------------
|
|
14 |
# This code is used to verify (or improve) time lagging
|
|
15 |
# - for each ensemble, a "narrow-band" time lagging is performed
|
|
16 |
# to determine the optimal scan offset
|
|
17 |
# - time-lag window is taken from 2nd value of -w
|
|
18 |
# - max search radius is hard-coded in $scan_offset_search_window
|
|
19 |
#----------------------------------------------------------------------
|
|
20 |
|
|
21 |
$post_merge_hook = sub { # arguments: firstGoodEns, lastGoodEns
|
|
22 |
my($fe,$le) = @_;
|
|
23 |
|
|
24 |
progress("Writing optimal lags for all ensembles to $data_subdir/$out_basename.TLcheck...\n");
|
|
25 |
|
|
26 |
my($scan_offset_search_window) = 10;
|
|
27 |
my($ew_hwidth) = # window half-width in ensembles
|
|
28 |
int($length_of_timelag_windows[1]/2 / $LADCP{MEAN_DT} + 0.5);
|
|
29 |
|
|
30 |
my(@mad,$nsamp);
|
|
31 |
|
|
32 |
@antsNewLayout = ('ensemble','best_scan_offset','mad');
|
|
33 |
open(STDOUT,">$data_subdir/$out_basename.TLcheck")
|
|
34 |
|| croak("$data_subdir/$out_basename.TLcheck: $!\n");
|
|
35 |
|
|
36 |
for (my($e)=$fe; $e<=$le; $e++) {
|
|
37 |
next unless numberp($LADCP{ENSEMBLE}[$e]->{CTD_DEPTH}); # skip non-valid
|
|
38 |
|
|
39 |
for (my($so)=-$scan_offset_search_window; $so<=$scan_offset_search_window; $so++) { # find narrowband best lag
|
|
40 |
$mad[$so + $scan_offset_search_window] = $nsamp = 0;
|
|
41 |
for (my($i)=max($fe,$e-$ew_hwidth); $i<=min($le,$e+$ew_hwidth); $i++) { # calc mad in window
|
|
42 |
next unless numberp($LADCP{ENSEMBLE}[$i]->{CTD_DEPTH});
|
|
43 |
$mad[$so + $scan_offset_search_window] +=
|
|
44 |
abs($LADCP{ENSEMBLE}[$i]->{REFLR_W} - $CTD{W}[$LADCP{ENSEMBLE}[$i]->{CTD_SCAN}+$so]);
|
|
45 |
$nsamp++;
|
|
46 |
} # for $i
|
|
47 |
if ($nsamp > 0) {
|
|
48 |
$mad[$so + $scan_offset_search_window] /= $nsamp;
|
|
49 |
} else {
|
|
50 |
$mad[$so + $scan_offset_search_window] = 9e99;
|
|
51 |
}
|
|
52 |
} # for $so
|
|
53 |
|
|
54 |
my($best_so) = min_i(@mad) - $scan_offset_search_window;
|
|
55 |
&antsOut($e,$best_so,$mad[$best_so + $scan_offset_search_window]);
|
|
56 |
|
|
57 |
}
|
|
58 |
|
|
59 |
&antsOut('EOF'); open(STDOUT,'>&2');
|
|
60 |
|
|
61 |
};
|
|
62 |
|
|
63 |
1;
|