37from igwn_ligolw
import ligolw
38from igwn_ligolw
import lsctables
39from igwn_ligolw
import utils
as ligolw_utils
40from igwn_ligolw.utils
import process
as ligolw_process
41from igwn_ligolw.utils
import search_summary
as ligolw_search_summary
42from .
import snglcoinc
43from .SimBurstUtils
import MW_CENTER_J2000_RA_RAD, MW_CENTER_J2000_DEC_RAD
46__author__ =
"Kipp Cannon <kipp.cannon@ligo.org>"
47from .git_version
import date
as __date__
48from .git_version
import version
as __version__
63 for pair
in intertools.combinations(sorted(instruments), 2):
67 self.
densities[
"%s_%s_dt" % pair] = rate.BinnedLnDPF(rate.NDBins((rate.ATanBins(-dt, +dt, 12001), rate.LinearBins(0.0, 2 * math.pi, 61))))
68 self.
densities[
"%s_%s_dband" % pair] = rate.BinnedLnDPF(rate.NDBins((rate.LinearBins(-2.0, +2.0, 12001), rate.LinearBins(0.0, 2 * math.pi, 61))))
69 self.
densities[
"%s_%s_ddur" % pair] = rate.BinnedLnDPF(rate.NDBins((rate.LinearBins(-2.0, +2.0, 12001), rate.LinearBins(0.0, 2 * math.pi, 61))))
70 self.
densities[
"%s_%s_df" % pair] = rate.BinnedLnDPF(rate.NDBins((rate.LinearBins(-2.0, +2.0, 12001), rate.LinearBins(0.0, 2 * math.pi, 61))))
71 self.
densities[
"%s_%s_dh" % pair] = rate.BinnedLnDPF(rate.NDBins((rate.LinearBins(-2.0, +2.0, 12001), rate.LinearBins(0.0, 2 * math.pi, 61))))
76 except AttributeError:
79 return sum(interps[param](value)
for param, value
in params.items())
82 if type(self) != type(other)
or set(self.
densities) != set(other.densities):
83 raise TypeError(
"cannot add %s and %s" % (type(self), type(other)))
85 pdf += other.densities[key]
90 for param, value
in params.items():
91 self.
densities[param].count[value] += weight
96 new.densities[key] = pdf.copy()
104 rate.filter_array(pdf.array, rate.gaussian_window(11, 5))
109 xml = super(LnLRDensity, self).
to_xml(name)
110 instruments = set(key.split(
"_", 2)[0]
for key
in self.
densities if key.endswith(
"_dt"))
111 instruments |= set(key.split(
"_", 2)[1]
for key
in self.
densities if key.endswith(
"_dt"))
112 xml.appendChild(ligolw.Param.from_pyvalue(
"instruments", lsctables.instrumentsproperty.set(instruments)))
114 xml.appendChild(pdf.to_xml(key))
120 self = cls(lsctables.instrumentsproperty.get(ligolw.Param.get_param(xml,
"instruments").value))
122 self.
densities[key] = rate.BinnedLnPDF.from_xml(xml, key)
127 ligo_lw_name_suffix =
"excesspower_coincparamsdistributions"
135 if type(self) != type(other):
136 raise TypeError(other)
157 xml = [elem
for elem
in xml.getElementsByTagName(ligolw.LIGO_LW.tagName)
if elem.hasAttribute(
"Name")
and elem.Name == name]
159 raise ValueError(
"XML tree must contain exactly one %s element named %s" % (ligolw.LIGO_LW.tagName, name))
166 self.
numerator = LnLRDensity.from_xml(xml,
"numerator")
167 self.
denominator = LnLRDensity.from_xml(xml,
"denominator")
168 self.
candidates = LnLRDensity.from_xml(xml,
"candidates")
180 Convenience function to deserialize
181 CoincParamsDistributions objects from a collection of XML
182 files
and return their sum. The
return value
is a
183 two-element tuple. The first element
is the deserialized
184 and summed CoincParamsDistributions object, the second
is a
185 segmentlistdict indicating the interval of time spanned by
186 the out segments
in the search_summary rows matching the
187 process IDs that were attached to the
188 CoincParamsDistributions objects
in the XML.
191 for n, filename
in enumerate(filenames, 1):
193 print(
"%d/%d:" % (n, len(filenames)), end=
' ', file=sys.stderr)
194 xmldoc = ligolw_utils.load_filename(filename, verbose = verbose)
197 seglists = lsctables.SearchSummaryTable.get_table(xmldoc).get_out_segmentlistdict(set([self.process_id])).coalesce()
201 seglists |= lsctables.SearchSummaryTable.get_table(xmldoc).get_out_segmentlistdict(set([other.process_id])).coalesce()
204 return self, seglists
232 events = tuple(events)
234 t += sum(float(event.peak - t) * event.ms_snr**2.0
for event
in events) / sum(event.ms_snr**2.0
for event
in events)
235 gmst = lal.GreenwichMeanSiderealTime(t) % (2 * math.pi)
237 for event1, event2
in itertools.combinations(sorted(events, key =
lambda x: x.ifo), 2):
238 if event1.ifo == event2.ifo:
243 prefix =
"%s_%s_" % (event1.ifo, event2.ifo)
249 dt = float(event1.peak + offsetvector[event1.ifo] - event2.peak - offsetvector[event2.ifo])
250 name =
"%sdt" % prefix
251 if name
not in params
or abs(params[name][0]) > abs(dt):
253 params[name] = (dt, gmst)
255 df = (event1.peak_frequency - event2.peak_frequency) / ((event1.peak_frequency + event2.peak_frequency) / 2)
256 name =
"%sdf" % prefix
257 if name
not in params
or abs(params[name][0]) > abs(df):
259 params[name] = (df, gmst)
261 dh = (event1.ms_hrss - event2.ms_hrss) / ((event1.ms_hrss + event2.ms_hrss) / 2)
262 name =
"%sdh" % prefix
263 if name
not in params
or abs(params[name][0]) > abs(dh):
265 params[name] = (dh, gmst)
267 dband = (event1.ms_bandwidth - event2.ms_bandwidth) / ((event1.ms_bandwidth + event2.ms_bandwidth) / 2)
268 name =
"%sdband" % prefix
269 if name
not in params
or abs(params[name][0]) > abs(dband):
271 params[name] = (dband, gmst)
273 ddur = (event1.ms_duration - event2.ms_duration) / ((event1.ms_duration + event2.ms_duration) / 2)
274 name =
"%sddur" % prefix
275 if name
not in params
or abs(params[name][0]) > abs(ddur):
277 params[name] = (ddur, gmst)
279 return self(**params)
290 detector = lal.cached_detector_by_prefix[event.ifo]
294 delay = lal.TimeDelayFromEarthCenter(detector.location, ra, dec, event.peak)
296 event.period = event.period.shift(-delay)
298 event.ms_peak -= delay
299 except AttributeError:
302 event.ms_period = event.ms_period.shift(-delay)
303 except AttributeError:
309 fp, fc = lal.ComputeDetAMResponse(detector.response, ra, dec, 0, lal.GreenwichMeanSiderealTime(event.peak))
310 mean_response = math.sqrt(fp**2 + fc**2)
311 event.amplitude /= mean_response
312 event.ms_hrss /= mean_response
321 ra, dec = MW_CENTER_J2000_RA_RAD, MW_CENTER_J2000_DEC_RAD
322 return EPAllSkyCoincParamsDistributions.coinc_params([
delay_and_amplitude_correct(copy.copy(event), ra, dec)
for event
in events], offsetvector)
334process_program_name =
"lalburst_power_meas_likelihood"
338 xmldoc = ligolw.Document()
339 node = xmldoc.appendChild(ligolw.LIGO_LW())
341 process = ligolw_process.register_to_xmldoc(xmldoc, program = process_program_name, paramdict = {}, version = __version__, cvs_repository =
"lscsoft", cvs_entry_time = __date__, comment = comment)
342 coinc_params_distributions.process_id = process.process_id
343 ligolw_search_summary.append_search_summary(xmldoc, process, ifos = seglists.keys(), inseg = seglists.extent_all(), outseg = seglists.extent_all())
345 node.appendChild(coinc_params_distributions.to_xml(name))
347 process.set_end_time_now()
def __init__(self, instruments)
def __iadd__(self, other)
def from_xml(cls, xml, name)
def from_filenames(cls, filenames, name, verbose=False)
Convenience function to deserialize CoincParamsDistributions objects from a collection of XML files a...
string ligo_lw_name_suffix
def get_xml_root(cls, xml, name)
def ln_lr_from_triggers(self, events, offsetvector)
def ln_lr_from_triggers(self, events, offsetvector)
def __init__(self, instruments)
def increment(self, params, weight=1.0)
Increment the counts defining this density at the given parameters.
def to_xml(self, name)
Serialize to an XML fragment and return the root element of the resulting XML tree.
def copy(self)
Return a duplicate copy of this object.
def __iadd__(self, other)
Marginalize the two densities.
def __call__(self, **params)
Evaluate.
def finish(self)
Ensure all internal densities are normalized, and initialize interpolator objects as needed for smoot...
def from_xml(cls, xml, name)
In the XML document tree rooted at xml, search for the serialized LnLRDensity object named name,...
Base class for parameter distribution densities for use in log likelihood ratio ranking statistics.
def get_xml_root(cls, xml, name)
Sub-classes can use this in their overrides of the .from_xml() method to find the root element of the...
Mixin to assist in implementing a log likelihood ratio ranking statistic class.
def delay_and_amplitude_correct(event, ra, dec)
def gen_likelihood_control(coinc_params_distributions, seglists, name=process_program_name, comment="")