logpar_example.py
1 |
#! /usr/bin/env python
|
---|---|
2 |
import gammalib as gl |
3 |
import obsutils as obsu |
4 |
|
5 |
obstime=0.5*3600 |
6 |
write=True
|
7 |
|
8 |
#-----------------------------------------------------
|
9 |
#Create one observation (run)
|
10 |
#-----------------------------------------------------
|
11 |
ra_degree=83.633212 #Crab position from NED |
12 |
dec_degree=22.014460
|
13 |
offset_degree=-1 #Observing offset in dec from Crab in deg |
14 |
pntdir = gl.GSkyDir() |
15 |
pntdir.radec_deg(ra_degree, dec_degree+offset_degree) |
16 |
ob = obsu.set(pntdir,tstart=0.0,duration=obstime,deadc=0.95, \ |
17 |
emin=0.1, emax=100.0, rad=8.0, irf="irf_file.fits",\ |
18 |
caldb="$PWD/caldb/data/cta/aar/bcf/DESY20140105_50h/")
|
19 |
ob.id("run_1")
|
20 |
|
21 |
#----------------------------------------------------
|
22 |
# Create background model
|
23 |
#----------------------------------------------------
|
24 |
spec = gl.GModelSpectralPlaw(1,0,gl.GEnergy(1.0,"TeV")) |
25 |
filename="$PWD/caldb/data/cta/aar/bcf/DESY20140105_50h/irf_file.fits"
|
26 |
bck = gl.GCTAModelIrfBackground(spec) |
27 |
bck.name("Background_run_1")
|
28 |
bck.instruments("CTA")
|
29 |
|
30 |
#----------------------------------------------------
|
31 |
# Create Crab nebula model
|
32 |
#----------------------------------------------------
|
33 |
crabdir = gl.GSkyDir() |
34 |
crabdir.radec_deg(ra_degree, dec_degree) |
35 |
crab_spatial = gl.GModelSpatialPointSource(crabdir) |
36 |
crab_spectrum = gl.GModelSpectralLogParabola(3.2e-17,-2.47,gl.GEnergy(1,"TeV"),-0.24) |
37 |
crab = gl.GModelSky(crab_spatial, crab_spectrum) |
38 |
crab.name("CrabNebula")
|
39 |
crab.ids("")
|
40 |
|
41 |
#----------------------------------------------------
|
42 |
# Create GObservations and add models
|
43 |
#----------------------------------------------------
|
44 |
obs = gl.GObservations() |
45 |
obs.append(ob) |
46 |
obs.models().append(bck) |
47 |
obs.models().append(crab) |
48 |
obssim = obsu.sim(obs, log=write, debug=False, edisp=False, seed=0) |
49 |
obsu.fit(obssim,log=True, debug=False, edisp=False) |