Esempio n. 1
0
def get_hardware_injection_segment_files(workflow,
                                         output_dir,
                                         hwinjDefPath,
                                         tag=None):
    """
    This function queries the segment database for the hardware
    injection segments and saves them to the output_dir.

    Parameters
    -----------
    workflow : ahope.Workflow
        The ahope workflow instance that the coincidence jobs will be added to.
    output_dir : path
        The directory in which output files will be stored.
    hwinjDefPath : path
        The path to the hardware injection definer file.
    tag : string, optional (default=None)
        Use this to specify a tag. This can be used if this module is being
        called more than once to give call specific configuration (by setting
        options in [workflow-datafind-${TAG}] rather than [workflow-datafind]).
        This is also used to tag the Files returned by the class to uniqueify
        the Files and uniqueify the actual filename.
    """

    # create log dir
    log_dir = os.path.join(output_dir, 'logs')
    if not os.path.exists(log_dir):
        os.makedirs(log_dir)

    # get hardware injection segments
    # ligolw_cbc_hardware_inj_page expects seperate XML files for each IFO
    for ifo in workflow.ifos:
        hwinjSegName = workflow.cp.get_opt_tags(
            'workflow-hardware-injections',
            'segments-%s-hwinj-name' % (ifo.lower()), [tag])

        output_filename = '-'.join(
            map(str, [
                ifo, 'HWINJ_SEGMENTS', workflow.analysis_time[0],
                abs(workflow.analysis_time)
            ])) + '.xml'
        output_path = os.path.join(output_dir, output_filename)

        segFindCall = [
            workflow.cp.get("executables", "segment_query"),
            "--query-segments", "--gps-start-time",
            str(workflow.analysis_time[0]), "--gps-end-time",
            str(workflow.analysis_time[1]), "--include-segments", hwinjSegName,
            "--output-file", output_path, "--segment-url",
            workflow.cp.get("workflow-hardware-injections",
                            "segments-database-url")
        ]

        make_external_call(segFindCall,
                           out_dir=log_dir,
                           out_basename='%s-hwinj-call' % (ifo.lower()))
Esempio n. 2
0
def get_hardware_injection_segment_files(workflow, output_dir, hwinjDefPath,
                                         tag=None):
    """
    This function queries the segment database for the hardware
    injection segments and saves them to the output_dir.

    Parameters
    -----------
    workflow : ahope.Workflow
        The ahope workflow instance that the coincidence jobs will be added to.
    output_dir : path
        The directory in which output files will be stored.
    hwinjDefPath : path
        The path to the hardware injection definer file.
    tag : string, optional (default=None)
        Use this to specify a tag. This can be used if this module is being
        called more than once to give call specific configuration (by setting
        options in [workflow-datafind-${TAG}] rather than [workflow-datafind]).
        This is also used to tag the Files returned by the class to uniqueify
        the Files and uniqueify the actual filename.
    """

    # create log dir
    log_dir = os.path.join(output_dir, 'logs')
    if not os.path.exists(log_dir):
        os.makedirs(log_dir)

    # get hardware injection segments
    # ligolw_cbc_hardware_inj_page expects seperate XML files for each IFO
    for ifo in workflow.ifos:
        hwinjSegName = workflow.cp.get_opt_tags('workflow-hardware-injections',
                                 'segments-%s-hwinj-name' % (ifo.lower()), [tag])

        output_filename = '-'.join(map(str, [ifo, 'HWINJ_SEGMENTS',
                                       workflow.analysis_time[0],
                                       abs(workflow.analysis_time)])) + '.xml'
        output_path = os.path.join(output_dir, output_filename)

        segFindCall = [ workflow.cp.get("executables","segment_query"),
            "--query-segments",
            "--gps-start-time", str(workflow.analysis_time[0]),
            "--gps-end-time", str(workflow.analysis_time[1]),
            "--include-segments", hwinjSegName,
            "--output-file", output_path,
            "--segment-url", workflow.cp.get("workflow-hardware-injections",
                                                 "segments-database-url")]

        make_external_call(segFindCall, out_dir=log_dir,
                                out_basename='%s-hwinj-call' %(ifo.lower()) )
Esempio n. 3
0
def get_science_segments(ifo, cp, start_time, end_time, out_dir, tag=None):
    """
    Obtain science segments for the selected ifo

    Parameters
    -----------
    ifo : string
        The string describing the ifo to obtain science times for.
    start_time : gps time (either int/LIGOTimeGPS)
        The time at which to begin searching for segments.
    end_time : gps time (either int/LIGOTimeGPS)
        The time at which to stop searching for segments.
    out_dir : path
        The directory in which output will be stored.    
    tag : string, optional (default=None)
        Use this to specify a tag. This can be used if this module is being
        called more than once to give call specific configuration (by setting
        options in [workflow-datafind-${TAG}] rather than [workflow-datafind]). This
        is also used to tag the Files returned by the class to uniqueify
        the Files and uniqueify the actual filename.

    Returns
    --------
    sciSegs : glue.segments.segmentlist
        The segmentlist generated by this call
    sciXmlFile : pycbc.workflow.core.OutSegFile
        The workflow File object corresponding to this science segments file.

    """
    segValidSeg = segments.segment([start_time,end_time])
    sciSegName = cp.get_opt_tags(
        "workflow-segments", "segments-%s-science-name" %(ifo.lower()), [tag])
    sciSegUrl = cp.get_opt_tags(
        "workflow-segments", "segments-database-url", [tag])
    if tag:
        sciXmlFilePath = os.path.join(
            out_dir, "%s-SCIENCE_SEGMENTS_%s.xml" %(ifo.upper(), tag) )
        tagList=[tag, 'SCIENCE']
    else:
        sciXmlFilePath = os.path.join(
            out_dir, "%s-SCIENCE_SEGMENTS.xml" %(ifo.upper()) )
        tagList = ['SCIENCE']

    if file_needs_generating(sciXmlFilePath):
        segFindCall = [ cp.get("executables","segment_query"),
            "--query-segments",
            "--segment-url", sciSegUrl,
            "--gps-start-time", str(start_time),
            "--gps-end-time", str(end_time),
            "--include-segments", sciSegName,
            "--output-file", sciXmlFilePath ]
   
        make_external_call(segFindCall, out_dir=os.path.join(out_dir,'logs'),
                                out_basename='%s-science-call' %(ifo.lower()) )

    # Yes its yucky to generate a file and then read it back in. This will be
    # fixed when the new API for segment generation is ready.
    sciXmlFP = open(sciXmlFilePath,'r')
    sciXmlFilePath = os.path.abspath(sciXmlFilePath)
    sciSegs = fromsegmentxml(sciXmlFP)
    sciXmlFP.close()
    currUrl = urlparse.urlunparse(['file', 'localhost', sciXmlFilePath,
                                   None, None, None])
    sciXmlFile = OutSegFile(ifo, 'SEGMENTS',
                                  segValidSeg, currUrl, segment_list=sciSegs,
                                  tags=tagList)
    sciXmlFile.PFN(sciXmlFilePath, site='local')
    return sciSegs, sciXmlFile