-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrmfarf4bg.py
100 lines (77 loc) · 3.55 KB
/
rmfarf4bg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# v2: * use asol3.py to find asol, flt1, pbk, msk, bpix or evt1 files
# v3: * based on rmf4entsoft2.py
# * for both ACIS-I AND ACIS-S
# rmfarf4bg: * based on rmf4ent3, with major modifications
# * added on 1/4/12: check that the identical RMF is not
# itself the one we want to make
# PURPOSE:
# make ARF and RMF to be used with the blank-sky spectra
# INPUT: evtfile (should be cleanOB.fits)
# INPUT: spfile (should be spec/bgspOB_ccdN.fits)
# INPUT: arffile: desired name for output ARF
# INPUT: rmffile: desired name for output RMF
# OUTPUT: ARF and RMF files
import commands
import os
import pdb
import globrmf
def rmf(evtfile, spfile, arffile, rmffile, ccdstr) :
caldbfolder = commands.getoutput('echo $CALDB')
# ARF
if os.path.exists('temp_wfef.fits') : os.remove('temp_wfef.fits')
os.system('punlearn mkwarf')
os.system('pset mkwarf infile='+spfile+'[WMAP]')
os.system('pset mkwarf outfile='+arffile)
os.system('pset mkwarf weightfile=temp_wfef.fits')
#os.system('pset mkwarf pbkfile=none')
os.system('pset mkwarf egridspec="0.3:11.0:0.01"')
os.system('pset mkwarf dafile=none')
os.system('mkwarf verbose=1 mode=h')
# RMF -----------------------
fptemp = float(commands.getoutput('dmkeypar '+evtfile+' fp_temp echo+'))
tgaincor = commands.getoutput('dmkeypar '+evtfile+' tgaincor echo+')
cticor = commands.getoutput('dmkeypar '+evtfile+' cti_corr echo+')
ctiapp = commands.getoutput('dmkeypar '+evtfile+' cti_app echo+')
# using mkacisrmf or...
if (fptemp < 158. or (fptemp >= 158. and ccdstr in ['5','7']) ) and ( ctiapp != 'NNNNNNNNNN' or cticor == 'TRUE' or cticor == '1' ) and (tgaincor == 'T') :
gainfile = commands.getoutput('dmkeypar '+evtfile+' gainfile echo+')
gainver = gainfile.split('.fits')[0][-1]
caldbls = commands.getoutput('ls $CALDB/data/chandra/acis/p2_resp/'+gainfile[0:15]+'*'+gainver+'.fits')
caldbresp = caldbls.split('\n')
if len(caldbresp) != 1 :
print
print
print ' ############### MORE OR LESS THAN ONE P2RESP FILES FOUND !!!!!!!!!! ###################'
print
print
# if gainfile in globrmf.gain and caldbresp[0] in globrmf.scat :
rmflinked=False
for iglob in range(len(globrmf.gain)) :
if gainfile == globrmf.gain[iglob].split('/')[-1] and caldbresp[0] == globrmf.scat[iglob] and ccdstr == globrmf.name[iglob][-6] and rmffile != globrmf.name[iglob][globrmf.name[iglob].rfind('mfe_'):] :
if os.path.exists(rmffile) : os.remove(rmffile)
os.symlink(globrmf.name[iglob], rmffile)
rmflinked=True
break
if not rmflinked :
os.system('punlearn mkacisrmf')
os.system('pset mkacisrmf infile='+caldbresp[0])
os.system('pset mkacisrmf outfile='+rmffile)
os.system('pset mkacisrmf energy="0.3:11.0:0.01" channel="1:1024:1"')
os.system('pset mkacisrmf chantype="PI"')
os.system('pset mkacisrmf wmap='+spfile+'[WMAP]')
os.system('pset mkacisrmf gain='+caldbfolder+'/data/chandra/acis/det_gain/'+gainfile)
os.system('pset mkacisrmf asolfile=none')
os.system('mkacisrmf mode=h verbose=1')
globrmf.gain.append(caldbfolder+'/data/chandra/acis/det_gain/'+gainfile)
globrmf.scat.append(caldbresp[0])
globrmf.name.append('/caviar/home/research/acchif/'+rmffile)
# using mkrmf
else :
os.system('punlearn mkrmf')
os.system('pset mkrmf infile=CALDB')
os.system('pset mkrmf outfile='+rmffile)
os.system('pset mkrmf axis1="energy=0.3:11.0:0.01"')
os.system('pset mkrmf axis2="pi=1:1024:1"')
os.system('pset mkrmf weights=temp_wfef.fits')
os.system('mkrmf verbose=1 mode=h')
if os.path.exists('temp_wfef.fits') : os.remove('temp_wfef.fits')