Exemple #1
0
def _build_series(series, dim_names, comment, delta_name, delta_unit):
    elem = ligolw.LIGO_LW(
        Attributes({u"Name": unicode(series.__class__.__name__)}))
    if comment is not None:
        elem.appendChild(ligolw.Comment()).pcdata = comment
    # FIXME:  make Time class smart so we don't have to build it by
    # hand
    elem.appendChild(
        ligolw.Time(Attributes({
            u"Name": u"epoch",
            u"Type": u"GPS"
        }))).pcdata = unicode(series.epoch)
    elem.appendChild(ligolw_param.from_pyvalue(u"f0", series.f0, unit=u"s^-1"))
    delta = getattr(series, delta_name)
    if np.iscomplexobj(series.data.data):
        data = np.row_stack((np.arange(len(series.data.data)) * delta,
                             series.data.data.real, series.data.data.imag))
    else:
        data = np.row_stack(
            (np.arange(len(series.data.data)) * delta, series.data.data))
    a = ligolw_array.from_array(series.name, data, dim_names=dim_names)
    a.Unit = lal.UnitToString(series.sampleUnits)
    dim0 = a.getElementsByTagName(ligolw.Dim.tagName)[0]
    dim0.Unit = delta_unit
    dim0.Start = series.f0
    dim0.Scale = delta
    elem.appendChild(a)
    return elem
Exemple #2
0
def make_psd_xmldoc(psddict):
    Attributes = ligolw.sax.xmlreader.AttributesImpl
    xmldoc = ligolw.Document()
    root_name = u"psd"
    lw = xmldoc.appendChild(ligolw.LIGO_LW(Attributes({u"Name": root_name})))
    for instrument, psd in psddict.items():
        xmlseries = _build_series(psd, (u"Frequency,Real", u"Frequency"), None,
                                  'deltaF', 's^-1')
        fs = lw.appendChild(xmlseries)
        fs.appendChild(ligolw_param.from_pyvalue(u"instrument", instrument))
    return xmldoc
Exemple #3
0
def build_COMPLEX16FrequencySeries(series, comment = None):
	elem = ligolw.LIGO_LW(Attributes({u"Name": u"COMPLEX16FrequencySeries"}))
	if comment is not None:
		elem.appendChild(ligolw.Comment()).pcdata = comment
	elem.appendChild(ligolw.Time.from_gps(series.epoch, Name = u"epoch"))
	elem.appendChild(ligolw_param.from_pyvalue(u"f0", series.f0, unit = LALUnit("s^-1")))
	data = series.data
	data = numpy.row_stack((numpy.arange(0, len(data)) * series.deltaF, numpy.real(data), numpy.imag(data)))
	a = ligolw_array.from_array(series.name, data, dim_names = (u"Frequency", u"Frequency,Real,Imaginary"))
	a.Unit = series.sampleUnits
	dim0 = a.getElementsByTagName(ligolw.Dim.tagName)[0]
	dim0.Unit = LALUnit("s^-1")
	dim0.Start = series.f0
	dim0.Scale = series.deltaF
	elem.appendChild(a)
	return elem
Exemple #4
0
def build_COMPLEX16FrequencySeries(series, comment = None):
	elem = ligolw.LIGO_LW(Attributes({u"Name": u"COMPLEX16FrequencySeries"}))
	if comment is not None:
		elem.appendChild(ligolw.Comment()).pcdata = comment
	elem.appendChild(ligolw.Time.from_gps(series.epoch, Name = u"epoch"))
	elem.appendChild(ligolw_param.from_pyvalue(u"f0", series.f0, unit = LALUnit("s^-1")))
	data = series.data
	data = numpy.row_stack((numpy.arange(0, len(data)) * series.deltaF, numpy.real(data), numpy.imag(data)))
	a = ligolw_array.from_array(series.name, data, dim_names = (u"Frequency", u"Frequency,Real,Imaginary"))
	a.Unit = series.sampleUnits
	dim0 = a.getElementsByTagName(ligolw.Dim.tagName)[0]
	dim0.Unit = LALUnit("s^-1")
	dim0.Start = series.f0
	dim0.Scale = series.deltaF
	elem.appendChild(a)
	return elem
