Commit 485d9e5e authored by James Clark's avatar James Clark

Merge branch 'update-for-internal-injections' into 'master'

Update to bayeswave_pipe for internal injections

See merge request !188
parents baed3f57 ff8eb86d
Pipeline #159265 passed with stages
in 1 minute and 59 seconds
......@@ -449,7 +449,7 @@ class triggerList:
for gps_time in gps_times:
self.triggers.append(eventTrigger(cp, trigger_time=gps_time))
elif trigger_file is not None:
elif trigger_file is not None and not internal_injections:
# Create trigger list from ascii file
self.triggers = self.parse_trigger_list(cp, trigger_file)
......@@ -464,7 +464,7 @@ class triggerList:
elif internal_injections:
# Set up || runs to sample from the prior
self.triggers = self.build_internal_injections(cp, gps_times)
self.triggers = self.build_internal_injections(cp, gps_times, trigger_file)
elif graceIDs is not None:
# Create trigger list from graceDB queries
......@@ -483,9 +483,7 @@ class triggerList:
return triggers
def build_internal_injections(self, cp, gps_time):
BW_Nsamples = cp.getint('bayeswave_options', 'BW-Nsamples')
def build_internal_injections(self, cp, gps_time=None, trigger_file=None):
# Determine chain length
injtype=cp.get('bayeswave_options', 'BW-inject')
......@@ -524,17 +522,51 @@ class triggerList:
BW_chainLength = file_len(filename)
try:
BW_seed = cp.getint('bayeswave_options', 'BW-seed')
except:
BW_seed = None
# User specified injection indices
if cp.has_option('bayeswave_options','BW-internal-events'):
events=cp.get('bayeswave_options', 'BW-internal-events')
random.seed(BW_seed)
BW_events = random.sample(xrange(0,BW_chainLength), BW_Nsamples)
if events!='all':
BW_events=list(hyphen_range(events))
else:
BW_events=range(0,BW_chainLength)
else:
try:
BW_Nsamples = cp.getint('bayeswave_options', 'BW-Nsamples')
except:
print("Error: must specify either BW-Nsamples or BW-internal-events.")
sys.exit(1)
try:
BW_seed = cp.getint('bayeswave_options', 'BW-seed')
except:
BW_seed = None
random.seed(BW_seed)
BW_events = random.sample(xrange(0,BW_chainLength), BW_Nsamples)
if trigger_file is not None: # injecting into specific GPS times from a list
print("Injecting int gps times specified by trigger file.")
trigger_data = np.loadtxt(trigger_file, ndmin=2)
nrows, ncols = trigger_data.shape
if ncols==1:
trig_times = []
for i in xrange(nrows):
trig_times.append(trigger_data[i])
else:
print("Warning: GPS file has more than one column. Using first column to set GPS times.")
elif gps_time is not None: # Use a single GPS time for injections
# A little bit of a hack here, but it's the most straightforward thing I could think of:
# For injections without a trigger list of GPS times, cope the single gps time to be used into a list.
trig_times = [gps_time for ii in range(BW_chainLength)]
else:
print("Could not find GPS time for BW internal injections.")
sys.exit(1)
triggers=[]
for BW_event in BW_events:
triggers.append(eventTrigger(cp, trigger_time=gps_time,
triggers.append(eventTrigger(cp, trigger_time=trig_times[BW_event],
BW_event=BW_event))
return triggers
......
......@@ -38,6 +38,7 @@ import numpy as np
from glue import pipeline
from lalapps import inspiralutils
from ligo import segments
......@@ -426,16 +427,23 @@ if injfile is not None:
trigger_list = pipe_utils.triggerList(cp, injection_file=injfilename)
if cp.has_option('bayeswave_options','BW-inject'):
print("Found internal injection.")
# Check the option is valid:
if cp.get('bayeswave_options','BW-inject') not in ['signal','glitch']:
print("Error: BW-inject must be in ", ['signal','glitch'], file=sys.stderr)
sys.exit(1)
# Perform internal injections drawn from the signal or glitch model
if opts.trigger_time is None:
opts.trigger_time=1126259462.392
print("Setting trigger time to %f"%opts.trigger_time, file=sys.stdout)
trigger_list = pipe_utils.triggerList(cp, gps_times=opts.trigger_time,
internal_injections=True)
# Check if there's a defined trigger list of GPS times
if opts.trigger_list is not None:
print("Found trigger list")
trigger_list = pipe_utils.triggerList(cp, trigger_file=opts.trigger_list,
internal_injections=True)
else:
if opts.trigger_time is None:
opts.trigger_time=1126259462.392
print("Setting trigger time to %f"%opts.trigger_time, file=sys.stdout)
trigger_list = pipe_utils.triggerList(cp, gps_times=opts.trigger_time,
internal_injections=True)
#
# GraceDB support
......
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