Commit 6692a424 authored by Kipp Cannon's avatar Kipp Cannon Committed by Patrick Godwin

gstlal_inspiral_compress_ranking_stat: fix compress logic

- wasn't doing what was intended.
parent e9ddc514
Pipeline #65277 passed with stages
in 24 minutes and 7 seconds
...@@ -54,7 +54,7 @@ def parse_command_line(): ...@@ -54,7 +54,7 @@ def parse_command_line():
parser = OptionParser( parser = OptionParser(
version = "Name: %%prog\n%s" % "" # FIXME version = "Name: %%prog\n%s" % "" # FIXME
) )
parser.add_option("-t", "--threshold", type = "float", default = 0.01, help = "Only keep horizon distance values that differ by this much, fractionally, from their neighbours (default = 0.01).") parser.add_option("-t", "--threshold", type = "float", default = 0.03, help = "Only keep horizon distance values that differ by this much, fractionally, from their neighbours (default = 0.03).")
parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose.") parser.add_option("-v", "--verbose", action = "store_true", help = "Be verbose.")
options, filenames = parser.parse_args() options, filenames = parser.parse_args()
...@@ -115,34 +115,32 @@ for filename in filenames: ...@@ -115,34 +115,32 @@ for filename in filenames:
abs_ln_thresh = math.log1p(options.threshold) abs_ln_thresh = math.log1p(options.threshold)
for instrument, horizon_history in list(rankingstat.numerator.horizon_history.items()): for instrument, horizon_history in list(rankingstat.numerator.horizon_history.items()):
# GPS times # GPS time / distance pairs
keys = horizon_history.keys() items = horizon_history.items()
# distances
values = horizon_history.values() # compress array
j = 1
# indexes of distances that are non-zero and differ for i in range(1, len(items) - 1):
# fractionally from both neighbours by less than the values = items[j - 1][1], items[i][1], items[i + 1][1]
# selected threshold. always keep the first and last # remove distances that are non-zero and differ
# values # fractionally from both neighbours by less than
removals = [i for i in range(2, len(values) - 1) if values[i - 1] > 0. and values[i] > 0. and values[i + 1] > 0. and abs(math.log(values[i] / values[i - 1])) < abs_ln_thresh and abs(math.log(values[i] / values[i + 1])) < abs_ln_thresh] # the selected threshold. always keep the first
# and last values
# compress arrays if values[0] > 0. and values[1] > 0. and values[2] > 0. and abs(math.log(values[1] / values[0])) < abs_ln_thresh and abs(math.log(values[1] / values[2])) < abs_ln_thresh:
j = k = 0 continue
for i in range(len(keys)): # remove distances that are 0 and surrounded by 0
if k < len(removals) and i == removals[k]: # on both sides (basically the same as the last
k += 1 # test, but we can't take log(0)).
else: if values == (0., 0., 0.):
keys[j] = keys[i] continue
values[j] = values[i] items[j] = items[i]
j += 1 j += 1
assert (i + 1) - j == len(removals), "%d %d %d" % (i, j, len(removals)) del items[j:]
del keys[j:]
del values[j:]
if options.verbose: if options.verbose:
print >>sys.stderr, "\"%s\": %s horizon history reduced to %.3g%% of original size" % (filename, instrument, 100. * j / (i + 1.)) print >>sys.stderr, "\"%s\": %s horizon history reduced to %.3g%% of original size" % (filename, instrument, 100. * j / (i + 1.))
# replace # replace
rankingstat.numerator.horizon_history[instrument] = type(horizon_history)(zip(keys, values)) rankingstat.numerator.horizon_history[instrument] = type(horizon_history)(items)
# #
# re-insert into XML tree # re-insert into XML tree
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment