Skip to content

Commit

Permalink
multi-ifo changes to pycbc_page_segtable (#2519)
Browse files Browse the repository at this point in the history
* multi-ifo changes to pycbc_page_segtable

* Updated to use itertools module, and deal with default ifos value more pythonically

* kick Travis

* fix typo to sort comp segs issue

* removing commented-out lines, formatting fixes

* PEP8 again
  • Loading branch information
GarethCabournDavies authored and tdent committed Feb 27, 2019
1 parent 27e95bd commit 6108456
Showing 1 changed file with 48 additions and 35 deletions.
83 changes: 48 additions & 35 deletions bin/hdfcoinc/pycbc_page_segtable
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ from pycbc.events.veto import get_segment_definer_comments
from pycbc.results import save_fig_with_metadata
from pycbc.workflow import SegFile
import pycbc.version
import itertools

def powerset_ifos(ifo_set):
combo_set = []
for n_ifos in range(1, len(ifo_set) + 1):
combo_set += itertools.combinations(ifo_set, n_ifos)
return combo_set

# parse command line
parser = argparse.ArgumentParser()
Expand All @@ -46,22 +53,25 @@ parser.add_argument('--title-text', type=str, required=False,
help='Additional text to append to title.')
parser.add_argument('--output-file', type=str,
help='Path of the output HTML file.')
parser.add_argument('--ifos', nargs='+', default=['H1', 'L1'],
help='List of IFOs: default H1, L1.')
opts = parser.parse_args()

# setup log
logging.basicConfig(format='%(asctime)s:%(levelname)s : %(message)s',
level=logging.INFO,datefmt='%I:%M:%S')

# create list of combinations of detectors
ifo_combinations = powerset_ifos(opts.ifos)

# set column names
columns = (('Name', []),
('H1 Time (s)', []),
('L1 Time (s)', []),
('H1L1 Time (s)', []),
)
caption = "This table shows the cumulative amount of time for each segment. Shown are:"
columns = (('Name', []),)
# columns for detectors and combinations
for combo in ifo_combinations:
det_combo_string = ''.join(combo).upper()
columns += (('%s Time (s)' % det_combo_string, []),)

# FIXME: set IFO list
ifos = ['H1', 'L1']
caption = "This table shows the cumulative amount of time for each segment. Shown are:"

# loop over segment files from command line
seg_dict = {}
Expand All @@ -86,7 +96,7 @@ for segment_name in opts.segment_names:
comp_segs = segments.segmentlistdict({})

# loop over IFOs
for ifo in ifos:
for ifo in opts.ifos:

# make an empty list for each IFO
base_segs[ifo] = segments.segmentlist([])
Expand Down Expand Up @@ -125,33 +135,36 @@ for segment_name in opts.segment_names:
#if comment_dict[key] != None:
# caption += " ("+comment_dict[key]+")"

# get length of time of single-IFO segments in seconds
if len(names) > 1:
h1_len = abs( ( base_segs['H1'].coalesce() & comp_segs["H1"].coalesce() ).coalesce() )
l1_len = abs( ( base_segs['L1'].coalesce() & comp_segs["L1"].coalesce() ).coalesce() )
else:
h1_len = abs( base_segs['H1'].coalesce() )
l1_len = abs( base_segs['L1'].coalesce() )

# find the AND of H1 and L1 time
h1l1_base_segs = base_segs["H1"].coalesce() & base_segs["L1"].coalesce()
h1l1_base_segs.coalesce()

# find all the time that should overlap
h1l1_comp_segs = comp_segs["H1"].coalesce() + comp_segs["L1"].coalesce()
h1l1_comp_segs.coalesce()

# get length of time in coincident H1L1 segments in seconds
if len(names) > 1:
h1l1_len = abs( (h1l1_base_segs & h1l1_comp_segs).coalesce() )
else:
h1l1_len = abs( h1l1_base_segs.coalesce() )

# put values into columns
# set up dictionary of length of time of single-ifo segments in seconds
ifo_len = {}
for ifo in opts.ifos:
if len(names) > 1:
ifo_len[ifo] = abs( ( base_segs[ifo].coalesce() & comp_segs[ifo].coalesce() ).coalesce() )
else:
ifo_len[ifo] = abs( base_segs[ifo].coalesce() )

columns[0][1].append(segment_name)
columns[1][1].append(float(h1_len))
columns[2][1].append(float(l1_len))
columns[3][1].append(float(h1l1_len))
counter = 1
for combo in ifo_combinations:
first_ifo = True
for ifo in combo:
if first_ifo:
combo_base_segs = base_segs[ifo].coalesce()
combo_comp_segs = comp_segs[ifo].coalesce()
first_ifo = False
else:
for ifo in combo:
combo_base_segs = combo_base_segs.coalesce() & base_segs[ifo].coalesce()
combo_comp_segs = combo_comp_segs.coalesce() + comp_segs[ifo].coalesce()

combo_base_segs.coalesce()
combo_comp_segs.coalesce()
if len(names) > 1:
combo_len = abs( (combo_base_segs.coalesce() & combo_comp_segs.coalesce() ).coalesce() )
else:
combo_len = abs( combo_base_segs.coalesce() )
columns[counter][1].append(float(combo_len))
counter += 1

# cast columns into arrays
keys = [numpy.array(key, dtype=type(key[0])) for key,_ in columns]
Expand Down

0 comments on commit 6108456

Please # to comment.