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
def _build_series(series, dim_names, comment, delta_name, delta_unit): from pycbc_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
def _build_series(series, dim_names, comment, delta_name, delta_unit): from pycbc_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