def make_trigger_timeseries(workflow, singles, ifo_times, out_dir, special_tids=None, exclude=None, require=None, tags=None): tags = [] if tags is None else tags makedir(out_dir) name = 'plot_trigger_timeseries' secs = requirestr(workflow.cp.get_subsections(name), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: node = PlotExecutable(workflow.cp, name, ifos=workflow.ifos, out_dir=out_dir, tags=[tag] + tags).create_node() node.add_multiifo_input_list_opt('--single-trigger-files', singles) node.add_opt('--times', ifo_times) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') if special_tids is not None: node.add_opt('--special-trigger-ids', special_tids) workflow += node files += node.output_files return files
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
def make_inference_inj_plots(workflow, inference_files, output_dir, parameters, name="inference_recovery", analysis_seg=None, tags=None): """ Sets up the recovered versus injected parameter plot in the workflow. Parameters ---------- workflow: pycbc.workflow.Workflow The core workflow instance we are populating inference_files: pycbc.workflow.FileList The files with posterior samples. output_dir: str The directory to store result plots and files. parameters : list A ``list`` of parameters. Each parameter gets its own plot. name: str The name in the [executables] section of the configuration file to use. analysis_segs: {None, ligo.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 inference 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 output_files = FileList([]) # make the directory that will contain the output files makedir(output_dir) # add command line options for (ii, param) in enumerate(parameters): plot_exe = PlotExecutable(workflow.cp, name, ifos=workflow.ifos, out_dir=output_dir, tags=tags + ['param{}'.format(ii)]) node = plot_exe.create_node() node.add_input_list_opt("--input-file", inference_files) node.new_output_file_opt(analysis_seg, ".png", "--output-file") node.add_opt("--parameters", param) workflow += node output_files += node.output_files return output_files
def make_trigger_timeseries(workflow, singles, ifo_times, out_dir, special_tids, exclude=None, require=None, tags=None): tags = [] if tags is None else tags makedir(out_dir) name = 'plot_trigger_timeseries' secs = requirestr(workflow.cp.get_subsections(name), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: node = PlotExecutable( workflow.cp, name, ifos=workflow.ifos, out_dir=out_dir, tags=[tag] + tags).create_node() node.add_multiifo_input_list_opt('--single-trigger-files', singles) node.add_opt('--times', ifo_times) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') if special_tids is not None: node.add_opt('--special-trigger-ids', special_tids) workflow += node files += node.output_files return files
def make_inference_inj_plots(workflow, inference_files, output_dir, parameters, name="inference_recovery", analysis_seg=None, tags=None): """ Sets up the recovered versus injected parameter plot in the workflow. Parameters ---------- workflow: pycbc.workflow.Workflow The core workflow instance we are populating inference_files: pycbc.workflow.FileList The files with posterior samples. output_dir: str The directory to store result plots and files. parameters : list A ``list`` of parameters. Each parameter gets its own plot. name: str The name in the [executables] section of the configuration file to use. analysis_segs: {None, ligo.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 inference 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 output_files = FileList([]) # make the directory that will contain the output files makedir(output_dir) # add command line options for (ii, param) in enumerate(parameters): plot_exe = PlotExecutable(workflow.cp, name, ifos=workflow.ifos, out_dir=output_dir, tags=tags+['param{}'.format(ii)]) node = plot_exe.create_node() node.add_input_list_opt("--input-file", inference_files) node.new_output_file_opt(analysis_seg, ".png", "--output-file") node.add_opt("--parameters", param) workflow += node output_files += node.output_files return output_files
def make_inference_posterior_plot(workflow, inference_file, output_dir, parameters=None, name="inference_posterior", 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 inference_file: pycbc.workflow.File The file with posterior samples. output_dir: str The directory to store result plots and files. parameters : list A list of parameters to plot. name: str The name in the [executables] section of the configuration file to use. analysis_segs: {None, ligo.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 inference 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 # 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", inference_file) node.new_output_file_opt(analysis_seg, ".png", "--output-file") if parameters is not None: node.add_opt("--parameters", " ".join(parameters)) # add node to workflow workflow += node return node.output_files
def make_inference_samples_plot(workflow, inference_file, output_dir, parameters=None, name="inference_samples", analysis_seg=None, tags=None): # default values tags = [] if tags is None else tags analysis_seg = workflow.analysis_time \ if analysis_seg is None else analysis_seg # 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", inference_file) node.new_output_file_opt(analysis_seg, ".png", "--output-file") node.add_opt("--parameters", " ".join(parameters)) # add node to workflow workflow += node return node.output_files
def make_inj_info(workflow, injection_file, injection_index, num, out_dir, tags=None): tags = [] if tags is None else tags makedir(out_dir) name = 'page_injinfo' files = FileList([]) node = PlotExecutable(workflow.cp, name, ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_opt('--injection-file', injection_file) node.add_opt('--injection-index', str(injection_index)) node.add_opt('--n-nearest', str(num)) node.new_output_file_opt(workflow.analysis_time, '.html', '--output-file') workflow += node files += node.output_files return files
def make_inference_acceptance_rate_plot(workflow, mcmc_file, output_dir, name="mcmc_rate", analysis_seg=None, tags=None): """ Sets up the acceptance rate plot 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. 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 # make the directory that will contain the output files makedir(output_dir) # make a node for plotting the acceptance rate node = PlotExecutable(workflow.cp, name, ifos=workflow.ifos, out_dir=output_dir, 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
def make_inj_info(workflow, injection_file, injection_index, num, out_dir, tags=None): tags = [] if tags is None else tags makedir(out_dir) name = "page_injinfo" files = FileList([]) node = PlotExecutable(workflow.cp, name, ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_opt("--injection-file", injection_file) node.add_opt("--injection-index", str(injection_index)) node.add_opt("--n-nearest", str(num)) node.new_output_file_opt(workflow.analysis_time, ".html", "--output-file") workflow += node files += node.output_files return files
def make_inference_samples_plot( workflow, inference_file, output_dir, parameters=None, name="inference_samples", analysis_seg=None, tags=None): # default values tags = [] if tags is None else tags analysis_seg = workflow.analysis_time \ if analysis_seg is None else analysis_seg # 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", inference_file) node.new_output_file_opt(analysis_seg, ".png", "--output-file") node.add_opt("--parameters", " ".join(parameters)) # add node to workflow workflow += node return node.output_files
def make_inference_corner_plot(workflow, inference_file, output_dir, variable_args=None, name="inference_posterior", 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 inference_file: pycbc.workflow.File The file with posterior 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. variable_args : list A list of parameters to use instead of [variable_args]. 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 # 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", inference_file) node.new_output_file_opt(analysis_seg, ".png", "--output-file") node.add_opt("--variable-args", " ".join(variable_args)) # add node to workflow workflow += node return node.output_files
def make_trigger_timeseries(workflow, singles, coinc, num, out_dir, exclude=None, require=None, tags=None): tags = [] if tags is None else tags makedir(out_dir) name = 'plot_trigger_timeseries' secs = requirestr(workflow.cp.get_subsections(name), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: node = PlotExecutable(workflow.cp, name, ifos=workflow.ifos, out_dir=out_dir, tags=[tag] + tags).create_node() node.add_input_list_opt('--single-trigger-files', singles) node.add_input_opt('--statmap-file', coinc) node.add_opt('--n-loudest', str(num)) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') workflow += node files += node.output_files return files
def make_inference_prior_plot(workflow, config_file, output_dir, sections=None, name="inference_prior", analysis_seg=None, tags=None): """ Sets up the corner plot of the priors in the workflow. Parameters ---------- workflow: pycbc.workflow.Workflow The core workflow instance we are populating config_file: pycbc.workflow.File The WorkflowConfigParser parasable inference configuration file.. output_dir: str The directory to store result plots and files. sections : list A list of subsections to use. name: str The name in the [executables] section of the configuration file to use. analysis_segs: {None, ligo.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 inference 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 # 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("--config-file", config_file) node.new_output_file_opt(analysis_seg, ".png", "--output-file") if sections is not None: node.add_opt("--sections", " ".join(sections)) # add node to workflow workflow += node return node.output_files
def make_singles_timefreq(workflow, single, bank_file, trig_time, out_dir, veto_file=None, time_window=10, data_segments=None, tags=None): """ Generate a singles_timefreq node and add it to workflow. This function generates a single node of the singles_timefreq executable and adds it to the current workflow. Parent/child relationships are set by the input/output files automatically. Parameters ----------- workflow: pycbc.workflow.core.Workflow The workflow class that stores the jobs that will be run. single: pycbc.workflow.core.File instance The File object storing the single-detector triggers to followup. bank_file: pycbc.workflow.core.File instance The File object storing the template bank. trig_time: int The time of the trigger being followed up. out_dir: str Location of directory to output to veto_file: File (optional, default=None) If given use this file to veto triggers to determine the loudest event. FIXME: Veto files *should* be provided a definer argument and not just assume that all segments should be read. time_window: int (optional, default=None) The amount of data (not including padding) that will be read in by the singles_timefreq job. The default value of 10s should be fine for most cases. data_segments: glue.segments.segmentlist (optional, default=None) The list of segments for which data exists and can be read in. If given the start/end times given to singles_timefreq will be adjusted if [trig_time - time_window, trig_time + time_window] does not completely lie within a valid data segment. A ValueError will be raised if the trig_time is not within a valid segment, or if it is not possible to find 2*time_window (plus the padding) of continuous data around the trigger. This **must** be coalesced. tags: list (optional, default=None) List of tags to add to the created nodes, which determine file naming. """ tags = [] if tags is None else tags makedir(out_dir) name = 'plot_singles_timefreq' curr_exe = PlotExecutable(workflow.cp, name, ifos=[single.ifo], out_dir=out_dir, tags=tags) node = curr_exe.create_node() node.add_input_opt('--trig-file', single) node.add_input_opt('--bank-file', bank_file) # Determine start/end times, using data segments if needed. # Begin by choosing "optimal" times start = trig_time - time_window end = trig_time + time_window # Then if data_segments is available, check against that, and move if # needed if data_segments is not None: # Assumes coalesced, so trig_time can only be within one segment for seg in data_segments: if trig_time in seg: data_seg = seg break else: err_msg = "Trig time {} ".format(trig_time) err_msg += "does not seem to lie within any data segments. " err_msg += "This shouldn't be possible, please ask for help!" raise ValueError(err_msg) # Check for pad-data if curr_exe.has_opt('pad-data'): pad_data = int(curr_exe.get_opt('pad-data')) else: pad_data = 0 if abs(data_seg) < (2 * time_window + 2 * pad_data): tl = 2 * time_window + 2 * pad_data err_msg = "I was asked to use {} seconds of data ".format(tl) err_msg += "to run a plot_singles_timefreq job. However, I have " err_msg += "only {} seconds available.".format(abs(data_seg)) raise ValueError(err_msg) if data_seg[0] > (start - pad_data): start = data_seg[0] + pad_data end = start + 2 * time_window if data_seg[1] < (end + pad_data): end = data_seg[1] - pad_data start = end - 2 * time_window # Sanity check, shouldn't get here! if data_seg[0] > (start - pad_data): err_msg = "I shouldn't be here! Go ask Ian what he broke." raise ValueError(err_msg) node.add_opt('--gps-start-time', int(start)) node.add_opt('--gps-end-time', int(end)) node.add_opt('--center-time', int(trig_time)) if veto_file: node.add_input_opt('--veto-file', veto_file) node.add_opt('--detector', single.ifo) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') workflow += node return node.output_files
def make_plot_waveform_plot(workflow, params, out_dir, ifos, exclude=None, require=None, tags=None): """ Add plot_waveform jobs to the workflow. """ tags = [] if tags is None else tags makedir(out_dir) name = 'single_template_plot' secs = requirestr(workflow.cp.get_subsections(name), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: node = PlotExecutable(workflow.cp, 'plot_waveform', ifos=ifos, out_dir=out_dir, tags=[tag] + tags).create_node() node.add_opt('--mass1', "%.6f" % params['mass1']) node.add_opt('--mass2', "%.6f" % params['mass2']) node.add_opt('--spin1z',"%.6f" % params['spin1z']) node.add_opt('--spin2z',"%.6f" % params['spin2z']) if params.has_key('u_vals'): # Precessing options node.add_opt('--spin1x',"%.6f" % params['spin1x']) node.add_opt('--spin2x',"%.6f" % params['spin2x']) node.add_opt('--spin1y',"%.6f" % params['spin1y']) node.add_opt('--spin2y',"%.6f" % params['spin2y']) node.add_opt('--inclination',"%.6f" % params['inclination']) node.add_opt('--u-val', "%.6f" % params['u_vals']) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') workflow += node files += node.output_files return files
def make_singles_timefreq(workflow, single, bank_file, start, end, out_dir, veto_file=None, tags=None): tags = [] if tags is None else tags makedir(out_dir) name = 'plot_singles_timefreq' node = PlotExecutable(workflow.cp, name, ifos=[single.ifo], out_dir=out_dir, tags=tags).create_node() node.add_input_opt('--trig-file', single) node.add_input_opt('--bank-file', bank_file) node.add_opt('--gps-start-time', int(start)) node.add_opt('--gps-end-time', int(end)) if veto_file: node.add_input_opt('--veto-file', veto_file) node.add_opt('--detector', single.ifo) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') workflow += node return node.output_files
def make_coinc_info(workflow, singles, bank, coinc, out_dir, n_loudest=None, trig_id=None, file_substring=None, tags=None): tags = [] if tags is None else tags makedir(out_dir) name = 'page_coincinfo' files = FileList([]) node = PlotExecutable(workflow.cp, name, ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_list_opt('--single-trigger-files', singles) node.add_input_opt('--statmap-file', coinc) node.add_input_opt('--bank-file', bank) if n_loudest is not None: node.add_opt('--n-loudest', str(n_loudest)) if trig_id is not None: node.add_opt('--trigger-id', str(trig_id)) if file_substring is not None: node.add_opt('--statmap-file-subspace-name', file_substring) node.new_output_file_opt(workflow.analysis_time, '.html', '--output-file') workflow += node files += node.output_files return files
def make_inference_plot(workflow, input_file, output_dir, name, analysis_seg=None, tags=None, input_file_opt='input-file', output_file_extension='.png', add_to_workflow=False): """Boiler-plate function for creating a standard plotting job. Parameters ---------- workflow: pycbc.workflow.Workflow The core workflow instance we are populating input_file: (list of) pycbc.workflow.File The file used for the input. May provide either a single file or a list of files. output_dir: str The directory to store result plots. name: str The name in the [executables] section of the configuration file to use. analysis_segs: ligo.segments.Segment, optional The segment this job encompasses. If None then use the total analysis time from the workflow. tags: list, optional Tags to add to the inference executables. input_file_opt : str, optional The name of the input-file option used by the executable. Default is ``input-file``. output_file_extension : str, optional What file type to create. Default is ``.png``. add_to_workflow : bool, optional If True, the node will be added to the workflow before being returned. **This means that no options may be added to the node afterward.** Default is ``False``. Returns ------- pycbc.workflow.plotting.PlotExecutable The job node for creating the plot. """ # default values if tags is None: tags = [] if analysis_seg is None: analysis_seg = workflow.analysis_time # make the directory that will contain the output files makedir(output_dir) # Catch if a parameters option was specified: # we need to do this because PlotExecutable will automatically add any # option in the section to the node. However, we need to add the # appropriate escapes to the parameters option so pegasus will render it # properly (see _params_for_pegasus for details). parameters = None if workflow.cp.has_option(name, 'parameters'): parameters = workflow.cp.get(name, 'parameters') workflow.cp.remove_option(name, 'parameters') # make a node for plotting the posterior as a corner plot node = PlotExecutable(workflow.cp, name, ifos=workflow.ifos, out_dir=output_dir, tags=tags).create_node() # add back the parameters option if it was specified if parameters is not None: node.add_opt("--parameters", _params_for_pegasus(parameters)) # and put the opt back in the config file in memory workflow.cp.set(name, 'parameters', parameters) # add input and output options if isinstance(input_file, list): # list of input files are given, use input_list_opt node.add_input_list_opt("--{}".format(input_file_opt), input_file) else: # assume just a single file node.add_input_opt("--{}".format(input_file_opt), input_file) node.new_output_file_opt(analysis_seg, output_file_extension, "--output-file") # add node to workflow if add_to_workflow: workflow += node return node
def make_coinc_info(workflow, singles, bank, coinc, num, out_dir, tags=None): tags = [] if tags is None else tags makedir(out_dir) name = 'page_coincinfo' files = FileList([]) node = PlotExecutable(workflow.cp, name, ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_list_opt('--single-trigger-files', singles) node.add_input_opt('--statmap-file', coinc) node.add_input_opt('--bank-file', bank) node.add_opt('--n-loudest', str(num)) node.new_output_file_opt(workflow.analysis_time, '.html', '--output-file') workflow += node files += node.output_files return files
def make_inference_single_parameter_plots(workflow, inference_file, output_dir, variable_args=None, samples_name="inference_samples", acf_name="inference_acf", acl_name="inference_acl", analysis_seg=None, tags=None): """ Sets up single-parameter plots for inference workflow. Parameters ---------- workflow: pycbc.workflow.Workflow The core workflow instance we are populating inference_file: pycbc.workflow.File The file with posterior samples. output_dir: str The directory to store result plots and files. variable_args : list A list of parameters to use instead of [variable_args]. samples_name: str The name in the [executables] section of the configuration file to use for the plot that shows all samples. acf_name: str The name in the [executables] section of the configuration file to use for the autocorrelation function plot. acl_name: str The name in the [executables] section of the configuration file to use for the autocorrelation length histogram. 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 inference 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 # 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: # plot posterior distribution corner_files = make_inference_posterior_plot(workflow, inference_file, output_dir, variable_args=[arg], analysis_seg=analysis_seg, tags=tags + [arg]) # make a node for plotting all the samples for each walker samples_node = PlotExecutable(workflow.cp, samples_name, ifos=workflow.ifos, out_dir=output_dir, tags=tags + [arg]).create_node() samples_node.add_input_opt("--input-file", inference_file) samples_node.new_output_file_opt(analysis_seg, ".png", "--output-file") samples_node.add_opt("--parameters", arg) # make node for plotting the autocorrelation function for each walker acf_node = PlotExecutable(workflow.cp, acf_name, ifos=workflow.ifos, out_dir=output_dir, tags=tags + [arg]).create_node() acf_node.add_input_opt("--input-file", inference_file) acf_node.new_output_file_opt(analysis_seg, ".png", "--output-file") acf_node.add_opt("--parameters", arg) # make node for plotting the autocorrelation function for each walker acl_node = PlotExecutable(workflow.cp, acl_name, ifos=workflow.ifos, out_dir=output_dir, tags=tags + [arg]).create_node() acl_node.add_input_opt("--input-file", inference_file) acl_node.new_output_file_opt(analysis_seg, ".png", "--output-file") acl_node.add_opt("--parameters", arg) # add nodes to workflow workflow += samples_node workflow += acf_node workflow += acl_node # add files to output files list files += corner_files files += samples_node.output_files files += acf_node.output_files files += acl_node.output_files return files
def make_plot_waveform_plot(workflow, params, out_dir, ifos, exclude=None, require=None, tags=None): """ Add plot_waveform jobs to the workflow. """ tags = [] if tags is None else tags makedir(out_dir) name = "single_template_plot" secs = requirestr(workflow.cp.get_subsections(name), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: node = PlotExecutable(workflow.cp, "plot_waveform", ifos=ifos, out_dir=out_dir, tags=[tag] + tags).create_node() node.add_opt("--mass1", "%.6f" % params["mass1"]) node.add_opt("--mass2", "%.6f" % params["mass2"]) node.add_opt("--spin1z", "%.6f" % params["spin1z"]) node.add_opt("--spin2z", "%.6f" % params["spin2z"]) if params.has_key("u_vals"): # Precessing options node.add_opt("--spin1x", "%.6f" % params["spin1x"]) node.add_opt("--spin2x", "%.6f" % params["spin2x"]) node.add_opt("--spin1y", "%.6f" % params["spin1y"]) node.add_opt("--spin2y", "%.6f" % params["spin2y"]) node.add_opt("--inclination", "%.6f" % params["inclination"]) node.add_opt("--u-val", "%.6f" % params["u_vals"]) node.new_output_file_opt(workflow.analysis_time, ".png", "--output-file") workflow += node files += node.output_files return files
def make_single_template_plots(workflow, segs, seg_name, coinc, bank, num, out_dir, exclude=None, require=None, tags=None): tags = [] if tags is None else tags makedir(out_dir) name = 'single_template_plot' secs = requirestr(workflow.cp.get_subsections(name), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: for ifo in workflow.ifos: # Reanalyze the time around the trigger in each detector node = PlotExecutable(workflow.cp, 'single_template', ifos=[ifo], out_dir=out_dir, tags=[tag] + tags).create_node() node.add_input_opt('--statmap-file', coinc) node.add_opt('--n-loudest', str(num)) node.add_input_opt('--inspiral-segments', segs[ifo]) node.add_opt('--segment-name', seg_name) node.add_input_opt('--bank-file', bank) node.new_output_file_opt(workflow.analysis_time, '.hdf', '--output-file') data = node.output_files[0] workflow += node # Make the plot for this trigger and detector node = PlotExecutable(workflow.cp, name, ifos=[ifo], out_dir=out_dir, tags=[tag] + tags).create_node() node.add_input_opt('--single-template-file', data) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') workflow += node files += node.output_files return files
def make_sngl_ifo(workflow, sngl_file, bank_file, trigger_id, out_dir, ifo, tags=None, rank=None): """Setup a job to create sngl detector sngl ifo html summary snippet. """ tags = [] if tags is None else tags makedir(out_dir) name = "page_snglinfo" files = FileList([]) node = PlotExecutable(workflow.cp, name, ifos=[ifo], out_dir=out_dir, tags=tags).create_node() node.add_input_opt("--single-trigger-file", sngl_file) node.add_input_opt("--bank-file", bank_file) node.add_opt("--trigger-id", str(trigger_id)) if rank is not None: node.add_opt("--n-loudest", str(rank)) node.add_opt("--instrument", ifo) node.new_output_file_opt(workflow.analysis_time, ".html", "--output-file") workflow += node files += node.output_files return files
def make_coinc_info(workflow, singles, bank, coinc, out_dir, n_loudest=None, trig_id=None, file_substring=None, sort_order=None, sort_var=None, tags=None): tags = [] if tags is None else tags makedir(out_dir) name = 'page_coincinfo' files = FileList([]) node = PlotExecutable(workflow.cp, name, ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_list_opt('--single-trigger-files', singles) node.add_input_opt('--statmap-file', coinc) node.add_input_opt('--bank-file', bank) if sort_order: node.add_opt('--sort-order', sort_order) if sort_var: node.add_opt('--sort-variable', sort_var) if n_loudest is not None: node.add_opt('--n-loudest', str(n_loudest)) if trig_id is not None: node.add_opt('--trigger-id', str(trig_id)) if file_substring is not None: node.add_opt('--statmap-file-subspace-name', file_substring) node.new_output_file_opt(workflow.analysis_time, '.html', '--output-file') workflow += node files += node.output_files return files
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
def make_plot_waveform_plot(workflow, params, out_dir, ifos, exclude=None, require=None, tags=None): """ Add plot_waveform jobs to the workflow. """ tags = [] if tags is None else tags makedir(out_dir) name = 'single_template_plot' secs = requirestr(workflow.cp.get_subsections(name), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: node = PlotExecutable(workflow.cp, 'plot_waveform', ifos=ifos, out_dir=out_dir, tags=[tag] + tags).create_node() node.add_opt('--mass1', "%.6f" % params['mass1']) node.add_opt('--mass2', "%.6f" % params['mass2']) node.add_opt('--spin1z',"%.6f" % params['spin1z']) node.add_opt('--spin2z',"%.6f" % params['spin2z']) if 'u_vals' in params: # Precessing options node.add_opt('--spin1x',"%.6f" % params['spin1x']) node.add_opt('--spin2x',"%.6f" % params['spin2x']) node.add_opt('--spin1y',"%.6f" % params['spin1y']) node.add_opt('--spin2y',"%.6f" % params['spin2y']) node.add_opt('--inclination',"%.6f" % params['inclination']) node.add_opt('--u-val', "%.6f" % params['u_vals']) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') workflow += node files += node.output_files return files
def make_sngl_ifo(workflow, sngl_file, bank_file, num, out_dir, ifo, veto_file=None, veto_segment_name=None, tags=None): """Setup a job to create sngl detector sngl ifo html summary snippet. """ tags = [] if tags is None else tags makedir(out_dir) name = 'page_snglinfo' files = FileList([]) node = PlotExecutable(workflow.cp, name, ifos=[ifo], out_dir=out_dir, tags=tags).create_node() node.add_input_opt('--single-trigger-file', sngl_file) node.add_input_opt('--bank-file', bank_file) if veto_file is not None: assert(veto_segment_name is not None) node.add_input_opt('--veto-file', veto_file) node.add_opt('--veto-segment-name', veto_segment_name) node.add_opt('--n-loudest', str(num)) node.add_opt('--instrument', ifo) node.new_output_file_opt(workflow.analysis_time, '.html', '--output-file') workflow += node files += node.output_files return files
def make_single_template_plots(workflow, segs, data_read_name, analyzed_name, params, out_dir, inj_file=None, exclude=None, require=None, tags=None, params_str=None, use_exact_inj_params=False): """Function for creating jobs to run the pycbc_single_template code and to run the associated plotting code pycbc_single_template_plots and add these jobs to the workflow. Parameters ----------- workflow : workflow.Workflow instance The pycbc.workflow.Workflow instance to add these jobs to. segs : workflow.File instance The pycbc.workflow.File instance that points to the XML file containing the segment lists of data read in and data analyzed. data_read_name : str The name of the segmentlist containing the data read in by each inspiral job in the segs file. analyzed_name : str The name of the segmentlist containing the data analyzed by each inspiral job in the segs file. params : dictionary A dictionary containing the parameters of the template to be used. params[ifo+'end_time'] is required for all ifos in workflow.ifos. If use_exact_inj_params is False then also need to supply values for [mass1, mass2, spin1z, spin2x]. For precessing templates one also needs to supply [spin1y, spin1x, spin2x, spin2y, inclination] additionally for precession one must supply u_vals or u_vals_+ifo for all ifos. u_vals is the ratio between h_+ and h_x to use when constructing h(t). h(t) = (h_+ * u_vals) + h_x. out_dir : str Directory in which to store the output files. inj_file : workflow.File (optional, default=None) If given send this injection file to the job so that injections are made into the data. exclude : list (optional, default=None) If given, then when considering which subsections in the ini file to parse for options to add to single_template_plot, only use subsections that *do not* match strings in this list. require : list (optional, default=None) If given, then when considering which subsections in the ini file to parse for options to add to single_template_plot, only use subsections matching strings in this list. tags : list (optional, default=None) Add this list of tags to all jobs. params_str : str (optional, default=None) If given add this string to plot title and caption to describe the template that was used. use_exact_inj_params : boolean (optional, default=False) If True do not use masses and spins listed in the params dictionary but instead use the injection closest to the filter time as a template. Returns -------- output_files : workflow.FileList The list of workflow.Files created in this function. """ tags = [] if tags is None else tags makedir(out_dir) name = 'single_template_plot' secs = requirestr(workflow.cp.get_subsections(name), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: for ifo in workflow.ifos: if params['%s_end_time' % ifo] == -1.0: continue # Reanalyze the time around the trigger in each detector node = SingleTemplateExecutable(workflow.cp, 'single_template', ifos=[ifo], out_dir=out_dir, tags=[tag] + tags).create_node() if use_exact_inj_params: node.add_opt('--use-params-of-closest-injection') else: node.add_opt('--mass1', "%.6f" % params['mass1']) node.add_opt('--mass2', "%.6f" % params['mass2']) node.add_opt('--spin1z',"%.6f" % params['spin1z']) node.add_opt('--spin2z',"%.6f" % params['spin2z']) node.add_opt('--template-start-frequency', "%.6f" % params['f_lower']) # Is this precessing? if 'u_vals' in params or 'u_vals_%s' % ifo in params: node.add_opt('--spin1x',"%.6f" % params['spin1x']) node.add_opt('--spin1y',"%.6f" % params['spin1y']) node.add_opt('--spin2x',"%.6f" % params['spin2x']) node.add_opt('--spin2y',"%.6f" % params['spin2y']) node.add_opt('--inclination',"%.6f" % params['inclination']) try: node.add_opt('--u-val',"%.6f" % params['u_vals']) except: node.add_opt('--u-val', "%.6f" % params['u_vals_%s' % ifo]) # str(numpy.float64) restricts to 2d.p. BE CAREFUL WITH THIS!!! str_trig_time = '%.6f' %(params[ifo + '_end_time']) node.add_opt('--trigger-time', str_trig_time) node.add_input_opt('--inspiral-segments', segs) if inj_file is not None: node.add_input_opt('--injection-file', inj_file) node.add_opt('--data-read-name', data_read_name) node.add_opt('--data-analyzed-name', analyzed_name) node.new_output_file_opt(workflow.analysis_time, '.hdf', '--output-file', store_file=False) data = node.output_files[0] workflow += node # Make the plot for this trigger and detector node = PlotExecutable(workflow.cp, name, ifos=[ifo], out_dir=out_dir, tags=[tag] + tags).create_node() node.add_input_opt('--single-template-file', data) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') title="'%s SNR and chi^2 timeseries" %(ifo) if params_str is not None: title+= " using %s" %(params_str) title+="'" node.add_opt('--plot-title', title) caption = "'The SNR and chi^2 timeseries around the injection" if params_str is not None: caption += " using %s" %(params_str) if use_exact_inj_params: caption += ". The injection itself was used as the template.'" else: caption += ". The template used has the following parameters: " caption += "mass1=%s, mass2=%s, spin1z=%s, spin2z=%s'"\ %(params['mass1'], params['mass2'], params['spin1z'], params['spin2z']) node.add_opt('--plot-caption', caption) workflow += node files += node.output_files return files
def make_single_template_plots(workflow, segs, seg_name, params, out_dir, inj_file=None, exclude=None, require=None, tags=None, params_str=None, use_exact_inj_params=False): tags = [] if tags is None else tags makedir(out_dir) name = 'single_template_plot' secs = requirestr(workflow.cp.get_subsections(name), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: for ifo in workflow.ifos: # Reanalyze the time around the trigger in each detector node = PlotExecutable(workflow.cp, 'single_template', ifos=[ifo], out_dir=out_dir, tags=[tag] + tags).create_node() if use_exact_inj_params: node.add_opt('--use-params-of-closest-injection') else: node.add_opt('--mass1', "%.6f" % params['mass1']) node.add_opt('--mass2', "%.6f" % params['mass2']) node.add_opt('--spin1z', "%.6f" % params['spin1z']) node.add_opt('--spin2z', "%.6f" % params['spin2z']) # str(numpy.float64) restricts to 2d.p. BE CAREFUL WITH THIS!!! str_trig_time = '%.6f' % (params[ifo + '_end_time']) node.add_opt('--trigger-time', str_trig_time) node.add_input_opt('--inspiral-segments', segs[ifo]) if inj_file is not None: node.add_input_opt('--injection-file', inj_file) node.add_opt('--segment-name', seg_name) node.new_output_file_opt(workflow.analysis_time, '.hdf', '--output-file', store_file=False) data = node.output_files[0] workflow += node # Make the plot for this trigger and detector node = PlotExecutable(workflow.cp, name, ifos=[ifo], out_dir=out_dir, tags=[tag] + tags).create_node() node.add_input_opt('--single-template-file', data) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') title = "'%s SNR and chi^2 timeseries" % (ifo) if params_str is not None: title += " using %s" % (params_str) title += "'" node.add_opt('--plot-title', title) caption = "'The SNR and chi^2 timeseries around the injection" if params_str is not None: caption += " using %s" % (params_str) if use_exact_inj_params: caption += ". The injection itself was used as the template.'" else: caption += ". The template used has the following parameters: " caption += "mass1=%s, mass2=%s, spin1z=%s, spin2z=%s'"\ %(params['mass1'], params['mass2'], params['spin1z'], params['spin2z']) node.add_opt('--plot-caption', caption) workflow += node files += node.output_files return files
def make_sngl_ifo(workflow, sngl_file, bank_file, num, out_dir, ifo, veto_file=None, veto_segment_name=None, tags=None): """Setup a job to create sngl detector sngl ifo html summary snippet. """ tags = [] if tags is None else tags makedir(out_dir) name = 'page_snglinfo' files = FileList([]) node = PlotExecutable(workflow.cp, name, ifos=[ifo], out_dir=out_dir, tags=tags).create_node() node.add_input_opt('--single-trigger-file', sngl_file) node.add_input_opt('--bank-file', bank_file) if veto_file is not None: assert (veto_segment_name is not None) node.add_input_opt('--veto-file', veto_file) node.add_opt('--veto-segment-name', veto_segment_name) node.add_opt('--n-loudest', str(num)) node.add_opt('--instrument', ifo) node.new_output_file_opt(workflow.analysis_time, '.html', '--output-file') workflow += node files += node.output_files return files
def make_single_template_plots(workflow, segs, seg_name, params, out_dir, inj_file=None, exclude=None, require=None, tags=None, params_str=None, use_exact_inj_params=False): tags = [] if tags is None else tags makedir(out_dir) name = 'single_template_plot' secs = requirestr(workflow.cp.get_subsections(name), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: for ifo in workflow.ifos: # Reanalyze the time around the trigger in each detector node = PlotExecutable(workflow.cp, 'single_template', ifos=[ifo], out_dir=out_dir, tags=[tag] + tags).create_node() if use_exact_inj_params: node.add_opt('--use-params-of-closest-injection') else: node.add_opt('--mass1', "%.6f" % params['mass1']) node.add_opt('--mass2', "%.6f" % params['mass2']) node.add_opt('--spin1z',"%.6f" % params['spin1z']) node.add_opt('--spin2z',"%.6f" % params['spin2z']) # str(numpy.float64) restricts to 2d.p. BE CAREFUL WITH THIS!!! str_trig_time = '%.6f' %(params[ifo + '_end_time']) node.add_opt('--trigger-time', str_trig_time) node.add_input_opt('--inspiral-segments', segs) if inj_file is not None: node.add_input_opt('--injection-file', inj_file) node.add_opt('--segment-name', seg_name) node.new_output_file_opt(workflow.analysis_time, '.hdf', '--output-file', store_file=False) data = node.output_files[0] workflow += node # Make the plot for this trigger and detector node = PlotExecutable(workflow.cp, name, ifos=[ifo], out_dir=out_dir, tags=[tag] + tags).create_node() node.add_input_opt('--single-template-file', data) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') title="'%s SNR and chi^2 timeseries" %(ifo) if params_str is not None: title+= " using %s" %(params_str) title+="'" node.add_opt('--plot-title', title) caption = "'The SNR and chi^2 timeseries around the injection" if params_str is not None: caption += " using %s" %(params_str) if use_exact_inj_params: caption += ". The injection itself was used as the template.'" else: caption += ". The template used has the following parameters: " caption += "mass1=%s, mass2=%s, spin1z=%s, spin2z=%s'"\ %(params['mass1'], params['mass2'], params['spin1z'], params['spin2z']) node.add_opt('--plot-caption', caption) workflow += node files += node.output_files return files
def make_sngl_ifo(workflow, sngl_file, bank_file, trigger_id, out_dir, ifo, tags=None): """Setup a job to create sngl detector sngl ifo html summary snippet. """ tags = [] if tags is None else tags makedir(out_dir) name = 'page_snglinfo' files = FileList([]) node = PlotExecutable(workflow.cp, name, ifos=[ifo], out_dir=out_dir, tags=tags).create_node() node.add_input_opt('--single-trigger-file', sngl_file) node.add_input_opt('--bank-file', bank_file) node.add_opt('--trigger-id', str(trigger_id)) node.add_opt('--instrument', ifo) node.new_output_file_opt(workflow.analysis_time, '.html', '--output-file') workflow += node files += node.output_files return files