Skip to content
Snippets Groups Projects
Commit bd612d1c authored by Shio Sakon's avatar Shio Sakon
Browse files

gstlal_inspiral_create_prior_diststats: changed order of for-loop, used...

gstlal_inspiral_create_prior_diststats: changed order of for-loop, used CacheEntry for file name, inspiral_lr.py: made local_mean_horizon_distance simpler
parent cdad0e3f
No related branches found
No related tags found
2 merge requests!309fix to MR 301,!301fix bug where horizon factor is stored only for 1 ifo instead of individual ifos
Pipeline #455391 passed with warnings
......@@ -31,7 +31,6 @@
from optparse import OptionParser
import numpy
import scipy
import os
from ligo.lw import ligolw
from ligo.lw import lsctables
......@@ -39,7 +38,7 @@ from ligo.lw import array as ligolw_array
from ligo.lw import param as ligolw_param
from ligo.lw import utils as ligolw_utils
from ligo.lw.utils import process as ligolw_process
from lal.utils import CacheEntry
from gstlal import far
from gstlal import svd_bank
......@@ -114,9 +113,9 @@ def parse_command_line():
horizon_factors = {}
bandwidths = []
if options.svd_file[0].endswith("xml") or options.svd_file[0].endswith("xml.gz"):
for n, svd_file in enumerate(options.svd_file):
svd_ifo = os.path.splitext(os.path.splitext(os.path.basename(svd_file))[0])[0].split('-')[0]
for n, svd_file in enumerate(options.svd_file):
if svd_file.endswith("xml") or svd_file.endswith("xml.gz"):
svd_ifo = CacheEntry.from_T050017(svd_file).observatory
horizon_factors_ifo = {}
for n, bank in enumerate(svd_bank.read_banks(svd_file, contenthandler = LIGOLWContentHandler, verbose = options.verbose)):
if bank.bank_type != "signal_model":
......@@ -128,20 +127,20 @@ def parse_command_line():
bandwidths += [templates.bandwidth(row.mass1, row.mass2, row.spin1z, row.spin2z, f_min = 10.0, f_max = row.f_final, delta_f = 0.25, psd = psd[ifo]) for row in bank.sngl_inspiral_table]
horizon_factors_ifo.update(bank.horizon_factors)
horizon_factors.update({svd_ifo: horizon_factors_ifo})
elif options.svd_file[0].endswith(".json"):
assert options.svd_bin is not None
import json
horizon_factors_ifo = {}
for n, svd_file in enumerate(options.svd_file):
svd_ifo = os.path.splitext(os.path.splitext(os.path.basename(svd_file))[0])[0].split('-')[0]
with open(svd_file) as f:
manifest = json.loads(f.read())
bandwidths = [manifest[svd_bin]["min_bw"], manifest[svd_bin]["max_bw"]]
horizon_factors_ifo.update(manifest[svd_bin]["horizon_factors"])
template_ids = [int(template_id) for template_id in list(manifest[svd_bin]["horizon_factors"].keys())]
horizon_factors.update({svd_ifo: horizon_factors_ifo})
else:
raise ValueError("svd file cannot be read")
elif svd_file.endswith(".json"):
assert options.svd_bin is not None
import json
horizon_factors_ifo = {}
for n, svd_file in enumerate(svd_file):
svd_ifo = CacheEntry.from_T050017(svd_file).observatory
with open(svd_file) as f:
manifest = json.loads(f.read())
bandwidths = [manifest[svd_bin]["min_bw"], manifest[svd_bin]["max_bw"]]
horizon_factors_ifo.update(manifest[svd_bin]["horizon_factors"])
template_ids = [int(template_id) for template_id in list(manifest[svd_bin]["horizon_factors"].keys())]
horizon_factors.update({svd_ifo: horizon_factors_ifo})
else:
raise ValueError("svd file cannot be read")
if options.df == "bandwidth":
# don't let the bandwidth get too small
......
......@@ -568,7 +568,7 @@ class LnSignalDensity(LnLRDensity):
# explicitly.
horizon_factor = {}
for instrument in segs:
horizon_factor.update({instrument: 1.}) if template_id is None else horizon_factor.update({instrument: self.horizon_factors[instrument][template_id]})
horizon_factor[instrument] = 1. if template_id is None else self.horizon_factors[instrument][template_id]
return dict((instrument, (self.horizon_history[instrument].functional_integral(map(float, segs[seg]), lambda D: D**3.) / float(abs(segs[seg])))**(1./3.) * horizon_factor[instrument]) for instrument, seg in zip(horizon_factor, segs))
def add_signal_model(self, prefactors_range = (0.001, 0.30), df = 100, inv_snr_pow = 4., verbose = False):
......
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