Exemple #5
0
def make_psd_xmldoc(psddict, xmldoc = None):
    """
    Construct an XML document tree representation of a dictionary of
    frequency series objects containing PSDs.  See also
    read_psd_xmldoc() for a function to parse the resulting XML
    documents.

    If xmldoc is None (the default), then a new XML document is created
    and the PSD dictionary added to it.  If xmldoc is not None then the
    PSD dictionary is appended to the children of that element inside a
    new LIGO_LW element.
    """
    if xmldoc is None:
        xmldoc = ligolw.Document()
    lw = xmldoc.appendChild(ligolw.LIGO_LW())
    for instrument, psd in psddict.items():
        fs = lw.appendChild(build_REAL8FrequencySeries(psd))
        if instrument is not None:
            fs.appendChild(ligolw_param.from_pyvalue(u"instrument", instrument))
    return xmldoc
Exemple #6
0
def make_tseries_xmldoc(psddict, xmldoc=None):
    """ 
	Construct an XML document tree representation of a dictionary of 
	frequency series objects containing complex data.  See also 
	read_tseries_xmldoc() for a function to parse the resulting XML 
	documents. 

	If xmldoc is None (the default), then a new XML document is created 
	and the frequency series dictionary added to it.  If xmldoc is not None 
	then the frequency series dictionary is appended to the children of that 
	element inside a new LIGO_LW element. 
	"""
    if xmldoc is None:
        xmldoc = ligolw.Document()
        lw = xmldoc.appendChild(ligolw.LIGO_LW())
        for instrument, psd in psddict.items():
            fs = lw.appendChild(build_REAL8TimeSeries(psd))
            if instrument is not None:
                fs.appendChild(param.from_pyvalue(u"instrument", instrument))
        return xmldoc
Exemple #7
0
def _build_series(series, dim_names, comment, delta_name, delta_unit):
    elem = ligolw.LIGO_LW(Attributes({u"Name": unicode(series.__class__.__name__)}))
    if comment is not None:
        elem.appendChild(ligolw.Comment()).pcdata = comment
    # FIXME:  make Time class smart so we don't have to build it by
    # hand
    elem.appendChild(ligolw.Time(Attributes({u"Name": u"epoch", u"Type": u"GPS"}))).pcdata = unicode(series.epoch)
    elem.appendChild(ligolw_param.from_pyvalue(u"f0", series.f0, unit=u"s^-1"))
    delta = getattr(series, delta_name)
    if np.iscomplexobj(series.data.data):
        data = np.row_stack((np.arange(len(series.data.data)) * delta, series.data.data.real, series.data.data.imag))
    else:
        data = np.row_stack((np.arange(len(series.data.data)) * delta, series.data.data))
    a = ligolw_array.from_array(series.name, data, dim_names=dim_names)
    a.Unit = lal.UnitToString(series.sampleUnits)
    dim0 = a.getElementsByTagName(ligolw.Dim.tagName)[0]
    dim0.Unit = delta_unit
    dim0.Start = series.f0
    dim0.Scale = delta
    elem.appendChild(a)
    return elem
def make_psd_xmldoc(psddict, xmldoc = None, root_name = u"psd"):
    """
    Construct an XML document tree representation of a dictionary of
    frequency series objects containing PSDs.  See also read_psd_xmldoc()
    for a function to parse the resulting XML documents.

    If xmldoc is None (the default), then a new XML document is created and
    the PSD dictionary added to it inside a LIGO_LW element.  If xmldoc is
    not None then the PSD dictionary is appended to the children of that
    element inside a new LIGO_LW element.  In both cases, the LIGO_LW
    element's Name attribute is set to root_name.  This will be looked for
    by read_psd_xmldoc() when parsing the PSD document.
    """
    if xmldoc is None:
        xmldoc = ligolw.Document()
    lw = xmldoc.appendChild(ligolw.LIGO_LW(Attributes({u"Name": root_name})))
    for instrument, psd in psddict.items():
        fs = lw.appendChild(build_REAL8FrequencySeries(psd))
        if instrument is not None:
            fs.appendChild(ligolw_param.from_pyvalue(u"instrument", instrument))
    return xmldoc
