Exemplo n.º 1
0
def make_inference_corner_plot(workflow, mcmc_file, output_dir, config_file,
                    name="mcmc_corner", analysis_seg=None, tags=None):
    """ Sets up the corner plot of the posteriors in the workflow.

    Parameters
    ----------
    workflow: pycbc.workflow.Workflow
        The core workflow instance we are populating
    mcmc_file: pycbc.workflow.File
        The file with MCMC samples.
    output_dir: str
        The directory to store result plots and files.
    config_file: str
        The path to the inference configuration file that has a
        [variable_args] section.
    name: str
        The name in the [executables] section of the configuration file
        to use.
    analysis_segs: {None, glue.segments.Segment}
       The segment this job encompasses. If None then use the total analysis
       time from the workflow.
    tags: {None, optional}
        Tags to add to the minifollowups executables.

    Returns
    -------
    pycbc.workflow.FileList
        A list of result and output files. 
    """

    # default values
    tags = [] if tags is None else tags
    analysis_seg = workflow.analysis_time \
                       if analysis_seg is None else analysis_seg

    # read config file to get variables that vary
    cp = WorkflowConfigParser([config_file])
    variable_args = cp.options("variable_args")

    # add derived mass parameters if mass1 and mass2 in variable_args
    if "mass1" in variable_args and "mass2" in variable_args:
        variable_args += ["mchirp", "eta"]

    # make the directory that will contain the output files
    makedir(output_dir)

    # make a node for plotting the posterior as a corner plot
    node = PlotExecutable(workflow.cp, name, ifos=workflow.ifos,
                      out_dir=output_dir, universe="local",
                      tags=tags).create_node()

    # add command line options
    node.add_input_opt("--input-file", mcmc_file)
    node.new_output_file_opt(analysis_seg, ".png", "--output-file")

    # add node to workflow
    workflow += node

    return node.output_files
Exemplo n.º 2
0
def make_inference_single_parameter_plots(workflow, mcmc_file, output_dir,
                    config_file, samples_name="mcmc_samples",
                    auto_name="mcmc_acf", analysis_seg=None, tags=None):
    """ Sets up single-parameter plots from MCMC in the workflow.

    Parameters
    ----------
    workflow: pycbc.workflow.Workflow
        The core workflow instance we are populating
    mcmc_file: pycbc.workflow.File
        The file with MCMC samples.
    output_dir: str
        The directory to store result plots and files.
    config_file: str
        The path to the inference configuration file that has a
        [variable_args] section.
    samples_name: str
        The name in the [executables] section of the configuration file
        to use for the plot that shows all samples.
    auto_name: str
        The name in the [executables] section of the configuration file
        to use for the autocorrelation function plot.
    analysis_segs: {None, glue.segments.Segment}
       The segment this job encompasses. If None then use the total analysis
       time from the workflow.
    tags: {None, optional}
        Tags to add to the minifollowups executables.

    Returns
    -------
    files: pycbc.workflow.FileList
        A list of result and output files. 
    """

    # default values
    tags = [] if tags is None else tags
    analysis_seg = workflow.analysis_time \
                       if analysis_seg is None else analysis_seg

    # read config file to get variables that vary
    cp = WorkflowConfigParser([config_file])
    variable_args = cp.options("variable_args")

    # make the directory that will contain the output files
    makedir(output_dir)

    # list of all output files
    files = FileList()

    # make a set of plots for each parameter
    for arg in variable_args:

        # make a node for plotting all the samples
        samples_node = PlotExecutable(workflow.cp, samples_name,
                          ifos=workflow.ifos, out_dir=output_dir,
                          tags=tags + [arg]).create_node()

        # add command line options
        samples_node.add_input_opt("--input-file", mcmc_file)
        samples_node.new_output_file_opt(analysis_seg, ".png", "--output-file")
        samples_node.add_opt("--variable-args", arg)
        samples_node.add_opt("--labels", arg)

        # make node for plotting the autocorrelation function for each walker
        auto_node = PlotExecutable(workflow.cp, auto_name, ifos=workflow.ifos,
                          out_dir=output_dir, tags=tags + [arg]).create_node()

        # add command line options
        auto_node.add_input_opt("--input-file", mcmc_file)
        auto_node.new_output_file_opt(analysis_seg, ".png", "--output-file")
        auto_node.add_opt("--variable-args", arg)

        # add nodes to workflow
        workflow += samples_node
        workflow += auto_node

        # add files to output files list
        files += samples_node.output_files
        files += auto_node.output_files

    return files