test_write.py

Lu Chia-Chun, 07/13/2014 03:35 PM

Download (1.17 KB)

 
1
from gammalib import *
2
from ctools import *
3
import math
4
import os
5
from gfuncs import *
6
from userclass import *
7
datadir = '/home/hfm/chiachun/disk1/gammalib/CubeAnalysis/cta1dc/crab/data/'
8
run = 23523
9

    
10
# files for this run
11
f_event = '{datadir}/run_00{run}_std_eventlist.fits'.format(**globals())
12
f_aeff = '{datadir}/run_00{run}_std_arf.fits'.format(**globals())
13
f_psf = '{datadir}/run_00{run}_std_psf.fits'.format(**globals())
14
f_bg = '/home/hfm/chiachun/disk1/gammalib/CubeAnalysis/irf_file.fits'.format(**globals())
15

    
16
# set up a cta observation
17
cta = GCTAObservation()
18
cta.id('{run}'.format(**globals()))
19
cta.load(f_event)
20
rsp = cta.response()
21
rsp.load_aeff(f_aeff)
22
rsp.load_psf(f_psf)
23
rsp.load_background(f_bg)
24
bg = GCTABackground3D(rsp.background())
25
bg_table = bg.rsp_table()
26
newhdu = GFitsBinTable()
27
bg_table.write(newhdu)
28
fits = GFits()
29
fits.append(newhdu)
30
fits.saveto('newfile.fits', True)
31
fits.close()
32

    
33
# set up a new cta observation
34
ncta = GCTAObservation()
35
ncta.id('{run}'.format(**globals()))
36
ncta.load(f_event)
37
nrsp = cta.response()
38
nrsp.load_aeff(f_aeff)
39
nrsp.load_psf(f_psf)
40
nrsp.load_background('newfile.fits')
41
bg = GCTABackground3D(rsp.background())
42
logE = 0
43
print( bg(logE, 0 ,0 ) )