def write_dag(self): """ Create directory and run lalapps_cohPTF_hipe to create the DAG. """ # write out an appropriate ini file ini_file_name = self.dag_base_name + ".ini" os.chdir(self._hipe_dir) if not os.path.isdir(self._log_path): # in case of relative path os.mkdir(self._log_path) cp_file = open(ini_file_name, 'w') self._cp.write(cp_file) cp_file.close() arguments = " ".join(self._hipe_args) arguments += " " + " ".join(["--" + stage for stage in self._stages]) # run inspiral_hipe inspiralutils.make_external_call(\ " ".join((self._cp.get("condor","cohPTF_hipe"), arguments % ini_file_name)), show_stdout=False, show_command=self._verbose) if os.path.isdir("cache") and not os.path.islink("cache"): os.rmdir("cache") if not os.path.exists("cache"): os.symlink("../datafind/cache", "cache") if cp.has_option('splitbank-meta','bank-file'): shutil.copy("../../" + cp.get('splitbank-meta','bank-file'),'.') if cp.has_option('coh_PTF_inspiral','bank-veto-templates'): shutil.copy("../../" + cp.get('coh_PTF_inspiral','bank-veto-templates'),'.') os.chdir("../../")
def write_dag(self): """ Create directory and run lalapps_inspiral_hipe to create the DAG. """ # write out an appropriate ini file ini_file_name = self.dag_base_name + ".ini" os.chdir(self._hipe_dir) if not os.path.isdir(self._log_path): # in case of relative path os.mkdir(self._log_path) cp_file = open(ini_file_name, 'w') self._cp.write(cp_file) cp_file.close() arguments = " ".join(self._hipe_args) arguments += " " + " ".join(["--" + stage for stage in self._stages]) # run inspiral_hipe inspiralutils.make_external_call(\ " ".join((self._cp.get("condor", "inspiral_hipe"), arguments % ini_file_name)), show_stdout=False, show_command=self._verbose) # create link to datafind directory's cache directory if not "datafind" in self._stages: if os.path.isdir("cache") and not os.path.islink("cache"): os.rmdir("cache") if not os.path.exists("cache"): os.symlink("../datafind/cache", "cache") # set inspinj jobs to run in the local universe inspinj_sub_files = glob.glob("*inspinj*.sub") for sub_file in inspinj_sub_files: contents = open(sub_file).read().replace("universe = standard", "universe = local") open(sub_file, "w").write(contents) os.chdir("../../")
gps_end = int(opts.gps_end_time) duration = gps_end - gps_start dqVetoes = {} dqVetoes["combined-veto-file"] = {} for category in veto_categories: ifos_string = "" veto_cat_files = [] veto_cat_filename = str(gps_start) + "-" + str(duration) + ".xml" for ifo in ifos: veto_cat_files.append("-".join([ifo, "VETOTIME_CAT" + str(category), veto_cat_filename])) ifos_string += ifo dqVetoes["combined-veto-file"][category] = '-'.join([ifos_string, "VETOTIME_CAT_" + str(category), veto_cat_filename]) concat_veto_call = " ".join([ cp.get("condor", "ligolw_add"), "--output", dqVetoes["combined-veto-file"][category] ] + veto_cat_files) inspiralutils.make_external_call(concat_veto_call) # FIXME: remove this block when the veto files from # ligolw_segments_from_cats have contain a segment table with start_time_ns # and end_time_ns, and when the process table doesn't need the domain, jobid, # and is_online columns added compat_veto_call = " ".join([cp.get("condor", "ligolw_segments_compat"), dqVetoes["combined-veto-file"][category]]) inspiralutils.make_external_call(compat_veto_call) segFile = {} for ifo in ifos: segFile[ifo], dqVetoes[ifo] = inspiralutils.findSegmentsToAnalyze( cp, ifo, veto_categories, opts.generate_segments, opts.use_available_data,
def createInjectionFile(hipe_dir, cp, cpinj, injrun, injection_segment, source_file, ipn_gps=None, usertag=None, verbose=False): """ Creates an master injection file containing all injections for this run. Also reads the file and returns its contents """ cpinj = copy.deepcopy(cpinj) # get the number of injections to be made for opt in ['exttrig-inj-start','exttrig-inj-stop']: value = int(cpinj.get(injrun,opt)) cpinj.remove_option(injrun,opt) if 'start' in opt: injStart = value else: injEnd = value seed = hash_n_bits(hipe_dir, 31) numberInjections = injEnd - injStart + 1 # e.g., 1 through 5000 inclusive # get the jitter parameters if cpinj.has_option(injrun, "jitter-skyloc"): jitter_sigma_deg = cpinj.getfloat(injrun, "jitter-skyloc") cpinj.remove_option(injrun, "jitter-skyloc") else: jitter_sigma_deg = None # check if the specific Fermi systematic error needs to # be added to the location jittering if cpinj.has_option(injrun, "jitter-skyloc-fermi"): jitter_skyloc_fermi = cpinj.getboolean(injrun, "jitter-skyloc-fermi") cpinj.remove_option(injrun, "jitter-skyloc-fermi") else: jitter_skyloc_fermi = False # check if we should align the total angular momentum if cpinj.has_option(injrun, "align-total-spin"): align_total_spin = cpinj.getboolean(injrun, "align-total-spin") cpinj.remove_option(injrun, "align-total-spin") else: align_total_spin = False # set all the arguments argument = [] for (opt,value) in cpinj.items(injrun): argument.append("--%s %s" % (opt, value) ) # add arguments on times and time-intervals interval = abs(injection_segment) injInterval = interval / numberInjections argument.append(" --gps-start-time %d" % injection_segment[0] ) argument.append(" --gps-end-time %d" % injection_segment[1] ) argument.append(" --time-interval %f" % injInterval ) argument.append(" --time-step %f" % injInterval ) argument.append(" --seed %d" % seed ) argument.append(" --user-tag %s" % usertag) # set output file as exttrig-file or IPN file with IPN GPS time if ipn_gps: argument.append(" --ipn-gps-time %d" % ipn_gps ) else: argument.append(" --exttrig-file %s" % source_file ) # execute the command executable = cp.get("condor", "inspinj") arguments = " ".join(argument) inspiralutils.make_external_call(executable + " " + arguments, show_command=verbose) # recreate the output filename injFile = "HL-INJECTIONS_" + str(seed) if usertag is not None: injFile += "_" + usertag injFile += "-%d-%d.xml" % (injection_segment[0], abs(injection_segment)) # move it into the GRB directory to avoid clutter new_injFile = hipe_dir + "/" + injFile os.rename(injFile, new_injFile) # jitter the sky locations of the injections if jitter_sigma_deg is not None: # rename the original, then have ligolw_cbc_jitter_skyloc create a new one os.rename(new_injFile, new_injFile + ".prejitter") cmd = ["ligolw_cbc_jitter_skyloc"] if jitter_skyloc_fermi: cmd.append("--apply-fermi-error") cmd.extend(["--jitter-sigma-deg", str(jitter_sigma_deg), "--output-file", new_injFile, new_injFile + ".prejitter"]) if verbose: print(" ".join(cmd)) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() if p.returncode != 0: raise subprocess.CalledProcessError(p.returncode, "%s: %s" % (" ".join(cmd), err)) # rotate the binary so that total angular momentum has the current inclination if align_total_spin: # rename the original then have ligolw_cbc_align_total_spin create a new one os.rename(new_injFile, new_injFile + ".prealign") cmd = ["ligolw_cbc_align_total_spin", "--output-file", new_injFile, new_injFile + ".prealign"] if verbose: print(" ".join(cmd)) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() if p.returncode != 0: raise subprocess.CalledProcessError(p.returncode, "%s: %s" % (" ".join(cmd), err)) # read in the file and the tables doc = utils.load_filename(new_injFile, contenthandler = lsctables.use_in(ligolw.LIGOLWContentHandler)) sims = lsctables.SimInspiralTable.get_table(doc) return sims, injInterval, numberInjections, new_injFile
def concatenate_files(input_names, output_name): """ Concatenate several files to a file named output_cache. """ inspiralutils.make_external_call("cat %s > %s" % \ (" ".join(input_names), output_name))