Exemplo n.º 1
0
def test_open_xmldoc():
    from glue.ligolw.ligolw import (Document, LIGO_LW)
    assert isinstance(io_ligolw.open_xmldoc(tempfile.mktemp()), Document)
    with tempfile.TemporaryFile(mode='w') as f:
        xmldoc = Document()
        xmldoc.appendChild(LIGO_LW())
        xmldoc.write(f)
        f.seek(0)
        assert isinstance(io_ligolw.open_xmldoc(f), Document)
Exemplo n.º 2
0
 def test_open_xmldoc(self):
     from glue.ligolw.ligolw import (Document, LIGO_LW)
     assert isinstance(io_ligolw.open_xmldoc(tempfile.mktemp()), Document)
     with tempfile.TemporaryFile(mode='w') as f:
         xmldoc = Document()
         xmldoc.appendChild(LIGO_LW())
         xmldoc.write(f)
         f.seek(0)
         assert isinstance(io_ligolw.open_xmldoc(f), Document)
Exemplo n.º 3
0
def write_ligolw(flag, fobj, **kwargs):
    """Write this `DataQualityFlag` to XML in LIGO_LW format
    """
    # if given a Document, just add data
    if isinstance(fobj, Document):
        return write_to_xmldoc(flag, fobj, **kwargs)
    # otherwise build a new Document
    xmldoc = Document()
    xmldoc.appendChild(LIGO_LW())
    # TODO: add process information
    write_to_xmldoc(flag, xmldoc)
    # and write
    if isinstance(fobj, string_types):
        return write_filename(xmldoc, fobj, gz=fobj.endswith('.gz'))
    else:
        return write_fileobj(xmldoc, fobj, gz=fobj.name.endswith('.gz'))
Exemplo n.º 4
0
def write_ligolw(flag, fobj, **kwargs):
    """Write this `DataQualityFlag` to XML in LIGO_LW format
    """
    if isinstance(fobj, Document):
        return write_to_xmldoc(flag, fobj, **kwargs)
    elif isinstance(fobj, (str, unicode)):
        fobj = open(fobj, 'w')
        close = True
    else:
        close = False
    xmldoc = Document()
    xmldoc.appendChild(LIGO_LW())
    # TODO: add process information
    write_to_xmldoc(flag, xmldoc)
    xmldoc.write(fobj)
    if close:
        fobj.close()
Exemplo n.º 5
0
def write_ligolw(flag, fobj, **kwargs):
    """Write this `DataQualityFlag` to XML in LIGO_LW format
    """
    if isinstance(fobj, Document):
        return write_to_xmldoc(flag, fobj, **kwargs)
    elif isinstance(fobj, (str, unicode)):
        fobj = open(fobj, 'w')
        close = True
    else:
        close = False
    xmldoc = Document()
    xmldoc.appendChild(LIGO_LW())
    # TODO: add process information
    write_to_xmldoc(flag, xmldoc)
    xmldoc.write(fobj)
    if close:
        fobj.close()
Exemplo n.º 6
0
def test_get_ligolw_element():
    from glue.ligolw.ligolw import (Document, LIGO_LW)
    xmldoc = Document()
    llw = xmldoc.appendChild(LIGO_LW())
    assert io_ligolw.get_ligolw_element(llw) is llw
    assert io_ligolw.get_ligolw_element(xmldoc) is llw
    with pytest.raises(ValueError):
        io_ligolw.get_ligolw_element(Document())
Exemplo n.º 7
0
def llwtable():
    from glue.ligolw.ligolw import (Document, LIGO_LW)

    # build dummy document with two tables
    xmldoc = Document()
    llw = xmldoc.appendChild(LIGO_LW())
    tables = [new_table('process'), new_table('sngl_ringdown')]
    for t in tables:
        llw.appendChild(t)
    return xmldoc
Exemplo n.º 8
0
    def test_list_tables(self):
        from glue.ligolw import lsctables
        from glue.ligolw.ligolw import (Document, LIGO_LW)

        # build dummy document with two tables
        xmldoc = Document()
        llw = xmldoc.appendChild(LIGO_LW())
        tables = [lsctables.New(lsctables.ProcessTable),
                  lsctables.New(lsctables.SnglRingdownTable)]
        names = [t.TableName(t.Name) for t in tables]
        [llw.appendChild(t) for t in tables]  # add tables to xmldoc

        # check that tables are listed properly
        assert io_ligolw.list_tables(xmldoc) == names

        # check that we can list from files
        with tempfile.NamedTemporaryFile(mode='w') as f:
            xmldoc.write(f)
            f.seek(0)
            assert io_ligolw.list_tables(f) == names
import glob
import re
from pylal.dq.dqTriggerUtils import fromkwfile
from glue.ligolw.utils import write_filename, write_fileobj
from glue.ligolw.ligolw import LIGO_LW, Document
from glue.ligolw import lsctables
from glue.ligolw import ilwd

if len(glob.glob("%s/*.trg" % sys.argv[1])) == 0:
	print "No .trg files found. Nothing to convert."
	sys.exit(0)

for f in glob.glob("%s/*.trg" % sys.argv[1]):
	#print f
	xmldoc = Document()
	xmldoc.appendChild( LIGO_LW() )
	sbt = lsctables.New(lsctables.SnglBurstTable,
            ["ifo", "peak_time", "peak_time_ns", "event_id", "process_id",
			"start_time", "start_time_ns", "confidence", "chisq", "chisq_dof",
			"amplitude", 
            "duration",  "search", "central_freq", "channel", "snr",
            "bandwidth"])
	#H1_TCS-ITMY_PD_ISS_OUT_AC_1_1024.xml
	fspl = os.path.basename(f).split("_")
	ifo = fspl[0]
	channel = "_".join( fspl[1:-2] )
	sbt += fromkwfile( f, ifo=ifo, channel=channel, columns = ["duration", "start_time", "peak_time", "central_freq", "bandwidth", "snr", "confidence"] )
	for i, sb in enumerate(sbt): 
		sb.search = "KleineWelle"
		sb.process_id = ilwd.ilwdchar("process:process_id:0")
		sb.event_id = ilwd.ilwdchar("sngl_burst:event_id:%d"% i )
import glob
import re
from pylal.dq.dqTriggerUtils import fromkwfile
from glue.ligolw.utils import write_filename, write_fileobj
from glue.ligolw.ligolw import LIGO_LW, Document
from glue.ligolw import lsctables
from glue.ligolw import ilwd

if len(glob.glob("%s/*.trg" % sys.argv[1])) == 0:
    print "No .trg files found. Nothing to convert."
    sys.exit(0)

for f in glob.glob("%s/*.trg" % sys.argv[1]):
    #print f
    xmldoc = Document()
    xmldoc.appendChild(LIGO_LW())
    sbt = lsctables.New(lsctables.SnglBurstTable, [
        "ifo", "peak_time", "peak_time_ns", "event_id", "process_id",
        "start_time", "start_time_ns", "confidence", "chisq", "chisq_dof",
        "amplitude", "duration", "search", "central_freq", "channel", "snr",
        "bandwidth"
    ])
    #H1_TCS-ITMY_PD_ISS_OUT_AC_1_1024.xml
    fspl = os.path.basename(f).split("_")
    ifo = fspl[0]
    channel = "_".join(fspl[1:-2])
    sbt += fromkwfile(f,
                      ifo=ifo,
                      channel=channel,
                      columns=[
                          "duration", "start_time", "peak_time",