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()
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) #------------------ Make the XML model for simulations lib,doc = xml.CreateLib() srcname = config["target"]["name"] Model = config["simulation"]["spectrum_model"] #SOURCE SPECTRUM if Model == "PL": spec = xml.addPowerLaw1(lib,srcname,"PointSource", eflux=1e6*numpy.sqrt(Analyse.config["energy"]["emax"]*Analyse.config["energy"]["emin"]),flux_value=1e-10,flux_max=1000.0, flux_min=1e-5)