Skip to content
Snippets Groups Projects
Commit aa48073c authored by Duncan Meacher's avatar Duncan Meacher
Browse files

gstlal_inspiral_split_injections: Added single output file and output tag options

parent 592eb27d
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -90,8 +90,10 @@ def parse_command_line():
parser = OptionParser()
parser.add_option("--target-injection-rate", "-r", metavar = "s^-1", type = "float", default = 0.1, help = "Desired injection rate of output files (default: 0.01)")
parser.add_option("--output-tag", "-o", metavar = "filename", default = "split_injections", help = "Base of output file name (default: split_injections)")
parser.add_option("--injection-rate-tolerance", type = "float", default = 0.1, help = "Acceptable tolerance for target injection rate, files will be written to disk once a splitting has been found such that the injection rate is target-injection-rate +- (injection-rate-tolerance*target-injection-rate) (default: 0.1)")
parser.add_option("--generate-inj-string-only", action = "store_true", help = "Do not combine files, generate an injection string specifying which chirp mass bounds to use to search for the provided injection files")
parser.add_option("--single-output", action = "store_true", help = "Produce a single output file containing all injections")
# FIXME Add option checking so num-output and target-injection-rate cannot both be provided
......@@ -132,26 +134,30 @@ else:
avg_inj_rate = numpy.inf
i=0
while avg_inj_rate > target_inj_rate_interval[1]:
if options.single_output:
split_keys = [siminspiralmchirps]
num_output += 1
split_keys = numpy.array_split(siminspiralmchirps, num_output)
avg_dts = []
for i, keys in enumerate(split_keys):
sorted_times = numpy.sort([siminspiralmap[tuple(k for k in key)][0] for key in keys])
if len(sorted_times) < 2:
raise ValueError("files need to be split too finely to hit target injection rate, try increasing target rate or tolerance (last splitting attempt: %d files)" % num_output)
avg_dts.append((sorted_times[1:] - sorted_times[:-1]).mean())
avg_inj_rate = 1/numpy.mean(avg_dts)
else:
while avg_inj_rate > target_inj_rate_interval[1]:
num_output += 1
split_keys = numpy.array_split(siminspiralmchirps, num_output)
avg_dts = []
for i, keys in enumerate(split_keys):
sorted_times = numpy.sort([siminspiralmap[tuple(k for k in key)][0] for key in keys])
if len(sorted_times) < 2:
raise ValueError("files need to be split too finely to hit target injection rate, try increasing target rate or tolerance (last splitting attempt: %d files)" % num_output)
avg_dts.append((sorted_times[1:] - sorted_times[:-1]).mean())
avg_inj_rate = 1/numpy.mean(avg_dts)
if avg_inj_rate < target_inj_rate_interval[0]:
print avg_inj_rate, num_output
# the average injection rate cannot increase with more splittings, thus we can't hit this injection rate interval
raise ValueError("target injection rate not attainable, either increase the tolerance or decrease the target rate")
if avg_inj_rate < target_inj_rate_interval[0]:
print avg_inj_rate, num_output
# the average injection rate cannot increase with more splittings, thus we can't hit this injection rate interval
raise ValueError("target injection rate not attainable, either increase the tolerance or decrease the target rate")
for i, keys in enumerate(split_keys):
create_split_injection(processmap, process_params_dict, [siminspiralmap[tuple(k for k in key)] for key in keys], keys[0][0], keys[-1][0], 'split_injections_%04d.xml' % i, options)
mchirp_str += mchirp_injection_str(keys, 'split_injections_%04d.xml' % i)
create_split_injection(processmap, process_params_dict, [siminspiralmap[tuple(k for k in key)] for key in keys], keys[0][0], keys[-1][0], "%s_%04d.xml" %( options.output_tag, i) if not options.single_output else "%s.xml" % options.output_tag, options)
mchirp_str += mchirp_injection_str(keys, "%s_%04d.xml" %( options.output_tag, i) if not options.single_output else "%s.xml" % options.output_tag)
print 'MCHIRP_INJECTIONS := %s' % mchirp_str[:-1]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment