Commit c7a2b229 authored by Ryan Michael Magee's avatar Ryan Michael Magee

inspiral_lr.py: enabled multiple dtdphi pdf capabilities

parent 5c1eeeb6
Pipeline #72424 passed with stages
in 19 minutes and 28 seconds
......@@ -293,9 +293,9 @@ class LnLRDensity(snglcoinc.LnLRDensity):
class LnSignalDensity(LnLRDensity):
def __init__(self, *args, **kwargs):
population_model_file = kwargs.pop("population_model_file", None)
dtdphi_file = kwargs.pop("dtdphi_file", None)
self.horizon_factors = kwargs.pop("horizon_factors", None)
super(LnSignalDensity, self).__init__(*args, **kwargs)
# install SNR, chi^2 PDF (one for all instruments)
self.densities = {
"snr_chi": inspiral_extrinsics.NumeratorSNRCHIPDF(self.snr_chi_binning)
......@@ -305,11 +305,12 @@ class LnSignalDensity(LnLRDensity):
# network
self.horizon_history = horizonhistory.HorizonHistories((instrument, horizonhistory.NearestLeafTree()) for instrument in self.instruments)
self.population_model_file = population_model_file
self.dtdphi_file = dtdphi_file
# source population model
# FIXME: introduce a mechanism for selecting the file
self.population_model = inspiral_intrinsics.SourcePopulationModel(self.template_ids, filename = self.population_model_file)
self.InspiralExtrinsics = inspiral_extrinsics.InspiralExtrinsics(self.min_instruments)
if self.dtdphi_file is not None:
self.InspiralExtrinsics = inspiral_extrinsics.InspiralExtrinsics(self.min_instruments, self.dtdphi_file)
def set_horizon_factors(self, horizon_factors):
self.horizon_factors = horizon_factors
......@@ -382,6 +383,10 @@ class LnSignalDensity(LnLRDensity):
raise ValueError("incompatible mass model file names")
if self.population_model_file is None and other.population_model_file is not None:
self.population_model_file = other.population_model_file
if self.dtdphi_file is not None and other.dtdphi_file is not None and other.dtdphi_file != self.dtdphi_file:
raise ValueError("incompatible dtdphi files")
if self.dtdphi_file is None and other.dtdphi_file is not None:
self.dtdphi_file = other.dtdphi_file
if self.horizon_factors is not None and other.horizon_factors is not None and other.horizon_factors != self.horizon_factors:
# require that the horizon factors be the same within 1%
for k in self.horizon_factors:
......@@ -399,6 +404,7 @@ class LnSignalDensity(LnLRDensity):
new = super(LnSignalDensity, self).copy()
new.horizon_history = self.horizon_history.copy()
new.population_model_file = self.population_model_file
new.dtdphi_file = self.dtdphi_file
# okay to use references because read-only data
new.population_model = self.population_model
new.InspiralExtrinsics = self.InspiralExtrinsics
......@@ -547,6 +553,7 @@ class LnSignalDensity(LnLRDensity):
xml.appendChild(self.horizon_history.to_xml(u"horizon_history"))
xml.appendChild(ligolw_param.Param.from_pyvalue(u"population_model_file", self.population_model_file))
xml.appendChild(ligolw_param.Param.from_pyvalue(u"horizon_factors", json.dumps(self.horizon_factors) if self.horizon_factors is not None else None))
xml.appendChild(ligolw_param.Param.from_pyvalue(u"dtdphi_file", self.dtdphi_file))
return xml
@classmethod
......@@ -555,6 +562,7 @@ class LnSignalDensity(LnLRDensity):
self = super(LnSignalDensity, cls).from_xml(xml, name)
self.horizon_history = horizonhistory.HorizonHistories.from_xml(xml, u"horizon_history")
self.population_model_file = ligolw_param.get_pyvalue(xml, u"population_model_file")
self.dtdphi_file = ligolw_param.get_pyvalue(xml, u"dtdphi_file")
self.horizon_factors = ligolw_param.get_pyvalue(xml, u"horizon_factors")
if self.horizon_factors is not None:
# FIXME, how do we properly decode the json, I assume something in ligolw can do this?
......@@ -563,7 +571,8 @@ class LnSignalDensity(LnLRDensity):
self.horizon_factors = dict((int(k), v) for k, v in self.horizon_factors.items())
assert set(self.template_ids) == set(self.horizon_factors)
self.population_model = inspiral_intrinsics.SourcePopulationModel(self.template_ids, filename = self.population_model_file)
self.InspiralExtrinsics = inspiral_extrinsics.InspiralExtrinsics(self.min_instruments)
if self.dtdphi_file is not None:
self.InspiralExtrinsics = inspiral_extrinsics.InspiralExtrinsics(self.min_instruments, self.dtdphi_file)
return self
......
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