Example #1
0
def read_psd_xmldoc(xmldoc, root_name=u"psd"):
    """
    Parse a dictionary of PSD frequency series objects from an XML
    document.  See also make_psd_xmldoc() for the construction of XML
    documents from a dictionary of PSDs.  Interprets an empty frequency
    series for an instrument as None.

    The XML document tree is searched for a LIGO_LW element whose Name
    attribute is root_name (default is "psd").  If root_name is None all
    REAL8Frequency series objects below xmldoc are included in the return
    value.
    """
    if root_name is not None:
        xmldoc, = (
            elem
            for elem in xmldoc.getElementsByTagName(ligolw.LIGO_LW.tagName)
            if elem.hasAttribute(u"Name") and elem.Name == root_name)
    result = dict(
        (ligolw_param.get_pyvalue(elem, u"instrument"),
         parse_REAL8FrequencySeries(elem))
        for elem in xmldoc.getElementsByTagName(ligolw.LIGO_LW.tagName)
        if elem.hasAttribute(u"Name") and elem.Name == u"REAL8FrequencySeries")
    # interpret empty frequency series as None
    for instrument in result:
        if len(result[instrument].data.data) == 0:
            result[instrument] = None
    return result
Example #2
0
 def from_xml(cls, name):
     xml = cls.get_xml_root(xml, name)
     self = cls(
         lsctables.instrument_set_from_ifos(
             ligolw_param.get_pyvalue(xml, "instruments")))
     for key in self.densities:
         self.densities[key] = rate.BinnedLnPDF.from_xml(xml, key)
     return self
Example #3
0
def get_snr_series(xmldoc):
    for elem in xmldoc.getElements(is_COMPLEX8TimeSeries):
        try:
            event_id = get_pyvalue(elem, 'event_id')
            array = get_array(elem, 'snr')
        except ValueError:
            pass
        else:
            yield event_id, array
Example #4
0
def psd_instrument_dict(elem):
    out = {}
    for lw in elem.getElementsByTagName(u"LIGO_LW"):
        if not lw.hasAttribute(u"Name"):
            continue
        if lw.getAttribute(u"Name") != u"REAL8FrequencySeries":
            continue
        ifo = param.get_pyvalue(lw, u"instrument")
        out[ifo] = lalseries.parse_REAL8FrequencySeries(lw)
    return out
Example #5
0
def psd_instrument_dict(elem):
    out = {}
    for lw in elem.getElementsByTagName(u"LIGO_LW"):
        if not lw.hasAttribute(u"Name"):
            continue
        if lw.getAttribute(u"Name") != u"REAL8FrequencySeries":
            continue
        ifo = param.get_pyvalue(lw, u"instrument")
        out[ifo] = lalseries.parse_REAL8FrequencySeries(lw)
    return out
Example #6
0
def read_tseries_xmldoc(xmldoc):
    result = dict(
        (param.get_pyvalue(elem, u"instrument"), parse_REAL8TimeSeries(elem))
        for elem in xmldoc.getElementsByTagName(ligolw.LIGO_LW.tagName)
        if elem.hasAttribute(u"Name")
        and elem.getAttribute(u"Name") == u"REAL8TimeSeries")
    # Interpret empty frequency series as None
    for instrument in result:
        if len(result[instrument].data) == 0:
            result[instrument] = None
    return result
 def _snr_series_by_sngl_inspiral(cls, doc):
     for elem in doc.getElementsByTagName(LIGO_LW.tagName):
         try:
             if elem.Name != lal.COMPLEX8TimeSeries.__name__:
                 continue
             array.get_array(elem, 'snr')
             event_id = param.get_pyvalue(elem, 'event_id')
             if not isinstance(event_id, SnglInspiralID):
                 continue
         except (AttributeError, ValueError):
             continue
         else:
             yield event_id, lal.series.parse_COMPLEX8TimeSeries(elem)
Example #8
0
def get_refpsd_xml(xml):
    retdict = dict()
    xmldoc = ligolw_utils.load_filename(refpsd, contenthandler = PSDContentHandler, verbose = True)
    root_name = u"psd"
    xmldoc, = (elem for elem in xmldoc.getElementsByTagName(ligolw.LIGO_LW.tagName) if elem.hasAttribute(u"Name") and elem.Name == root_name)
    for elem in xmldoc.getElementsByTagName(ligolw.LIGO_LW.tagName):
        if elem.hasAttribute(u"Name") and elem.Name == u"REAL8FrequencySeries":
            ifo = ligolw_param.get_pyvalue(elem, u"instrument")
            # t, = elem.getElementsByTagName(ligolw.Time.tagName)
            a, = elem.getElementsByTagName(ligolw.Array.tagName)
            # dims = a.getElementsByTagName(ligolw.Dim.tagName)
            # f0 = ligolw_param.get_param(elem, u"f0")
            retdict[str(ifo)] = a.array
    return retdict
Example #9
0
def read_psd_xmldoc(xmldoc):
    """
    Parse a dictionary of PSD frequency series objects from an XML
    document.  See also make_psd_xmldoc() for the construction of XML documents
    from a dictionary of PSDs.  Interprets an empty freuency series for an
    instrument as None.
    """
    out = dict((ligolw_param.get_pyvalue(elem, u"instrument"),
                parse_REAL8FrequencySeries(elem))
               for elem in xmldoc.getElementsByTagName(ligolw.LIGO_LW.tagName)
               if elem.hasAttribute(u"Name")
               and elem.getAttribute(u"Name") == u"REAL8FrequencySeries")
    # Interpret empty frequency series as None
    for k in out:
        if len(out[k].data.data) == 0:
            out[k] = None
    return out
Example #10
0
def read_psd_xmldoc(xmldoc, root_name = None):
	"""
	Parse a dictionary of PSD frequency series objects from an XML
	document.  See also make_psd_xmldoc() for the construction of XML
	documents from a dictionary of PSDs.  Interprets an empty freuency
	series for an instrument as None.

	The XML document tree is searched for a LIGO_LW element whose Name
	attribute is root_name.  For backwards compatibility, if root_name
	is None (the default) all REAL8Frequency series objects below
	xmldoc are included in the return value.
	"""
	# FIXME:  change the default value to u"psd" once enough time has
	# passed for the latest make_pds_xmldoc() to have sunk in
	if root_name is not None:
		xmldoc, = (elem for elem in xmldoc.getElementsByTagName(ligolw.LIGO_LW.tagName) if elem.hasAttribute(u"Name") and elem.Name == root_name)
	result = dict((ligolw_param.get_pyvalue(elem, u"instrument"), parse_REAL8FrequencySeries(elem)) for elem in xmldoc.getElementsByTagName(ligolw.LIGO_LW.tagName) if elem.hasAttribute(u"Name") and elem.Name == u"REAL8FrequencySeries")
	# interpret empty frequency series as None
	for instrument in result:
		if len(result[instrument].data) == 0:
			result[instrument] = None
	return result