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()
Astropy = True try: import Coordinates.CoordHandler as CH import Coordinates.CoordUtilities as CU from astropy.coordinates import FK5 except: Astropy = False #define source name. This also allows to have the coordinate if you have astropy source = "AP Librae" ra = 229.42423006 dec = -24.3720738456 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 = 36000 emin = 0.2 emax = 10 caldb = "prod2" irf = "South_0.5h"
#Create a object from RA DEC of the HBL PKS 2155-304 in the FK5 frame coords = CH.CoordinatesHandler(329.716938, -30.225588, FK5) #change to different frame print coords.ToGalactic() print coords.ToFK4() print coords.ToFK5() print coords.ToICRS() print #Current frame print "frame: ", coords.frame print "Coordinate in different format" #coordinate in degree print "In degrees:" print CU.GetCoordInDegrees(coords) #coordinate in Hours Minute Second and Degree Minute Second print "In HMS DMS:" print CU.GetCoordInHMSDMS(coords) coords2 = CH.CoordinatesHandler(328.716938, -30.225588, FK4) print "separation between \n", coords.skycoord, "\n and \n", coords2.skycoord print "val = ", CU.AngleSepDegree(coords, coords2) #look at the altaz at a the date='2016-06-06 00:00:00' for 2 location #HESS and LAPALMA print "Observability" altaz = CU.GetAltAzHESS(coords, date='2016-06-06 00:00:00') print "Object's Altitude = {0.alt:.4}".format(altaz)