Commit 5ea52c08 authored by megmillhouse's avatar megmillhouse

Add option to handle injection list in hyphenated form

parent 0cdde70e
......@@ -455,9 +455,13 @@ 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)
list_of_times = [t.trigger_time for t in self.triggers]
print(list_of_times)
# for t in self.triggers:
# print(t.trigger_time)
elif injection_file is not None:
# Create trigger list from sim* LIGOLW-XML table
......@@ -470,7 +474,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
......@@ -489,9 +493,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')
......@@ -530,11 +532,22 @@ class triggerList:
BW_chainLength = file_len(filename)
# User specified injection indices
if cp.has_option('bayeswave_options','BW-internal-events'):
events=cp.get('bayeswave_options', 'BW-internal-events')
# Add option for doing deterministic BW injections
if cp.has_option('bayeswave_options','BW-internal-all'):
BW_events = range(0,BW_chainLength)
if events!='all':
BW_events=list(hyphen_range(events))
print(BW_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:
......@@ -542,10 +555,29 @@ class triggerList:
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
......
......@@ -429,6 +429,7 @@ 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)
......@@ -436,6 +437,7 @@ if cp.has_option('bayeswave_options','BW-inject'):
# Perform internal injections drawn from the signal or glitch model
# 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:
......
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