Skip to content

Commit

Permalink
Generalize sngl_minifollowups (gwastro#1368)
Browse files Browse the repository at this point in the history
* Generalize single mini-followups

* Fixing previous

* Fix bug

* One too many spaces
  • Loading branch information
spxiwh authored and ahnitz committed Jan 13, 2017
1 parent 36bbb9a commit e1cf292
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
15 changes: 14 additions & 1 deletion bin/minifollowups/pycbc_sngl_minifollowup
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
""" Followup foreground events
"""
import os, sys, argparse, logging, h5py
import numpy
from glue.ligolw import lsctables, table
from glue.ligolw import utils as ligolw_utils
from pycbc.results import layout
Expand Down Expand Up @@ -66,6 +67,9 @@ parser.add_argument('--non-coinc-time-only', default=False,
help="If given remove (veto) single-detector triggers "
"that occur during a time when at least one other "
"instrument is taking science data.")
parser.add_argument('--minimum-duration', default=None, type=float,
help="If given only consider single-detector triggers "
"with template duration larger than this.")
parser.add_argument('--output-map')
parser.add_argument('--output-file')
parser.add_argument('--tags', nargs='+', default=[])
Expand Down Expand Up @@ -95,7 +99,7 @@ insp_data_seglists = select_segments_by_definer\
(args.inspiral_segments, segment_name=args.inspiral_data_read_name,
ifo=args.instrument)

num_events = int(workflow.cp.get_opt_tags('workflow-minifollowups',
num_events = int(workflow.cp.get_opt_tags('workflow-sngl_minifollowups',
'num-sngl-events', ''))

trigs = hdf.SingleDetTriggers(args.single_detector_file, args.bank_file,
Expand All @@ -117,6 +121,15 @@ if args.non_coinc_time_only:
trigs.end_time, [args.inspiral_segments],
ifo=ifo, segment_name=args.inspiral_data_analyzed_name)
trigs.mask = trigs.mask[curr_veto_mask]
if args.minimum_duration is not None:
durations = trigs.template_duration
lgc_mask = durations > args.minimum_duration
if trigs.mask.dtype == 'bool':
orig_indices = trigs.mask.nonzero()[0][lgc_mask]
trigs.mask = numpy.in1d(numpy.arange(len(trigs.mask)), orig_indices,
assume_unique=True)
else:
trigs.mask = trigs.mask[lgc_mask]

if len(trigs.snr) == 0:
# There are no triggers, make no-op job and exit
Expand Down
32 changes: 18 additions & 14 deletions bin/workflows/pycbc_make_coinc_search_workflow
Original file line number Diff line number Diff line change
Expand Up @@ -354,22 +354,26 @@ for bin_file in bin_files:
'daxes', currdir, tags=bin_file.tags)

# Also run minifollowups on loudest sngl detector events
excl_subsecs = set([])

for insp_file in full_insps:
for tag in insp_file.tags:
excl_subsecs.add(tag)

for insp_file in full_insps:
curr_ifo = insp_file.ifo
currdir = rdir['single_triggers/%s_loudest_all_time' %(curr_ifo,)]
wf.setup_single_det_minifollowups(workflow, insp_file, hdfbank[0],
insp_files_seg_file, data_analysed_name,
trig_generated_name, 'daxes', currdir,
veto_file=censored_veto,
veto_segment_name='closed_box',
tags=insp_file.tags)
currdir = rdir['single_triggers/%s_loudest_noncoinc_time' %(curr_ifo,)]
wf.setup_single_det_minifollowups(workflow, insp_file, hdfbank[0],
insp_files_seg_file, data_analysed_name,
trig_generated_name, 'daxes', currdir,
veto_file=censored_veto,
veto_segment_name='closed_box',
tags=insp_file.tags+['noncoinconly'])
for subsec in workflow.cp.get_subsections('workflow-sngl_minifollowups'):
if subsec in excl_subsecs:
continue
sec_name = 'workflow-sngl_minifollowups-{}'.format(subsec)
dir_str = workflow.cp.get(sec_name, 'section-header')
currdir = rdir['single_triggers/{}_{}'.format(curr_ifo, dir_str)]
wf.setup_single_det_minifollowups(workflow, insp_file, hdfbank[0],
insp_files_seg_file, data_analysed_name,
trig_generated_name, 'daxes', currdir,
veto_file=censored_veto,
veto_segment_name='closed_box',
tags=insp_file.tags + [subsec])

################## Setup segment / veto related plots #########################
# do plotting of segments / veto times
Expand Down
27 changes: 15 additions & 12 deletions pycbc/workflow/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,26 +357,29 @@ def interpolate_exe(self, testString):
def get_subsections(self, section_name):
""" Return a list of subsections for the given section name
"""
subsections = [sec for sec in self.sections() if sec.startswith(section_name + '-')]
# Keep only subsection names
subsections = [sec[len(section_name)+1:] for sec in self.sections()\
if sec.startswith(section_name + '-')]

for sec in subsections:
sp = sec.split('-')
# This is unusual, but a format [section-subsection-tag] is okay. Just
# check that [section-subsection] section exists. If not it is possible
# the user is trying to use an subsection name with '-' in it
if (len(sp) > 1) and not self.has_section('%s-%s' % (sp[0], sp[1])):
raise ValueError( "Workflow uses the '-' as a delimiter so this is"
"interpreted as section-subsection-tag. "
"While checking section %s, no section with "
"name %s-%s was found. "
"If you did not intend to use tags in an "
"'advanced user' manner, or do not understand what "
"this means, don't use dashes in section "
"names. So [injection-nsbhinj] is good. "
"[injection-nsbh-inj] is not." % (sec, sp[0], sp[1]))
if (len(sp) > 1) and not self.has_section('%s-%s' % (section_name,
sp[0])):
raise ValueError( "Workflow uses the '-' as a delimiter so "
"this is interpreted as section-subsection-tag. "
"While checking section %s, no section with "
"name %s-%s was found. "
"If you did not intend to use tags in an "
"'advanced user' manner, or do not understand what "
"this means, don't use dashes in section "
"names. So [injection-nsbhinj] is good. "
"[injection-nsbh-inj] is not." % (sec, sp[0], sp[1]))

if len(subsections) > 0:
return [sec.split('-')[1] for sec in subsections]
return [sec.split('-')[0] for sec in subsections]
elif self.has_section(section_name):
return ['']
else:
Expand Down
4 changes: 2 additions & 2 deletions pycbc/workflow/minifollowups.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def setup_single_det_minifollowups(workflow, single_trig_file, tmpltbank_file,
"""
logging.info('Entering minifollowups module')

if not workflow.cp.has_section('workflow-minifollowups'):
msg = 'There is no [workflow-minifollowups] section in '
if not workflow.cp.has_section('workflow-sngl_minifollowups'):
msg = 'There is no [workflow-sngl_minifollowups] section in '
msg += 'configuration file'
logging.info(msg)
logging.info('Leaving minifollowups')
Expand Down

0 comments on commit e1cf292

Please sign in to comment.