From aa48073cdfad46571a8486a4b9723e785ba342aa Mon Sep 17 00:00:00 2001 From: Duncan Meacher <duncan.meacher@ligo.org> Date: Thu, 19 Jul 2018 10:01:49 -0700 Subject: [PATCH] gstlal_inspiral_split_injections: Added single output file and output tag options --- .../bin/gstlal_inspiral_split_injections | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/gstlal-inspiral/bin/gstlal_inspiral_split_injections b/gstlal-inspiral/bin/gstlal_inspiral_split_injections index d2a626bd27..c2fc46d55f 100755 --- a/gstlal-inspiral/bin/gstlal_inspiral_split_injections +++ b/gstlal-inspiral/bin/gstlal_inspiral_split_injections @@ -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] -- GitLab