def make_veto_table(workflow, out_dir, vetodef_file=None, tags=None): """ Creates a node in the workflow for writing the veto_definer table. Returns a File instances for the output file. """ if vetodef_file is None: if not workflow.cp.has_option_tags("workflow-segments", "segments-veto-definer-file", []): return None vetodef_file = workflow.cp.get_opt_tags("workflow-segments", "segments-veto-definer-file", []) file_url = urljoin('file:', pathname2url(vetodef_file)) vdf_file = File(workflow.ifos, 'VETO_DEFINER', workflow.analysis_time, file_url=file_url) vdf_file.add_pfn(file_url, site='local') else: vdf_file = vetodef_file if tags is None: tags = [] makedir(out_dir) node = PlotExecutable(workflow.cp, 'page_vetotable', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_opt('--veto-definer-file', vdf_file) node.new_output_file_opt(workflow.analysis_time, '.html', '--output-file') workflow += node return node.output_files[0]
def render_workflow_html_template(filename, subtemplate, filelists, **kwargs): """ Writes a template given inputs from the workflow generator. Takes a list of tuples. Each tuple is a pycbc File object. Also the name of the subtemplate to render and the filename of the output. """ dirnam = os.path.dirname(filename) makedir(dirnam) try: filenames = [f.name for filelist in filelists for f in filelist if f is not None] except TypeError: filenames = [] # render subtemplate subtemplate_dir = pycbc.results.__path__[0] + '/templates/wells' env = Environment(loader=FileSystemLoader(subtemplate_dir)) env.globals.update(get_embedded_config=get_embedded_config) env.globals.update(path_exists=os.path.exists) env.globals.update(len=len) subtemplate = env.get_template(subtemplate) context = {'filelists' : filelists, 'dir' : dirnam} context.update(kwargs) output = subtemplate.render(context) # save as html page kwds = {'render-function' : 'render_tmplt', 'filenames' : ','.join(filenames)} save_html_with_metadata(str(output), filename, None, kwds)
def make_ifar_plot(workflow, trigger_file, out_dir, tags=None, hierarchical_level=None, executable='page_ifar'): """ Creates a node in the workflow for plotting cumulative histogram of IFAR values. """ if hierarchical_level is not None and tags: tags = [("HIERARCHICAL_LEVEL_{:02d}".format(hierarchical_level)) ] + tags elif hierarchical_level is not None and not tags: tags = ["HIERARCHICAL_LEVEL_{:02d}".format(hierarchical_level)] elif hierarchical_level is None and not tags: tags = [] makedir(out_dir) exe = PlotExecutable(workflow.cp, executable, ifos=trigger_file.ifo_list, out_dir=out_dir, tags=tags) node = exe.create_node() node.add_input_opt('--trigger-file', trigger_file) if hierarchical_level is not None: node.add_opt('--use-hierarchical-level', hierarchical_level) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') workflow += node return node.output_files[0]
def make_gating_plot(workflow, insp_files, out_dir, tags=[]): makedir(out_dir) node = PlotExecutable(workflow.cp, 'plot_gating', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_list_opt('--input-file', insp_files) node.new_output_file_opt(workflow.analysis_time, '.html', '--output-file') workflow += node
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_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, 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 ------- 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_coinc_info(workflow, singles, bank, coinc, num, out_dir, exclude=None, require=None, tags=None): tags = [] if tags is None else tags makedir(out_dir) name = 'page_coincinfo' secs = requirestr(workflow.cp.get_subsections(name), require) secs = excludestr(secs, exclude) 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_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_single_hist(workflow, trig_file, veto_file, veto_name, out_dir, exclude=None, require=None, tags=[]): makedir(out_dir) secs = requirestr(workflow.cp.get_subsections('plot_hist'), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: node = PlotExecutable(workflow.cp, 'plot_hist', ifos=trig_file.ifo, out_dir=out_dir, tags=[tag] + tags).create_node() node.add_opt('--segment-name', veto_name) node.add_input_opt('--veto-file', veto_file) node.add_input_opt('--trigger-file', trig_file) node.new_output_file_opt(trig_file.segment, '.png', '--output-file') workflow += node files += node.output_files return files
def make_throughput_plot(workflow, insp_files, out_dir, tags=None): tags = [] if tags is None else tags makedir(out_dir) node = PlotExecutable(workflow.cp, "plot_throughput", ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_list_opt("--input-file", insp_files) node.new_output_file_opt(workflow.analysis_time, ".png", "--output-file") workflow += node
def make_segments_plot(workflow, seg_files, out_dir, tags=None): tags = [] if tags is None else tags makedir(out_dir) node = PlotExecutable(workflow.cp, "plot_segments", ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_list_opt("--segment-files", seg_files) node.new_output_file_opt(workflow.analysis_time, ".html", "--output-file") workflow += node
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_snrifar_plot(workflow, bg_file, out_dir, tags=[]): makedir(out_dir) node = PlotExecutable(workflow.cp, 'plot_snrifar', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_opt('--trigger-file', bg_file) node.new_output_file_opt(bg_file.segment, '.png', '--output-file') workflow += node
def make_foreground_table(workflow, trig_file, bank_file, out_dir, singles=None, extension='.html', tags=None, hierarchical_level=None): if hierarchical_level is not None and tags: tags = [("HIERARCHICAL_LEVEL_{:02d}".format(hierarchical_level)) ] + tags elif hierarchical_level is not None and not tags: tags = ["HIERARCHICAL_LEVEL_{:02d}".format(hierarchical_level)] elif hierarchical_level is None and not tags: tags = [] makedir(out_dir) exe = PlotExecutable(workflow.cp, 'page_foreground', ifos=trig_file.ifo_list, out_dir=out_dir, tags=tags) node = exe.create_node() node.add_input_opt('--bank-file', bank_file) node.add_input_opt('--trigger-file', trig_file) if hierarchical_level is not None: node.add_opt('--use-hierarchical-level', hierarchical_level) if singles is not None: node.add_input_list_opt('--single-detector-triggers', singles) node.new_output_file_opt(bank_file.segment, extension, '--output-file') workflow += node return node.output_files[0]
def make_foundmissed_plot(workflow, inj_file, out_dir, exclude=None, require=None, tags=None): if tags is None: tags = [] makedir(out_dir) secs = requirestr(workflow.cp.get_subsections('plot_foundmissed'), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: exe = PlotExecutable(workflow.cp, 'plot_foundmissed', ifos=workflow.ifos, out_dir=out_dir, tags=[tag] + tags) node = exe.create_node() ext = '.html' if exe.has_opt('dynamic') else '.png' node.add_input_opt('--injection-file', inj_file) node.new_output_file_opt(inj_file.segment, ext, '--output-file') workflow += node files += node.output_files return files
def make_coinc_snrchi_plot(workflow, inj_file, inj_trig, stat_file, trig_file, out_dir, exclude=None, require=None, tags=None): tags = [] if tags is None else tags makedir(out_dir) secs = requirestr(workflow.cp.get_subsections('plot_coinc_snrchi'), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: exe = PlotExecutable(workflow.cp, 'plot_coinc_snrchi', ifos=inj_trig.ifo_list, out_dir=out_dir, tags=[tag] + tags) node = exe.create_node() node.add_input_opt('--found-injection-file', inj_file) node.add_input_opt('--single-injection-file', inj_trig) node.add_input_opt('--coinc-statistic-file', stat_file) node.add_input_opt('--single-trigger-file', trig_file) node.new_output_file_opt(inj_file.segment, '.png', '--output-file') workflow += node files += 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_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_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
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_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_singles_plot(workflow, trig_files, bank_file, veto_file, veto_name, out_dir, exclude=None, require=None, tags=None): tags = [] if tags is None else tags makedir(out_dir) secs = requirestr(workflow.cp.get_subsections('plot_singles'), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: for trig_file in trig_files: node = PlotExecutable(workflow.cp, 'plot_singles', ifos=trig_file.ifo, out_dir=out_dir, tags=[tag] + tags).create_node() node.set_memory(15000) node.add_input_opt('--bank-file', bank_file) if veto_file is not None: node.add_input_opt('--veto-file', veto_file) node.add_opt('--segment-name', veto_name) node.add_opt('--detector', trig_file.ifo) node.add_input_opt('--single-trig-file', trig_file) node.new_output_file_opt(trig_file.segment, '.png', '--output-file') workflow += node files += node.output_files return files
def make_seg_table(workflow, seg_files, seg_names, out_dir, tags=None, title_text=None, description=None): """ Creates a node in the workflow for writing the segment summary table. Returns a File instances for the output file. """ seg_files = list(seg_files) seg_names = list(seg_names) if tags is None: tags = [] makedir(out_dir) node = PlotExecutable(workflow.cp, 'page_segtable', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_list_opt('--segment-files', seg_files) quoted_seg_names = [] for s in seg_names: quoted_seg_names.append("'" + s + "'") node.add_opt('--segment-names', ' '.join(quoted_seg_names)) node.add_opt('--ifos', ' '.join(workflow.ifos)) if description: node.add_opt('--description', "'" + description + "'") if title_text: node.add_opt('--title-text', "'" + title_text + "'") node.new_output_file_opt(workflow.analysis_time, '.html', '--output-file') workflow += node return node.output_files[0]
def make_foreground_table(workflow, trig_file, bank_file, ftag, out_dir, singles=None, extension='.html', tags=None, hierarchical_level=None): if hierarchical_level is not None and tags: tags = [("HIERARCHICAL_LEVEL_{:02d}".format( hierarchical_level))] + tags elif hierarchical_level is not None and not tags: tags = ["HIERARCHICAL_LEVEL_{:02d}".format(hierarchical_level)] elif hierarchical_level is None and not tags: tags = [] makedir(out_dir) node = PlotExecutable(workflow.cp, 'page_foreground', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_opt('--bank-file', bank_file) node.add_opt('--foreground-tag', ftag) node.add_input_opt('--trigger-file', trig_file) if hierarchical_level is not None: node.add_opt('--use-hierarchical-level', hierarchical_level) if singles is not None: node.add_input_list_opt('--single-detector-triggers', singles) node.new_output_file_opt(bank_file.segment, extension, '--output-file') workflow += node return node.output_files[0]
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_snrratehist_plot(workflow, bg_file, out_dir, closed_box=False, tags=None, hierarchical_level=None): if hierarchical_level is not None and tags: tags = [("HIERARCHICAL_LEVEL_{:02d}".format(hierarchical_level)) ] + tags elif hierarchical_level is not None and not tags: tags = ["HIERARCHICAL_LEVEL_{:02d}".format(hierarchical_level)] elif hierarchical_level is None and not tags: tags = [] makedir(out_dir) exe = PlotExecutable(workflow.cp, 'plot_snrratehist', ifos=bg_file.ifo_list, out_dir=out_dir, tags=tags) node = exe.create_node() node.add_input_opt('--trigger-file', bg_file) if hierarchical_level is not None: node.add_opt('--use-hierarchical-level', hierarchical_level) if closed_box: node.add_opt('--closed-box') node.new_output_file_opt(bg_file.segment, '.png', '--output-file') workflow += node return node.output_files[0]
def make_inj_table(workflow, inj_file, out_dir, tags=[]): makedir(out_dir) node = PlotExecutable(workflow.cp, 'page_injections', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_opt('--injection-file', inj_file) node.new_output_file_opt(inj_file.segment, '.html', '--output-file') workflow += node
def make_snrchi_plot(workflow, trig_files, veto_file, veto_name, out_dir, exclude=None, require=None, tags=None): tags = [] if tags is None else tags makedir(out_dir) secs = requirestr(workflow.cp.get_subsections('plot_snrchi'), require) secs = excludestr(secs, exclude) files = FileList([]) for tag in secs: for trig_file in trig_files: exe = PlotExecutable(workflow.cp, 'plot_snrchi', ifos=trig_file.ifo_list, out_dir=out_dir, tags=[tag] + tags) node = exe.create_node() node.add_input_opt('--trigger-file', trig_file) if veto_file is not None: node.add_input_opt('--veto-file', veto_file) node.add_opt('--segment-name', veto_name) node.new_output_file_opt(trig_file.segment, '.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_snrifar_plot(workflow, bg_file, out_dir, closed_box=False, cumulative=True, tags=None, hierarchical_level=None): if hierarchical_level is not None and tags: tags = [("HIERARCHICAL_LEVEL_{:02d}".format( hierarchical_level))] + tags elif hierarchical_level is not None and not tags: tags = ["HIERARCHICAL_LEVEL_{:02d}".format(hierarchical_level)] elif hierarchical_level is None and not tags: tags = [] makedir(out_dir) node = PlotExecutable(workflow.cp, 'plot_snrifar', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_opt('--trigger-file', bg_file) if hierarchical_level is not None: node.add_opt('--use-hierarchical-level', hierarchical_level) if closed_box: node.add_opt('--closed-box') if not cumulative: node.add_opt('--not-cumulative') node.new_output_file_opt(bg_file.segment, '.png', '--output-file') workflow += node return node.output_files[0]
def make_segments_plot(workflow, seg_files, out_dir, tags=[]): makedir(out_dir) node = PlotExecutable(workflow.cp, 'plot_segments', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_list_opt('--segment-files', seg_files) node.new_output_file_opt(workflow.analysis_time, '.html', '--output-file') workflow += node
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): 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('--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_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_sensitivity_plot(workflow, inj_file, out_dir, tags=[]): makedir(out_dir) for tag in workflow.cp.get_subsections('plot_sensitivity'): node = PlotExecutable(workflow.cp, 'plot_sensitivity', ifos=workflow.ifos, out_dir=out_dir, tags=[tag] + tags).create_node() node.add_input_opt('--injection-file', inj_file) node.new_output_file_opt(inj_file.segment, '.png', '--output-file') workflow += node
def make_gating_plot(workflow, insp_files, out_dir, tags=None): tags = [] if tags is None else tags makedir(out_dir) node = PlotExecutable(workflow.cp, 'plot_gating', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_list_opt('--input-file', insp_files) node.new_output_file_opt(workflow.analysis_time, '.html', '--output-file') workflow += node
def make_segments_plot(workflow, seg_files, out_dir, tags=None): tags = [] if tags is None else tags makedir(out_dir) node = PlotExecutable(workflow.cp, 'plot_segments', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_list_opt('--segment-files', seg_files) node.new_output_file_opt(workflow.analysis_time, '.html', '--output-file') workflow += node
def make_spectrum_plot(workflow, psd_files, out_dir, tags=None): tags = [] if tags is None else tags makedir(out_dir) node = PlotExecutable(workflow.cp, "plot_spectrum", ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_list_opt("--psd-files", psd_files) node.new_output_file_opt(workflow.analysis_time, ".png", "--output-file") workflow += node return node.output_files[0]
def make_throughput_plot(workflow, insp_files, out_dir, tags=None): tags = [] if tags is None else tags makedir(out_dir) node = PlotExecutable(workflow.cp, 'plot_throughput', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_list_opt('--input-file', insp_files) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') workflow += node
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_summary_table(workflow, inference_file, output_dir, variable_args=None, name="inference_table", 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. 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, 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, tags=tags).create_node() # add command line options node.add_input_opt("--input-file", inference_file) node.new_output_file_opt(analysis_seg, ".html", "--output-file") node.add_opt("--parameters", " ".join(variable_args)) # add node to workflow workflow += node return node.output_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_results_web_page(workflow, results_dir): template_path = "templates/orange.html" out_dir = workflow.cp.get("results_page", "output-path") makedir(out_dir) node = PlotExecutable(workflow.cp, "results_page", ifos=workflow.ifos, out_dir=out_dir).create_node() node.add_opt("--plots-dir", results_dir) node.add_opt("--template-file", template_path) workflow += node
def make_range_plot(workflow, psd_files, out_dir, tags=None): tags = [] if tags is None else tags makedir(out_dir) node = PlotExecutable(workflow.cp, 'plot_range', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_list_opt('--psd-files', psd_files) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') workflow += node return node.output_files[0]
def make_foreground_table(workflow, trig_file, bank_file, ftag, out_dir, tags=[]): makedir(out_dir) node = PlotExecutable(workflow.cp, 'page_foreground', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_opt('--bank-file', bank_file) node.add_opt('--foreground-tag', ftag) node.add_input_opt('--trigger-file', trig_file) node.new_output_file_opt(bank_file.segment, '.html', '--output-file') workflow += node
def make_foundmissed_plot(workflow, inj_file, out_dir, tags=[]): makedir(out_dir) for tag in workflow.cp.get_subsections('plot_foundmissed'): exe = PlotExecutable(workflow.cp, 'plot_foundmissed', ifos=workflow.ifos, out_dir=out_dir, tags=[tag] + tags) node = exe.create_node() ext = '.html' if exe.has_opt('dynamic') else '.png' node.add_input_opt('--injection-file', inj_file) node.new_output_file_opt(inj_file.segment, ext, '--output-file') workflow += node
def make_results_web_page(workflow, results_dir): template_path = 'templates/orange.html' out_dir = workflow.cp.get('results_page', 'output-path') makedir(out_dir) node = PlotExecutable(workflow.cp, 'results_page', ifos=workflow.ifos, out_dir=out_dir).create_node() node.add_opt('--plots-dir', results_dir) node.add_opt('--template-file', template_path) workflow += node
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_results_web_page(workflow, results_dir): import pycbc.results template_path = pycbc.results.__path__[0] + '/templates/concrete.html' out_dir = workflow.cp.get('results_page', 'output-path') makedir(out_dir) node = PlotExecutable(workflow.cp, 'results_page', ifos=workflow.ifos, out_dir=out_dir).create_node() node.add_opt('--plots-dir', results_dir) node.add_opt('--template-file', template_path) workflow += node
def make_coinc_snrchi_plot(workflow, inj_file, inj_trig, stat_file, trig_file, out_dir, tags=[]): makedir(out_dir) for tag in workflow.cp.get_subsections('plot_coinc_snrchi'): node = PlotExecutable(workflow.cp, 'plot_coinc_snrchi', ifos=inj_trig.ifo, out_dir=out_dir, tags=[tag] + tags).create_node() node.add_input_opt('--found-injection-file', inj_file) node.add_input_opt('--single-injection-file', inj_trig) node.add_input_opt('--coinc-statistic-file', stat_file) node.add_input_opt('--single-trigger-file', trig_file) node.new_output_file_opt(inj_file.segment, '.png', '--output-file') workflow += node
def make_snrifar_plot(workflow, bg_file, out_dir, closed_box=False, tags=[]): makedir(out_dir) node = PlotExecutable(workflow.cp, "plot_snrifar", ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_opt("--trigger-file", bg_file) if closed_box: node.add_opt("--closed-box") node.new_output_file_opt(bg_file.segment, ".png", "--output-file") workflow += node return node.output_files[0]
def make_snrratehist_plot(workflow, bg_file, out_dir, closed_box=False, tags=[]): makedir(out_dir) node = PlotExecutable(workflow.cp, 'plot_snrratehist', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_opt('--trigger-file', bg_file) if closed_box: node.add_opt('--closed-box') node.new_output_file_opt(bg_file.segment, '.png', '--output-file') workflow += node return node.output_files[0]
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_spectrum_plot(workflow, psd_files, out_dir, tags=None, precalc_psd_files=None): tags = [] if tags is None else tags makedir(out_dir) node = PlotExecutable(workflow.cp, 'plot_spectrum', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_list_opt('--psd-files', psd_files) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') if precalc_psd_files is not None and len(precalc_psd_files) == 1: node.add_input_list_opt('--psd-file', precalc_psd_files) workflow += node return node.output_files[0]
def make_inj_table(workflow, inj_file, out_dir, missed=False, tags=[]): makedir(out_dir) node = PlotExecutable(workflow.cp, 'page_injections', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_opt('--injection-file', inj_file) if missed: node.add_opt('--show-missed') node.new_output_file_opt(inj_file.segment, '.html', '--output-file') workflow += node return node.output_files[0]
def make_ifar_plot(workflow, trigger_file, out_dir, tags=None): """ Creates a node in the workflow for plotting cumlative histogram of IFAR values. """ if tags is None: tags = [] makedir(out_dir) node = PlotExecutable(workflow.cp, 'page_ifar', ifos=workflow.ifos, out_dir=out_dir, tags=tags).create_node() node.add_input_opt('--trigger-file', trigger_file) node.new_output_file_opt(workflow.analysis_time, '.png', '--output-file') workflow += node return node.output_files[0]