def save_veto_definer(cp, out_dir, tags=None): """ Retrieve the veto definer file and save it locally Parameters ----------- cp : ConfigParser instance out_dir : path tags : list of strings Used to retrieve subsections of the ini file for configuration options. """ if tags is None: tags = [] make_analysis_dir(out_dir) veto_def_url = cp.get_opt_tags("workflow-segments", "segments-veto-definer-url", tags) veto_def_base_name = os.path.basename(veto_def_url) veto_def_new_path = os.path.abspath( os.path.join(out_dir, veto_def_base_name)) # Don't need to do this if already done resolve_url(veto_def_url, out_dir) # and update location cp.set("workflow-segments", "segments-veto-definer-file", veto_def_new_path) return veto_def_new_path
def setup_psd_pregenerated(workflow, tags=None): ''' Setup CBC workflow to use pregenerated psd files. The file given in cp.get('workflow','pregenerated-psd-file-(ifo)') will be used as the --psd-file argument to geom_nonspinbank, geom_aligned_bank and pycbc_plot_psd_file. Parameters ---------- workflow: pycbc.workflow.core.Workflow An instanced class that manages the constructed workflow. tags : list of strings If given these tags are used to uniquely name and identify output files that would be produced in multiple calls to this function. Returns -------- psd_files : pycbc.workflow.core.FileList The FileList holding the gating files ''' if tags is None: tags = [] psd_files = FileList([]) cp = workflow.cp global_seg = workflow.analysis_time user_tag = "PREGEN_PSD" # Check for one psd for all ifos try: pre_gen_file = cp.get_opt_tags('workflow-psd', 'psd-pregenerated-file', tags) pre_gen_file = resolve_url(pre_gen_file) file_url = urljoin('file:', pathname2url(pre_gen_file)) curr_file = File(workflow.ifos, user_tag, global_seg, file_url, tags=tags) curr_file.PFN(file_url, site='local') psd_files.append(curr_file) except ConfigParser.Error: # Check for one psd per ifo for ifo in workflow.ifos: try: pre_gen_file = cp.get_opt_tags('workflow-psd', 'psd-pregenerated-file-%s' % ifo.lower(), tags) pre_gen_file = resolve_url(pre_gen_file) file_url = urljoin('file:', pathname2url(pre_gen_file)) curr_file = File(ifo, user_tag, global_seg, file_url, tags=tags) curr_file.PFN(file_url, site='local') psd_files.append(curr_file) except ConfigParser.Error: # It's unlikely, but not impossible, that only some ifos # will have pregenerated PSDs logging.warn("No psd file specified for IFO %s." % (ifo,)) pass return psd_files
def setup_psd_pregenerated(workflow, tags=[]): ''' Setup CBC workflow to use pregenerated psd files. The file given in cp.get('workflow','pregenerated-psd-file-(ifo)') will be used as the --psd-file argument to geom_nonspinbank, geom_aligned_bank and pycbc_plot_psd_file. Parameters ---------- workflow: pycbc.workflow.core.Workflow An instanced class that manages the constructed workflow. tags : list of strings If given these tags are used to uniquely name and identify output files that would be produced in multiple calls to this function. Returns -------- psd_files : pycbc.workflow.core.FileList The FileList holding the gating files ''' psd_files = FileList([]) cp = workflow.cp global_seg = workflow.analysis_time user_tag = "PREGEN_PSD" # Check for one psd for all ifos try: pre_gen_file = cp.get_opt_tags('workflow-psd', 'psd-pregenerated-file', tags) pre_gen_file = resolve_url(pre_gen_file) file_url = urlparse.urljoin('file:', urllib.pathname2url(pre_gen_file)) curr_file = File(workflow.ifos, user_tag, global_seg, file_url, tags=tags) curr_file.PFN(file_url, site='local') psd_files.append(curr_file) except ConfigParser.Error: # Check for one psd per ifo for ifo in workflow.ifos: try: pre_gen_file = cp.get_opt_tags('workflow-psd', 'psd-pregenerated-file-%s' % ifo.lower(), tags) pre_gen_file = resolve_url(pre_gen_file) file_url = urlparse.urljoin('file:', urllib.pathname2url(pre_gen_file)) curr_file = File(ifo, user_tag, global_seg, file_url, tags=tags) curr_file.PFN(file_url, site='local') psd_files.append(curr_file) except ConfigParser.Error: # It's unlikely, but not impossible, that only some ifos # will have pregenerated PSDs logging.warn("No psd file specified for IFO %s." % (ifo,)) pass return psd_files
def get_ipn_sky_files(workflow, file_url, tags=None): ''' Retreive the sky point files for searching over the IPN error box and populating it with injections. Parameters ---------- workflow: pycbc.workflow.core.Workflow An instanced class that manages the constructed workflow. file_url : string The URL of the IPN sky points file. tags : list of strings If given these tags are used to uniquely name and identify output files that would be produced in multiple calls to this function. Returns -------- sky_points_file : pycbc.workflow.core.File File object representing the IPN sky points file. ''' tags = tags or [] ipn_sky_points = resolve_url(file_url) sky_points_url = urlparse.urljoin("file:", urllib.pathname2url(ipn_sky_points)) sky_points_file = File(workflow.ifos, "IPN_SKY_POINTS", workflow.analysis_time, file_url=sky_points_url, tags=tags) sky_points_file.PFN(sky_points_url, site="local") return sky_points_file
def get_ipn_sky_files(workflow, tags=None): ''' Retreive the sky point files for searching over the IPN error box and populating it with injections. Parameters ---------- workflow: pycbc.workflow.core.Workflow An instanced class that manages the constructed workflow. tags : list of strings If given these tags are used to uniquely name and identify output files that would be produced in multiple calls to this function. Returns -------- cp : pycbc.workflow.core.Workflow The parsed configuration options for the workflow ipn_files : pycbc.workflow.core.FileList FileList holding the details of the IPN sky point files. ''' if tags is None: tags = [] cp = workflow.cp ipn_search_points = cp.get("workflow-inspiral", "ipn-search-points") ipn_search_points = resolve_url(ipn_search_points) search_points_url = urlparse.urljoin( "file:", urllib.pathname2url(ipn_search_points)) search_points_file = File(workflow.ifos, "SEARCH_POINTS", workflow.analysis_time, file_url=search_points_url, tags=tags) search_points_file.PFN(search_points_url, site="local") ipn_sim_points = cp.get("workflow-injections", "ipn-sim-points") ipn_sim_points = resolve_url(ipn_sim_points) sim_points_url = urlparse.urljoin("file:", urllib.pathname2url(ipn_sim_points)) sim_points_file = File(workflow.ifos, "SIM_POINTS", workflow.analysis_time, file_url=sim_points_url, tags=tags) sim_points_file.PFN(sim_points_url, site="local") return search_points_file, sim_points_file
def get_ipn_sky_files(workflow, tags=None): ''' Retreive the sky point files for searching over the IPN error box and populating it with injections. Parameters ---------- workflow: pycbc.workflow.core.Workflow An instanced class that manages the constructed workflow. tags : list of strings If given these tags are used to uniquely name and identify output files that would be produced in multiple calls to this function. Returns -------- cp : pycbc.workflow.core.Workflow The parsed configuration options for the workflow ipn_files : pycbc.workflow.core.FileList FileList holding the details of the IPN sky point files. ''' if tags is None: tags = [] cp = workflow.cp ipn_search_points = cp.get("workflow-inspiral", "ipn-search-points") ipn_search_points = resolve_url(ipn_search_points) search_points_url = urlparse.urljoin("file:", urllib.pathname2url(ipn_search_points)) search_points_file = File(workflow.ifos, "SEARCH_POINTS", workflow.analysis_time, file_url=search_points_url, tags=tags) search_points_file.PFN(search_points_url, site="local") ipn_sim_points = cp.get("workflow-injections", "ipn-sim-points") ipn_sim_points = resolve_url(ipn_sim_points) sim_points_url = urlparse.urljoin("file:", urllib.pathname2url(ipn_sim_points)) sim_points_file = File(workflow.ifos, "SIM_POINTS", workflow.analysis_time, file_url=sim_points_url, tags=tags) sim_points_file.PFN(sim_points_url, site="local") return search_points_file, sim_points_file
def setup_gate_pregenerated(workflow, output_dir=None, tags=None): ''' Setup CBC workflow to use pregenerated gating files. The file given in cp.get('workflow','gating-file-(ifo)') will be used as the --gating-file for all jobs for that ifo. Parameters ---------- workflow: pycbc.workflow.core.Workflow An instanced class that manages the constructed workflow. output_dir : path string The directory where data products will be placed. tags : list of strings If given these tags are used to uniquely name and identify output files that would be produced in multiple calls to this function. Returns -------- gate_files : pycbc.workflow.core.FileList The FileList holding the gating files ''' if tags is None: tags = [] gate_files = FileList([]) cp = workflow.cp global_seg = workflow.analysis_time user_tag = "PREGEN_GATE" for ifo in workflow.ifos: try: pre_gen_file = cp.get_opt_tags('workflow-gating', 'gating-file-%s' % ifo.lower(), tags) pre_gen_file = resolve_url(pre_gen_file, os.path.join(os.getcwd(),output_dir)) file_url = urlparse.urljoin('file:', urllib.pathname2url(pre_gen_file)) curr_file = File(ifo, user_tag, global_seg, file_url, tags=tags) curr_file.PFN(file_url, site='local') gate_files.append(curr_file) logging.info("Using gating file %s for %s", file_url, ifo) except ConfigParser.Error: logging.info("No gating file specified for %s", ifo) return gate_files
def setup_gate_pregenerated(workflow, output_dir=None, tags=None): ''' Setup CBC workflow to use pregenerated gating files. The file given in cp.get('workflow','gating-file-(ifo)') will be used as the --gating-file for all jobs for that ifo. Parameters ---------- workflow: pycbc.workflow.core.Workflow An instanced class that manages the constructed workflow. output_dir : path string The directory where data products will be placed. tags : list of strings If given these tags are used to uniquely name and identify output files that would be produced in multiple calls to this function. Returns -------- gate_files : pycbc.workflow.core.FileList The FileList holding the gating files ''' if tags is None: tags = [] gate_files = FileList([]) cp = workflow.cp global_seg = workflow.analysis_time user_tag = "PREGEN_GATE" for ifo in workflow.ifos: try: pre_gen_file = cp.get_opt_tags('workflow-gating', 'gating-file-%s' % ifo.lower(), tags) pre_gen_file = resolve_url(pre_gen_file, os.path.join(os.getcwd(), output_dir)) file_url = urlparse.urljoin('file:', urllib.pathname2url(pre_gen_file)) curr_file = File(ifo, user_tag, global_seg, file_url, tags=tags) curr_file.PFN(file_url, site='local') gate_files.append(curr_file) logging.info("Using gating file %s for %s", file_url, ifo) except ConfigParser.Error: logging.info("No gating file specified for %s", ifo) return gate_files
def setup_gate_pregenerated(workflow, tags=None): ''' Setup CBC workflow to use pregenerated gating files. The file given in cp.get('workflow','pregenerated-gating-file-(ifo)') will be used as the --gating-file for all matched-filtering jobs for that ifo. Parameters ---------- workflow: pycbc.workflow.core.Workflow An instanced class that manages the constructed workflow. tags : list of strings If given these tags are used to uniquely name and identify output files that would be produced in multiple calls to this function. Returns -------- gate_files : pycbc.workflow.core.FileList The FileList holding the gating files ''' if tags is None: tags = [] gate_files = FileList([]) cp = workflow.cp global_seg = workflow.analysis_time user_tag = "PREGEN_GATE" for ifo in workflow.ifos: try: pre_gen_file = cp.get_opt_tags( 'workflow-gating', 'gating-pregenerated-file-%s' % ifo.lower(), tags) pre_gen_file = resolve_url(pre_gen_file) file_url = urlparse.urljoin('file:', urllib.pathname2url(pre_gen_file)) curr_file = File(ifo, user_tag, global_seg, file_url, tags=tags) curr_file.PFN(file_url, site='local') gate_files.append(curr_file) except ConfigParser.Error: # It's unlikely, but not impossible, that only some ifos # will be gated logging.warn("No gating file specified for IFO %s." % (ifo, )) pass return gate_files
def setup_gate_pregenerated(workflow, tags=[]): ''' Setup CBC workflow to use pregenerated gating files. The file given in cp.get('workflow','pregenerated-gating-file-(ifo)') will be used as the --gating-file for all matched-filtering jobs for that ifo. Parameters ---------- workflow: pycbc.workflow.core.Workflow An instanced class that manages the constructed workflow. tags : list of strings If given these tags are used to uniquely name and identify output files that would be produced in multiple calls to this function. Returns -------- gate_files : pycbc.workflow.core.FileList The FileList holding the gating files ''' gate_files = FileList([]) cp = workflow.cp global_seg = workflow.analysis_time user_tag = "PREGEN_GATE" for ifo in workflow.ifos: try: pre_gen_file = cp.get_opt_tags('workflow-gating', 'gating-pregenerated-file-%s' % ifo.lower(), tags) pre_gen_file = resolve_url(pre_gen_file) file_url = urlparse.urljoin('file:', urllib.pathname2url(pre_gen_file)) curr_file = File(ifo, user_tag, global_seg, file_url, tags=tags) curr_file.PFN(file_url, site='local') gate_files.append(curr_file) except ConfigParser.Error: # It's unlikely, but not impossible, that only some ifos # will be gated logging.warn("No gating file specified for IFO %s." % (ifo,)) pass return gate_files
def get_segments_file(workflow, name, option_name, out_dir): """Get cumulative segments from option name syntax for each ifo. Use syntax of configparser string to define the resulting segment_file e.x. option_name = +up_flag1,+up_flag2,+up_flag3,-down_flag1,-down_flag2 Each ifo may have a different string and is stored separately in the file. Flags which add time must precede flags which subtract time. Parameters ---------- workflow: pycbc.workflow.Workflow name: string Name of the segment list being created option_name: str Name of option in the associated config parser to get the flag list returns -------- seg_file: pycbc.workflow.SegFile SegFile intance that points to the segment xml file on disk. """ from pycbc.dq import query_str make_analysis_dir(out_dir) cp = workflow.cp start = workflow.analysis_time[0] end = workflow.analysis_time[1] # Check for veto definer file veto_definer = None if cp.has_option("workflow-segments", "segments-veto-definer-url"): veto_definer = save_veto_definer(workflow.cp, out_dir, []) # Check for provided server server = "https://segments.ligo.org" if cp.has_option("workflow-segments", "segments-database-url"): server = cp.get("workflow-segments", "segments-database-url") source = "any" if cp.has_option("workflow-segments", "segments-source"): source = cp.get("workflow-segments", "segments-source") if source == "file": local_file_path = \ resolve_url(cp.get("workflow-segments", option_name+"-file")) pfn = os.path.join(out_dir, os.path.basename(local_file_path)) shutil.move(local_file_path, pfn) return SegFile.from_segment_xml(pfn) segs = {} for ifo in workflow.ifos: flag_str = cp.get_opt_tags("workflow-segments", option_name, [ifo]) key = ifo + ':' + name segs[key] = query_str(ifo, flag_str, start, end, source=source, server=server, veto_definer=veto_definer) logging.info("%s: got %s flags", ifo, option_name) return SegFile.from_segment_list_dict(name, segs, extension='.xml', valid_segment=workflow.analysis_time, directory=out_dir)
def setup_tmpltbank_pregenerated(workflow, tags=None): ''' Setup CBC workflow to use a pregenerated template bank. The bank given in cp.get('workflow','pregenerated-template-bank') will be used as the input file for all matched-filtering jobs. If this option is present, workflow will assume that it should be used and not generate template banks within the workflow. Parameters ---------- workflow: pycbc.workflow.core.Workflow An instanced class that manages the constructed workflow. tags : list of strings If given these tags are used to uniquely name and identify output files that would be produced in multiple calls to this function. Returns -------- tmplt_banks : pycbc.workflow.core.FileList The FileList holding the details of the template bank. ''' if tags is None: tags = [] # Currently this uses the *same* fixed bank for all ifos. # Maybe we want to add capability to analyse separate banks in all ifos? # Set up class for holding the banks tmplt_banks = FileList([]) cp = workflow.cp global_seg = workflow.analysis_time user_tag = "PREGEN_TMPLTBANK" try: # First check if we have a bank for all ifos pre_gen_bank = cp.get_opt_tags('workflow-tmpltbank', 'tmpltbank-pregenerated-bank', tags) pre_gen_bank = resolve_url(pre_gen_bank) file_url = urlparse.urljoin('file:', urllib.pathname2url(pre_gen_bank)) curr_file = File(workflow.ifos, user_tag, global_seg, file_url, tags=tags) curr_file.PFN(file_url, site='local') tmplt_banks.append(curr_file) except ConfigParser.Error: # Okay then I must have banks for each ifo for ifo in workflow.ifos: try: pre_gen_bank = cp.get_opt_tags( 'workflow-tmpltbank', 'tmpltbank-pregenerated-bank-%s' % ifo.lower(), tags) pre_gen_bank = resolve_url(pre_gen_bank) file_url = urlparse.urljoin('file:', urllib.pathname2url(pre_gen_bank)) curr_file = File(ifo, user_tag, global_seg, file_url, tags=tags) curr_file.PFN(file_url, site='local') tmplt_banks.append(curr_file) except ConfigParser.Error: err_msg = "Cannot find pregerated template bank in section " err_msg += "[workflow-tmpltbank] or any tagged sections. " if tags: tagged_secs = " ".join("[workflow-tmpltbank-%s]" \ %(ifo,) for ifo in workflow.ifos) err_msg += "Tagged sections are %s. " % (tagged_secs, ) err_msg += "I looked for 'tmpltbank-pregenerated-bank' option " err_msg += "and 'tmpltbank-pregenerated-bank-%s'." % (ifo, ) raise ConfigParser.Error(err_msg) return tmplt_banks
def setup_injection_workflow(workflow, output_dir=None, inj_section_name='injections', exttrig_file=None, tags=None): """ This function is the gateway for setting up injection-generation jobs in a workflow. It should be possible for this function to support a number of different ways/codes that could be used for doing this, however as this will presumably stay as a single call to a single code (which need not be inspinj) there are currently no subfunctions in this moudle. Parameters ----------- workflow : pycbc.workflow.core.Workflow The Workflow instance that the coincidence jobs will be added to. output_dir : path The directory in which injection files will be stored. inj_section_name : string (optional, default='injections') The string that corresponds to the option describing the exe location in the [executables] section of the .ini file and that corresponds to the section (and sub-sections) giving the options that will be given to the code at run time. tags : list of strings (optional, default = []) A list of the tagging strings that will be used for all jobs created by this call to the workflow. This will be used in output names. Returns -------- inj_files : pycbc.workflow.core.FileList The list of injection files created by this call. inj_tags : list of strings The tag corresponding to each injection file and used to uniquely identify them. The FileList class contains functions to search based on tags. """ if tags is None: tags = [] logging.info("Entering injection module.") make_analysis_dir(output_dir) # Get full analysis segment for output file naming full_segment = workflow.analysis_time ifos = workflow.ifos # Identify which injections to do by presence of sub-sections in # the configuration file inj_tags = [] inj_files = FileList([]) for section in workflow.cp.get_subsections(inj_section_name): inj_tag = section.upper() curr_tags = tags + [inj_tag] # FIXME: Remove once fixed in pipedown # TEMPORARILY we require inj tags to end in "INJ" if not inj_tag.endswith("INJ"): err_msg = "Currently workflow requires injection names to end with " err_msg += "a inj suffix. Ie. bnslininj or bbhinj. " err_msg += "%s is not good." % (inj_tag.lower()) raise ValueError(err_msg) # Parse for options in ini file injection_method = workflow.cp.get_opt_tags("workflow-injections", "injections-method", curr_tags) if injection_method in ["IN_WORKFLOW", "AT_RUNTIME"]: # FIXME: Add ability to specify different exes inj_job = LalappsInspinjExecutable(workflow.cp, inj_section_name, out_dir=output_dir, ifos='HL', tags=curr_tags) node = inj_job.create_node(full_segment) if injection_method == "AT_RUNTIME": workflow.execute_node(node) else: workflow.add_node(node) inj_file = node.output_files[0] inj_files.append(inj_file) elif injection_method == "PREGENERATED": injectionFilePath = workflow.cp.get_opt_tags( "workflow-injections", "injections-pregenerated-file", curr_tags) injectionFilePath = resolve_url(injectionFilePath) file_url = urlparse.urljoin('file:', urllib.pathname2url(injectionFilePath)) inj_file = File('HL', 'PREGEN_inj_file', full_segment, file_url, tags=curr_tags) inj_file.PFN(injectionFilePath, site='local') inj_files.append(inj_file) elif injection_method in ["IN_COH_PTF_WORKFLOW", "AT_COH_PTF_RUNTIME"]: inj_job = LalappsInspinjExecutable(workflow.cp, inj_section_name, out_dir=output_dir, ifos=ifos, tags=curr_tags) node = inj_job.create_node(full_segment, exttrig_file) if injection_method == "AT_COH_PTF_RUNTIME": workflow.execute_node(node) else: workflow.add_node(node) inj_file = node.output_files[0] if workflow.cp.has_option("workflow-injections", "em-bright-only"): em_filter_job = PycbcDarkVsBrightInjectionsExecutable( workflow.cp, 'em_bright_filter', tags=curr_tags, out_dir=output_dir, ifos=ifos) node = em_filter_job.create_node(inj_file, full_segment, curr_tags) if injection_method == "AT_COH_PTF_RUNTIME": workflow.execute_node(node) else: workflow.add_node(node) inj_file = node.output_files[0] if workflow.cp.has_option("workflow-injections", "do-jitter-skyloc"): jitter_job = LigolwCBCJitterSkylocExecutable( workflow.cp, 'jitter_skyloc', tags=curr_tags, out_dir=output_dir, ifos=ifos) node = jitter_job.create_node(inj_file, full_segment, curr_tags) if injection_method == "AT_COH_PTF_RUNTIME": workflow.execute_node(node) else: workflow.add_node(node) inj_file = node.output_files[0] if workflow.cp.has_option("workflow-injections", "do-align-total-spin"): align_job = LigolwCBCAlignTotalSpinExecutable( workflow.cp, 'align_total_spin', tags=curr_tags, out_dir=output_dir, ifos=ifos) node = align_job.create_node(inj_file, full_segment, curr_tags) if injection_method == "AT_COH_PTF_RUNTIME": workflow.execute_node(node) else: workflow.add_node(node) inj_file = node.output_files[0] inj_files.append(inj_file) else: err = "Injection method must be one of IN_WORKFLOW, " err += "AT_RUNTIME or PREGENERATED. Got %s." % (injection_method) raise ValueError(err) inj_tags.append(inj_tag) logging.info("Leaving injection module.") return inj_files, inj_tags
def setup_tmpltbank_pregenerated(workflow, tags=None): ''' Setup CBC workflow to use a pregenerated template bank. The bank given in cp.get('workflow','pregenerated-template-bank') will be used as the input file for all matched-filtering jobs. If this option is present, workflow will assume that it should be used and not generate template banks within the workflow. Parameters ---------- workflow: pycbc.workflow.core.Workflow An instanced class that manages the constructed workflow. tags : list of strings If given these tags are used to uniquely name and identify output files that would be produced in multiple calls to this function. Returns -------- tmplt_banks : pycbc.workflow.core.FileList The FileList holding the details of the template bank. ''' if tags is None: tags = [] # Currently this uses the *same* fixed bank for all ifos. # Maybe we want to add capability to analyse separate banks in all ifos? # Set up class for holding the banks tmplt_banks = FileList([]) cp = workflow.cp global_seg = workflow.analysis_time user_tag = "PREGEN_TMPLTBANK" try: # First check if we have a bank for all ifos pre_gen_bank = cp.get_opt_tags('workflow-tmpltbank', 'tmpltbank-pregenerated-bank', tags) pre_gen_bank = resolve_url(pre_gen_bank) file_url = urlparse.urljoin('file:', urllib.pathname2url(pre_gen_bank)) curr_file = File(workflow.ifos, user_tag, global_seg, file_url, tags=tags) curr_file.PFN(file_url, site='local') tmplt_banks.append(curr_file) except ConfigParser.Error: # Okay then I must have banks for each ifo for ifo in workflow.ifos: try: pre_gen_bank = cp.get_opt_tags('workflow-tmpltbank', 'tmpltbank-pregenerated-bank-%s' % ifo.lower(), tags) pre_gen_bank = resolve_url(pre_gen_bank) file_url = urlparse.urljoin('file:', urllib.pathname2url(pre_gen_bank)) curr_file = File(ifo, user_tag, global_seg, file_url, tags=tags) curr_file.PFN(file_url, site='local') tmplt_banks.append(curr_file) except ConfigParser.Error: err_msg = "Cannot find pregerated template bank in section " err_msg += "[workflow-tmpltbank] or any tagged sections. " if tags: tagged_secs = " ".join("[workflow-tmpltbank-%s]" \ %(ifo,) for ifo in workflow.ifos) err_msg += "Tagged sections are %s. " %(tagged_secs,) err_msg += "I looked for 'tmpltbank-pregenerated-bank' option " err_msg += "and 'tmpltbank-pregenerated-bank-%s'." %(ifo,) raise ConfigParser.Error(err_msg) return tmplt_banks
def setup_injection_workflow(workflow, output_dir=None, inj_section_name='injections', exttrig_file=None, tags =None): """ This function is the gateway for setting up injection-generation jobs in a workflow. It should be possible for this function to support a number of different ways/codes that could be used for doing this, however as this will presumably stay as a single call to a single code (which need not be inspinj) there are currently no subfunctions in this moudle. Parameters ----------- workflow : pycbc.workflow.core.Workflow The Workflow instance that the coincidence jobs will be added to. output_dir : path The directory in which injection files will be stored. inj_section_name : string (optional, default='injections') The string that corresponds to the option describing the exe location in the [executables] section of the .ini file and that corresponds to the section (and sub-sections) giving the options that will be given to the code at run time. tags : list of strings (optional, default = []) A list of the tagging strings that will be used for all jobs created by this call to the workflow. This will be used in output names. Returns -------- inj_files : pycbc.workflow.core.FileList The list of injection files created by this call. inj_tags : list of strings The tag corresponding to each injection file and used to uniquely identify them. The FileList class contains functions to search based on tags. """ if tags is None: tags = [] logging.info("Entering injection module.") make_analysis_dir(output_dir) # Get full analysis segment for output file naming full_segment = workflow.analysis_time ifos = workflow.ifos # Identify which injections to do by presence of sub-sections in # the configuration file inj_tags = [] inj_files = FileList([]) for section in workflow.cp.get_subsections(inj_section_name): inj_tag = section.upper() curr_tags = tags + [inj_tag] # FIXME: Remove once fixed in pipedown # TEMPORARILY we require inj tags to end in "INJ" if not inj_tag.endswith("INJ"): err_msg = "Currently workflow requires injection names to end with " err_msg += "a inj suffix. Ie. bnslininj or bbhinj. " err_msg += "%s is not good." %(inj_tag.lower()) raise ValueError(err_msg) # Parse for options in ini file injection_method = workflow.cp.get_opt_tags("workflow-injections", "injections-method", curr_tags) if injection_method in ["IN_WORKFLOW", "AT_RUNTIME"]: # FIXME: Add ability to specify different exes inj_job = LalappsInspinjExecutable(workflow.cp, inj_section_name, out_dir=output_dir, ifos='HL', tags=curr_tags) node = inj_job.create_node(full_segment) if injection_method == "AT_RUNTIME": workflow.execute_node(node) else: workflow.add_node(node) inj_file = node.output_files[0] inj_files.append(inj_file) elif injection_method == "PREGENERATED": injectionFilePath = workflow.cp.get_opt_tags("workflow-injections", "injections-pregenerated-file", curr_tags) injectionFilePath = resolve_url(injectionFilePath) file_url = urlparse.urljoin('file:', urllib.pathname2url(injectionFilePath)) inj_file = File('HL', 'PREGEN_inj_file', full_segment, file_url, tags=curr_tags) inj_file.PFN(injectionFilePath, site='local') inj_files.append(inj_file) elif injection_method in ["IN_COH_PTF_WORKFLOW", "AT_COH_PTF_RUNTIME"]: inj_job = LalappsInspinjExecutable(workflow.cp, inj_section_name, out_dir=output_dir, ifos=ifos, tags=curr_tags) node = inj_job.create_node(full_segment, exttrig_file) if injection_method == "AT_COH_PTF_RUNTIME": workflow.execute_node(node) else: workflow.add_node(node) inj_file = node.output_files[0] if workflow.cp.has_option("workflow-injections", "em-bright-only"): em_filter_job = PycbcDarkVsBrightInjectionsExecutable( workflow.cp, 'em_bright_filter', tags=curr_tags, out_dir=output_dir, ifos=ifos) node = em_filter_job.create_node(inj_file, full_segment, curr_tags) if injection_method == "AT_COH_PTF_RUNTIME": workflow.execute_node(node) else: workflow.add_node(node) inj_file = node.output_files[0] if workflow.cp.has_option("workflow-injections", "do-jitter-skyloc"): jitter_job = LigolwCBCJitterSkylocExecutable(workflow.cp, 'jitter_skyloc', tags=curr_tags, out_dir=output_dir, ifos=ifos) node = jitter_job.create_node(inj_file, full_segment, curr_tags) if injection_method == "AT_COH_PTF_RUNTIME": workflow.execute_node(node) else: workflow.add_node(node) inj_file = node.output_files[0] if workflow.cp.has_option("workflow-injections", "do-align-total-spin"): align_job = LigolwCBCAlignTotalSpinExecutable(workflow.cp, 'align_total_spin', tags=curr_tags, out_dir=output_dir, ifos=ifos) node = align_job.create_node(inj_file, full_segment, curr_tags) if injection_method == "AT_COH_PTF_RUNTIME": workflow.execute_node(node) else: workflow.add_node(node) inj_file = node.output_files[0] inj_files.append(inj_file) else: err = "Injection method must be one of IN_WORKFLOW, " err += "AT_RUNTIME or PREGENERATED. Got %s." % (injection_method) raise ValueError(err) inj_tags.append(inj_tag) logging.info("Leaving injection module.") return inj_files, inj_tags