def MakeconfigFromFile(out, source, ra, dec, conf_template): ''' Generate a config file from another default config file given in the parameters Parameters --------- out : place where the fits file work : place where fits file will be temporarily stored and where the log file will be kept source : source name ra : right Ascension of the source dec : dec of the source conf_template : default config provided by the user ''' config = get_config(conf_template) config["out"] = out config['file']['inobs'] = 'event_' + source.replace(" ", "") + ".fits" config['file']['selectedevent'] = 'event_selected_' + source.replace( " ", "") + ".fits" config['file']['inmodel'] = source.replace(" ", "") + '.xml' config['file']['cube'] = 'Cube_' + source.replace(" ", "") + ".fits" config['file']['model'] = 'Model_' + source.replace(" ", "") + ".fits" config['target']['name'] = source.replace(" ", "") config['target']['ra'] = ra config['target']['dec'] = dec return config
def DoSimulation(source, area, simutime): #define source name. This also allows to have the coordinate if you have astropy #source = "AP Librae" ra = None dec = None if Astropy: coord = CH.CoordinatesHandler.fromName(source, FK5) ra, dec = CU.GetCoordInDegrees(coord) #default work and out path. Not use if you provide a config file in the command line #out = join(os.getcwd(), "out") #work = join(os.getcwd(), "work") out = "/Users/gateflorian/Documents/CTAtools/Script/out" work = "/Users/gateflorian/Documents/CTAtools/Script/work" # setup : Time, Energy and IRFS. Not use if you provide a config file in the command line tmin = 0 #tmax = 3600 tmaxtmp = simutime * 3600 tmax = int(tmaxtmp) print tmax irfTime = IrfChoice(simutime) emin = 0.2 emax = 10 irf = str(area) + "_" + str(irfTime) + "h" print irf caldb = "prod2" #irf = "South_0.5h" # Not use if you provide a config file in the command line try: #conf file provided config_tmp = get_config(sys.argv[1]) config = MakeconfigFromFile(out, work, source, ra, dec, config_tmp) except: config = MakeconfigFromDefault(out, work, source, ra, dec) config.write( open( "simu_" + source.replace(" ", "") + "_" + str(simutime) + "h" + ".conf", 'w')) #creation of the simulation object simu = CTA_ctools_sim.fromConfig(config) #set up if there is no config file provided if len(sys.argv) == 1: simu.SetTimeRange(tmin, tmax) simu.SetEnergyRange(emin, emax) simu.SetIRFs(caldb, irf) simu.config.write( open( work + "/simu_" + source.replace(" ", "") + "_" + str(simutime) + "h" + ".conf", 'w')) # run simu.run_sim(prefix=source.replace(" ", "") + "_" + str(simutime) + "h", nsim=1, write=True, clobber=True) simu.Print() return
def DoFit(source,area,simutime): #define source name. This also allows to have the coordinate if you have astropy #source = "AP Librae" ra = None dec = None if Astropy: coord = CH.CoordinatesHandler.fromName(source,FK5) ra, dec = CU.GetCoordInDegrees(coord) #default work and out path. Not use if you provide a config file in the command line out = join(os.getcwd(), "out") work = join(os.getcwd(), "work") # setup : Time, Energy and IRFS. Not use if you provide a config file in the command line tmin = 0 #tmax = 3600 tmaxtmp=simutime*3600 tmax = int(tmaxtmp) irfTime=IrfChoice(simutime) emin = 0.2 emax = 10 irf = str(area)+"_"+str(irfTime)+"h" caldb = "prod2" #irf = "South_0.5h" #quentin fitsFile = out+"/"+source.replace(" ","")+"_"+str(simutime)+"h"+"_event00001.fits" #fitsFile="/Users/gateflorian/Documents/CTAtools/Script/out/Mkn180_event00001.fits" #fitsFile = "/Users/gateflorian/Documents/CTAtools/Script/out/table_20161213.fits" try: #conf file provided config_tmp = get_config(sys.argv[-1]) config = MakeconfigFromFile(out,work,source,ra,dec,config_tmp) #config["file"]["inobs"] = sys.argv[-2] config["file"]["inobs"] = fitsFile except: #Not use if you provide a config file in the command line config = MakeconfigFromDefault(out,work,source,ra,dec) config["file"]["inobs"] = fitsFile #config["file"]["inobs"] = sys.argv[-1] config.write(open(work+"/Fit_"+source.replace(" ","")+"_"+str(simutime)+"h"+".conf", 'w')) Analyse = CTA_ctools_analyser.fromConfig(config) #set up if there is no config file provided if len(sys.argv) == 1 : Analyse.SetTimeRange(tmin,tmax) Analyse.SetEnergyRange(emin,emax) Analyse.SetIRFs(caldb,irf) Analyse.create_fit(log = True,debug = False) Analyse.fit() Analyse.PrintResults()
def MakeconfigFromFile(out,source,ra,dec,conf_template): ''' Generate a config file from another default config file given in the parameters Parameters --------- out : place where the fits file work : place where fits file will be temporarily stored and where the log file will be kept source : source name ra : right Ascension of the source dec : dec of the source conf_template : default config provided by the user ''' config = get_config(conf_template) config["out"] = out config['file']['inobs'] = 'event_'+source.replace(" ","")+".fits" config['file']['selectedevent'] = 'event_selected_'+source.replace(" ","")+".fits" config['file']['inmodel'] = source.replace(" ","")+'.xml' config['file']['cube'] = 'Cube_'+source.replace(" ","")+".fits" config['file']['model'] = 'Model_'+source.replace(" ","")+".fits" config['target']['name'] = source.replace(" ","") config['target']['ra'] = ra config['target']['dec'] = dec return config
import pyfits import random # ------------------------------ # try: get_ipython().magic(u'pylab') except : pass catalog = os.getcwd()+"/AGN_Monitoring_list.dat" #Model = "PL" #Model = "LPEBL" Model = "PLEBL" #Model = "PLECEBL" try: #conf file provided config = get_config(sys.argv[-2]) redshift = float(sys.argv[-1]) except : print "usage : python "+sys.argv[0]+" config_file redshift" exit() # #------------------- Analyse = CTA_ctools_analyser.fromConfig(config) #------------------ Value of the EBL ETeV = numpy.logspace(-2,2.5,200) EBL_mod = config["simulation"]["EBL_model"] tau = OD.readmodel(model = EBL_mod) Tau_values = tau.opt_depth(redshift,ETeV)
# ------ Imports --------------- # import os,sys,numpy import matplotlib.pyplot as plt import pyfits from Script.Utils import LiMa from ctoolsAnalysis.config import get_config,get_default_config # ------------------------------ # try: get_ipython().magic(u'pylab') except : pass try: #conf file provided config = get_config(sys.argv[-1]) except : print "usage : python "+sys.argv[0]+" config_file" exit() prefix = config["target"]["name"]+"_onoff" Onfile = config['out']+"/"+prefix+"_stacked_pha_on.fits" Offfile = config['out']+"/"+prefix+"_stacked_pha_off.fits" Ondata = pyfits.open(Onfile)[1].data Oncount = Ondata['COUNTS'] dOncount = Ondata['STAT_ERR'] Alpha = Ondata['BACKSCAL'] Offdata = pyfits.open(Offfile)[1].data Offcount = Offdata['COUNTS'] dOffcount = Offdata['STAT_ERR'] Ebound = pyfits.open(Onfile)[2].data
from Script.Common_Functions import * import ctoolsAnalysis.xml_generator as xml import matplotlib.pyplot as plt # ------------------------------ # try: get_ipython().magic(u'pylab') except : pass catalog = os.getcwd()+"/AGN_Monitoring_list.dat" #Model = "PL" #Model = "LPEBL" Model = "PLEBL" #Model = "PLECEBL" try: #conf file provided config = get_config(sys.argv[-1]) except : print "usage : python "+sys.argv[0]+" config_file" exit() #------ Source Id data = numpy.genfromtxt("AGN_Monitoring_list.dat",dtype=str,unpack=True) for i in xrange(len(data[0])): srcname = data[0][i]+data[1][i] if srcname == config["target"]["name"]: redshift = data[-1][i] srcname = config["target"]["name"] ra = config["target"]["ra"] dec = config["target"]["dec"]
out = join(os.getcwd(), "out") work = join(os.getcwd(), "work") # setup : Time, Energy and IRFS. Not use if you provide a config file in the command line tmin = 0 tmax = 36000 emin = 0.2 emax = 10 caldb = "prod2" irf = "South_0.5h" # Not use if you provide a config file in the command line try :#conf file provided config_tmp = get_config(sys.argv[1]) config = MakeconfigFromFile(out,work,source,ra,dec,config_tmp) except : config = MakeconfigFromDefault(out,work,source,ra,dec) config.write(open("simu_"+source.replace(" ","")+".conf", 'w')) #creation of the simulation object simu = CTA_ctools_sim.fromConfig(config) #set up if there is no config file provided if len(sys.argv) == 1 : simu.SetTimeRange(tmin,tmax) simu.SetEnergyRange(emin,emax) simu.SetIRFs(caldb,irf) simu.config.write(open(work+"/simu_"+source.replace(" ","")+".conf", 'w'))
out = join(os.getcwd(), "out") work = join(os.getcwd(), "work") # setup : Time, Energy and IRFS. Not use if you provide a config file in the command line tmin = 0 tmax = 36000 emin = 0.2 emax = 10 caldb = "prod2" irf = "South_0.5h" # Not use if you provide a config file in the command line try: #conf file provided config_tmp = get_config(sys.argv[1]) config = MakeconfigFromFile(out, work, source, ra, dec, config_tmp) except: config = MakeconfigFromDefault(out, work, source, ra, dec) config.write(open("simu_" + source.replace(" ", "") + ".conf", 'w')) #creation of the simulation object simu = CTA_ctools_sim.fromConfig(config) #set up if there is no config file provided if len(sys.argv) == 1: simu.SetTimeRange(tmin, tmax) simu.SetEnergyRange(emin, emax) simu.SetIRFs(caldb, irf) simu.config.write(
import os,numpy import Script.Common_Functions as CF from ctoolsAnalysis.config import get_config,get_default_config data = numpy.genfromtxt("AGN_Monitoring_list.dat",dtype=str,unpack=True) for i in xrange(len(data[0])): srcname = data[0][i]+data[1][i] cwd = os.getcwd()+"/"+srcname os.system("mkdir -p "+cwd) ra = data[2][i] dec = data[3][i] z = data[4][i] print srcname," ",ra," ",dec, " ", z config = get_config('Template.conf') config = CF.MakeconfigFromFile(cwd,srcname,ra,dec,'Template.conf') config['out'] = cwd config['file']['inobs'] = cwd+"/outobs_"+srcname+".xml" config['file']['selectedevent'] = cwd+"/outobs_"+srcname+"_selected.xml" config['file']['inmodel'] = cwd+"/"+srcname+".xml" config["file"]["tag"] = srcname+"_DC1" config["file"]["outmap"] = cwd+"/"+srcname+"_DC1_skymap.fits" config["space"]["xref"] = ra config["space"]["yref"] = dec config["space"]["rad"] = 3 config["irfs"]["irf"] = "South_z20_50h" config["irfs"]["caldb"] = "1dc"