def run(infile): """Run an entire Fermi analysis (spectrum) by reading a config file""" config = get_config(infile) folder = config['out'] os.system('mkdir -p ' + folder) runfit,Fit = GenAnalysisObject(config) # create all the fit files and run gtlike runfit.PerformFit(Fit) if config['verbose'] == 'yes' : utils.GetFluxes(Fit,runfit.obs.Emin,runfit.obs.Emax) #print the flux of all the sources Result = runfit.GetAndPrintResults(Fit)#Get and dump the target specific results utils.DumpResult(Result, config) #plot the SED and model map if possible and asked if config['Spectrum']['ResultPlots'] == 'yes' : os.system("mkdir -p "+config['out'] + '/Spectrum/') if float(config['UpperLimit']['TSlimit']) < Fit.Ts(config['target']['name']): runfit.ComputeSED(Fit) outXml = utils._dump_xml(config) if SummedLike == 'yes': # the possiblity of making the model map is checked inside the function runfitback.ModelMap(outXml) runfitfront.ModelMap(outXml) else: runfit.ModelMap(outXml) # Make energy bins by run a *new* analysis Nbin = config['Ebin']['NumEnergyBins'] if int(Nbin) > 0: configfiles = utils.PrepareEbin(Fit, runfit) ind = 0 enricodir = environ.DIRS.get('ENRICO_DIR') fermidir = environ.DIRS.get('FERMI_DIR') for conf in configfiles: pathconf = folder + "/Ebin" + str(Nbin) +"/" + conf Newconfig = get_config(pathconf) cmd = enricodir+"/enrico/RunGTlike.py "+pathconf if Newconfig['Ebin']['Submit'] == 'no' : #run directly os.system(cmd) else : #submit a job to a cluster prefix = Newconfig['out'] + "/Ebin" + str(ind) scriptname = prefix + "_Script.sh" JobLog = prefix + "_Job.log" JobName = (Newconfig['target']['name'] + "_" + Newconfig['analysis']['likelihood'] + "_Ebin_" + str(ind) + "_" + Newconfig['file']['tag']) call(cmd, enricodir, fermidir, scriptname, JobLog, JobName)# submition ind+=1
def _launch(self,ra,dec,i,j): """ Launch a job (either pixel evaluation or row evaluation). Can be the submittion of a job to a cluster """ enricodir = environ.DIRS.get('ENRICO_DIR') fermidir = environ.DIRS.get('FERMI_DIR') cmd = enricodir+"/enrico/tsmap.py "+os.getcwd()+"/"+self.infile +" "+ str(ra) +" "+ str(dec) +" "+ str(i) +" "+ str(j) #cmd line to send if self.config['TSMap']['Submit'] == 'yes': prefix = self.tsfolder + "/TSMap_" + str(i) +"_"+ str(j) scriptname = prefix + "_Script.sh" JobLog = prefix + "_Job.log" JobName = (self.config['target']['name'] + "_TSMap_" + str(i) +"_"+ str(j)) call(cmd, enricodir, fermidir, scriptname, JobLog, JobName) #submition else : os.system(cmd) #run directly
def MakeLC(self) : '''Main function of the Lightcurve script. Read the config file and run the gtlike analysis''' enricodir = environ.DIRS.get('ENRICO_DIR') fermidir = environ.DIRS.get('FERMI_DIR') self.PrepareLC(self.config['LightCurve']['MakeConfFile'])#Get the config file for i in xrange(self.config['LightCurve']['NLCbin']): if self.config['LightCurve']['Submit'] == 'yes': cmd = "enrico_sed "+self.configfile[i] scriptname = self.LCfolder+"LC_Script_"+str(i)+".sh" JobLog = self.LCfolder+"LC_Job_"+str(i)+".log" JobName = (self.config['target']['name'] + "_" + self.config['analysis']['likelihood'] + "_LC_" + self.config['file']['tag'])+"_"+str(i)+".log" call(cmd,enricodir,fermidir,scriptname,JobLog,JobName)#Submit the job else : run(self.configfile[i])#run in command line
def RunEbin(folder,Nbin,Fit,FitRunner): if int(Nbin) > 0: configfiles = PrepareEbin(Fit, FitRunner) ind = 0 enricodir = environ.DIRS.get('ENRICO_DIR') fermidir = environ.DIRS.get('FERMI_DIR') for conf in configfiles: pathconf = folder + "/Ebin" + str(Nbin) +"/" + conf Newconfig = get_config(pathconf) cmd = enricodir+"/enrico/RunGTlike.py "+pathconf if Newconfig['Ebin']['Submit'] == 'no' : #run directly os.system(cmd) else : #submit a job to a cluster prefix = Newconfig['out'] + "/Ebin" + str(ind) scriptname = prefix + "_Script.sh" JobLog = prefix + "_Job.log" JobName = (Newconfig['target']['name'] + "_" + Newconfig['analysis']['likelihood'] + "_Ebin_" + str(ind) + "_" + Newconfig['file']['tag']) call(cmd, enricodir, fermidir, scriptname, JobLog, JobName)# submition ind+=1
work, sourcename.replace(" ", "").replace("-", "m").replace("+", "p") + "_alpha_" + str(alpha) + "_index_" + str(index) + ".txt") CF.MakeFileFunction(energy * 1e6, EBL_corrected_phi, Filefunction) config = CF.MakeconfigFromDefault(work, work, sourcename, ra, dec) config["file"]["inobs"] = data config["file"]["selectedevent"] = data.replace( ".fits", "_alpha_" + str(alpha) + "_index_" + str(index) + "_selected.fits") config["file"]["inmodel"] = Filefunction.replace("txt", "xml") config["time"]["tmax"] = 20 * 3600 config["irfs"]["irf"] = irf config["irfs"]["caldb"] = caldb config["energy"]["emin"] = 0.05 config["energy"]["emax"] = 10 config.write(open(Filefunction.replace("txt", "conf"), 'w')) create_xml_from_fileFunctions(sourcename, ra, dec, Filefunction) cmd = "python " + join(os.getcwd(), "Fit_Ctools.py") + " " + Filefunction.replace( "txt", "conf") # print cmd # os.system(cmd) call(cmd, Filefunction.replace("txt", "sh"), Filefunction.replace("txt", "log"))
config = CF.MakeconfigFromDefault(outfolder,work,sourcename,ra,dec) # config.write(open("simu_"+sourcename.replace(" ","")+"_"+str(simutime)+"h"+".conf", 'w')) for emin in emin_table: print 'simu' #creation of the simulation object # simu = CTA_ctools_sim.fromConfig(config) # simu.SetTimeRange(tmin,tmax) # simu.SetIRFs(caldb,irf) # simu.SetEnergyRange(float(emin),emax) config["file"]["inmodel"] = Filefunction.replace("_File.txt",'.xml') config["time"]["tmin"] = tmin config["time"]["tmax"] = tmax config["irfs"]["irf"] = irf config["irfs"]["caldb"] = caldb config["energy"]["emin"] = float(emin) config["energy"]["emax"] = emax config_file = Filefunction.replace("_File.txt","_"+str(int(emin*100.)/100.)+"TeV"+".conf") config.write(open(config_file, 'w')) print "save configuration file ",config_file # run the simulation cmd = "python "+join(os.getcwd(), "Simulate_Ctools.py")+" "+config_file call(cmd,config_file.replace(".conf",".sh"),config_file.replace(".conf",".log")) # os.system(cmd)
for emin in emin_table: print 'simu' #creation of the simulation object # simu = CTA_ctools_sim.fromConfig(config) # simu.SetTimeRange(tmin,tmax) # simu.SetIRFs(caldb,irf) # simu.SetEnergyRange(float(emin),emax) config["file"]["inmodel"] = Filefunction.replace("_File.txt", '.xml') config["time"]["tmin"] = tmin config["time"]["tmax"] = tmax config["irfs"]["irf"] = irf config["irfs"]["caldb"] = caldb config["energy"]["emin"] = float(emin) config["energy"]["emax"] = emax config_file = Filefunction.replace( "_File.txt", "_" + str(int(emin * 100.) / 100.) + "TeV" + ".conf") config.write(open(config_file, 'w')) print "save configuration file ", config_file # run the simulation cmd = "python " + join(os.getcwd(), "Simulate_Ctools.py") + " " + config_file call(cmd, config_file.replace(".conf", ".sh"), config_file.replace(".conf", ".log")) # os.system(cmd)
for index in np.arange(Gmin,Gmax,Gstep): phi = powerlaw(energy,norm,index) for alpha in np.arange(alphamin,alphamax,alphastep): # create_fileFunctions(TauEBL, sourcename,phi,alpha,index) EBL_corrected_phi = phi*np.exp(-alpha * TauEBL) Filefunction = join(work,sourcename.replace(" ","").replace("-","m").replace("+","p")+"_alpha_"+str(alpha)+"_index_"+str(index)+".txt") CF.MakeFileFunction(energy*1e6,EBL_corrected_phi,Filefunction) config = CF.MakeconfigFromDefault(work,work,sourcename,ra,dec) config["file"]["inobs"] = data config["file"]["selectedevent"] = data.replace(".fits","_alpha_"+str(alpha)+"_index_"+str(index)+"_selected.fits") config["file"]["inmodel"] = Filefunction.replace("txt","xml") config["time"]["tmax"] = 20*3600 config["irfs"]["irf"] = irf config["irfs"]["caldb"] = caldb config["energy"]["emin"] = 0.05 config["energy"]["emax"] = 10 config.write(open(Filefunction.replace("txt","conf"), 'w')) create_xml_from_fileFunctions(sourcename,ra,dec,Filefunction) cmd = "python "+join(os.getcwd(), "Fit_Ctools.py")+" "+Filefunction.replace("txt","conf") # print cmd # os.system(cmd) call(cmd,Filefunction.replace("txt","sh"),Filefunction.replace("txt","log"))