Skip to content
Snippets Groups Projects
Commit c7a2b229 authored by Ryan Michael Magee's avatar Ryan Michael Magee
Browse files

inspiral_lr.py: enabled multiple dtdphi pdf capabilities

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