Exemple #9
0
def build_REAL8FrequencySeries(series, comment = None):
	elem = ligolw.LIGO_LW(Attributes({u"Name": u"REAL8FrequencySeries"}))
	if comment is not None:
		elem.appendChild(ligolw.Comment()).pcdata = comment
	elem.appendChild(ligolw.Time.from_gps(series.epoch, Name = u"epoch"))
	elem.appendChild(ligolw_param.from_pyvalue(u"f0", series.f0, unit = LALUnit("s^-1")))
	data = series.data
        try:
            # Support both the pylal-wrapped class, and the direct lal class
            datalength = data.length
            data = data.data
        except:
            datalength = len(data)
	data = numpy.row_stack((numpy.arange(0, datalength) * series.deltaF, data))
	a = ligolw_array.from_array(series.name, data, dim_names = (u"Frequency", u"Frequency,Real"))
	a.Unit = series.sampleUnits
	dim0 = a.getElementsByTagName(ligolw.Dim.tagName)[0]
	dim0.Unit = LALUnit("s^-1")
	dim0.Start = series.f0
	dim0.Scale = series.deltaF
	elem.appendChild(a)
	return elem
Exemple #10
0
def make_psd_xmldoc(psddict, xmldoc = None, root_name = u"psd"):
	"""
	Construct an XML document tree representation of a dictionary of
	frequency series objects containing PSDs.  See also
	read_psd_xmldoc() for a function to parse the resulting XML
	documents.

	If xmldoc is None (the default), then a new XML document is created
	and the PSD dictionary added to it inside a LIGO_LW element.  If
	xmldoc is not None then the PSD dictionary is appended to the
	children of that element inside a new LIGO_LW element.  In both
	cases, the LIGO_LW element's Name attribute is set to root_name.
	This will be looked for by read_psd_xmldoc() when parsing the PSD
	document.
	"""
	if xmldoc is None:
		xmldoc = ligolw.Document()
	lw = xmldoc.appendChild(ligolw.LIGO_LW(Attributes({u"Name": root_name})))
	for instrument, psd in psddict.items():
		fs = lw.appendChild(build_REAL8FrequencySeries(psd))
		if instrument is not None:
			fs.appendChild(ligolw_param.from_pyvalue(u"instrument", instrument))
	return xmldoc
Exemple #11
0
def _build_series(series, dim_names, comment, delta_name, delta_unit):
    from glue.ligolw import array as ligolw_array
    Attributes = ligolw.sax.xmlreader.AttributesImpl
    elem = ligolw.LIGO_LW(
        Attributes({u"Name": unicode(series.__class__.__name__)}))
    if comment is not None:
        elem.appendChild(ligolw.Comment()).pcdata = comment
    elem.appendChild(ligolw.Time.from_gps(series.epoch, u"epoch"))
    elem.appendChild(ligolw_param.from_pyvalue(u"f0", series.f0, unit=u"s^-1"))
    delta = getattr(series, delta_name)
    if numpy.iscomplexobj(series.data.data):
        data = numpy.row_stack((numpy.arange(len(series.data.data)) * delta,
                                series.data.data.real, series.data.data.imag))
    else:
        data = numpy.row_stack(
            (numpy.arange(len(series.data.data)) * delta, series.data.data))
    a = ligolw_array.from_array(series.name, data, dim_names=dim_names)
    a.Unit = str(series.sampleUnits)
    dim0 = a.getElementsByTagName(ligolw.Dim.tagName)[0]
    dim0.Unit = delta_unit
    dim0.Start = series.f0
    dim0.Scale = delta
    elem.appendChild(a)
    return elem