Esempio n. 1
0
def multi_segments_to_file(seg_list, filename, names, ifos):
    """ Save segments to an xml file
    
    Parameters
    ----------
    seg_list: glue.segments.segmentlist
        List of segment lists to write to disk
    filename : str
        name of the output file
    names : 
        name of each segment list
    ifos :
        list of ifos
        
    Returns
    -------
    File : Return a pycbc.core.File reference to the file
    """
    from pycbc.workflow.core import File

    # create XML doc and add process table
    outdoc = ligolw.Document()
    outdoc.appendChild(ligolw.LIGO_LW())
    process = ligolw_utils.process.register_to_xmldoc(outdoc, argv[0], {})

    for segs, ifo, name in zip(seg_list, ifos, names):
        fsegs = [(lal.LIGOTimeGPS(seg[0]), lal.LIGOTimeGPS(seg[1])) \
            for seg in segs]

        # add segments, segments summary, and segment definer tables using glue library
        with ligolw_segments.LigolwSegments(outdoc, process) as xmlsegs:
            xmlsegs.insert_from_segmentlistdict({ifo: fsegs}, name)

    # write file
    ligolw_utils.write_filename(outdoc, filename)

    # return a File instance
    url = urlparse.urlunparse(
        ['file', 'localhost', filename, None, None, None])
    f = File(ifo, name, segs, file_url=url, tags=[name])
    f.PFN(os.path.abspath(filename), site='local')
    return f
def tosegmentxml(file, segs):
    """
    Write the glue.segments.segmentlist object segs to file object file in xml
    format with appropriate tables.
  """

    # generate empty document
    xmldoc = ligolw.Document()
    xmldoc.appendChild(ligolw.LIGO_LW())
    xmldoc.childNodes[-1].appendChild(lsctables.New(lsctables.ProcessTable))
    xmldoc.childNodes[-1].appendChild(
        lsctables.New(lsctables.ProcessParamsTable))

    # append process to table
    process = ligolw_process.append_process(xmldoc,\
                                    program='pylal.dq.dqSegmentUtils',\
                                    version=__version__,\
                                    cvs_repository='lscsoft',\
                                    cvs_entry_time=__date__)

    gpssegs = segments.segmentlist()
    for seg in segs:
        gpssegs.append(
            segments.segment(LIGOTimeGPS(seg[0]), LIGOTimeGPS(seg[1])))

    # append segs and seg definer
    segments_tables = ligolw_segments.LigolwSegments(xmldoc)
    segments_tables.add(ligolw_segments.LigolwSegmentList(active=gpssegs))
    # finalise
    segments_tables.coalesce()
    segments_tables.optimize()
    segments_tables.finalize(process)
    ligolw_process.set_process_end_time(process)

    # write file
    with utils.SignalsTrap():
        utils.write_fileobj(xmldoc, file, gz=False)
Esempio n. 3
0
def write_round_xml(vetosegs, vetotrigs, winner, ifo, opts):
    """
	Write out the products from this round of hveto: veto segments and the vetoed triggers.
	"""
    # Create a new document
    xmldoc = ligolw.Document()
    xmldoc.appendChild(ligolw.LIGO_LW())

    # Append the process information
    procrow = utils.process.append_process(xmldoc, program="laldetchar-hveto")
    utils.process.append_process_params(
        xmldoc, procrow, utils.process.process_params_from_dict(opts))

    # Add the vetoed triggers
    xmldoc.childNodes[0].childNodes.append(vetotrigs)

    # Append the veto segments
    segl = segmentlistdict()
    segl[ifo] = vetosegs
    lwsegs = ligolw_segments.LigolwSegments(xmldoc)
    lwsegs.insert_from_segmentlistdict(segl, "hveto")
    lwsegs.finalize(procrow)

    return xmldoc
if opts.verbose:
	print "Loaded %s, total coverage time: %f" % (opts.frame_cache, abs(seg))

#
# Set up the XML document
#
xmldoc = ligolw.Document()
xmldoc.appendChild(ligolw.LIGO_LW())
# Append the process information
procrow = utils.process.append_process(xmldoc, program=sys.argv[0])
utils.process.append_process_params(xmldoc, procrow, process.process_params_from_dict(opts.__dict__))

#
# Segment storage
#
lwsegs = lw_segs.LigolwSegments(xmldoc)
all_segs = {}

#
# Loop over each channel, applying the set of conditions appropriate to it
#
for channel, opthresholds in channel_cond.iteritems():
	#
	# Can't have both an equality as well as an inequality via threshold
	#
	if len(opthresholds) > 1 and any([op == "==" for (op, t) in opthresholds]):
		raise ValueError("Equality and inequality are not compatible.")

	#
	# Determine lt and gt thresholds
	#