forked from abostroem/13287
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combine_spectra.py
262 lines (211 loc) · 7.33 KB
/
combine_spectra.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import pyraf
from pyraf import iraf
from iraf import stsdas,hst_calib,ctools,splice as splice
from astropy.io import fits
import os
#----------------------------
def add_weight_column():
'''
Weight by exposure time?
Weight by error?
'''
pass
#----------------------------
def add_dq_flags_to_edges(input_filename):
'''
The STIS DHB recommends setting a DQ flag at the edges before combining. 4 is included
in the STIS SDQFLAGS
'''
ofile = fits.open(input_filename, mode = 'update')
ofile[1].data['dq'][0][0:50] = 4
ofile[1].data['dq'][0][-10:] = 4
ofile[0].header.add_history('setting dq = 4 for first and last 10 values')
ofile.close()
#----------------------------
def splice_file_together(input_flist, output_filename):
'''
Combine extracted FUV and NUV spectra into a single file
'''
sdqflag_value = fits.getval(input_flist[0], 'SDQFLAGS', 1)
input_string = ','.join(input_flist)
output_file_whole_path = os.path.join(os.getcwd(), output_filename)
if os.path.exists(output_file_whole_path):
os.remove(output_file_whole_path)
splice( intable = input_string,
outtable = output_filename,
spacing = 'fine',
sdqflags = sdqflag_value,
wl_name = 'wavelength',
flux_name = 'flux',
err_name = 'error',
dq_name = 'dq',
n_name = 'nelem')
#Consider adding a weight column
# wgt_name = 'weight',
#----------------------------
def splice_2010jl_fuv():
'''
Combine all 2010jl FUV 1D extraction files
'''
flist = ['2010jl_loc_327.0_hgt_21/ocdd03010_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd03070_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd03020_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd03080_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd03030_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd030a0_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd03040_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd030b0_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd03050_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd030c0_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd03060_x1d.fits']
for ifile in flist:
add_dq_flags_to_edges(ifile)
splice_file_together(flist, '2010jl_loc_327.0_hgt_21/2010jl_fuv_x1dsum.fits')
#----------------------------
def splice_2010jl_nuv():
'''
Combine all 2010JL NUV 1D extraction files
'''
flist = ['2010jl_loc_323.0_hgt_21/ocdd030d0_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030h0_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030e0_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030i0_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030f0_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030j0_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030g0_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030k0_x1d.fits']
for ifile in flist:
add_dq_flags_to_edges(ifile)
splice_file_together(flist, '2010jl_loc_323.0_hgt_21/2010jl_nuv_x1dsum.fits')
#----------------------------
def combine_all_2010jl():
'''
Combine FUV and NUV 1D extraction files for 2010JL
'''
flist = ['2010jl_loc_327.0_hgt_21/ocdd03010_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd03070_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd03020_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd03080_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd03030_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd030a0_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd03040_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd030b0_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd03050_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd030c0_x1d.fits',
'2010jl_loc_327.0_hgt_21/ocdd03060_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030d0_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030h0_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030e0_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030i0_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030f0_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030j0_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030g0_x1d.fits',
'2010jl_loc_323.0_hgt_21/ocdd030k0_x1d.fits']
for ifile in flist:
add_dq_flags_to_edges(ifile)
splice_file_together(flist, '2010jl_all_x1dsum.fits')
#----------------------------
def splice_2005ip_fuv():
'''
Combine all 2005ip FUV 1D extraction files
'''
flist = ['2005ip_otfr/ocdd02010_x1d.fits',
'2005ip_otfr/ocdd02020_x1d.fits',
'2005ip_otfr/ocdd02030_x1d.fits',
'2005ip_otfr/ocdd02040_x1d.fits',
'2005ip_otfr/ocdd02050_x1d.fits',
'2005ip_otfr/ocdd02060_x1d.fits',
'2005ip_otfr/ocdd02070_x1d.fits',
'2005ip_otfr/ocdd02080_x1d.fits']
for ifile in flist:
add_dq_flags_to_edges(ifile)
splice_file_together(flist, '2005ip_otfr/2005ip_fuv_x1dsum.fits')
#----------------------------
def splice_2005ip_nuv():
'''
Combine all 2005ip NUV 1D extraction files
'''
flist = [#'2005ip_otfr/ocdd02090_x1d.fits', #remove from analysis until I can figure out what is going on
'2005ip_otfr/ocdd020a0_x1d.fits',
'2005ip_otfr/ocdd020b0_x1d.fits',
'2005ip_otfr/ocdd020c0_x1d.fits']
for ifile in flist:
add_dq_flags_to_edges(ifile)
splice_file_together(flist, '2005ip_otfr/2005ip_nuv_x1dsum.fits')
#----------------------------
def combine_all_2005ip():
'''
Combine FUV and NUV 1D extraction files for 2005ip
'''
flist = ['2005ip_otfr/ocdd02010_x1d.fits',
'2005ip_otfr/ocdd02020_x1d.fits',
'2005ip_otfr/ocdd02030_x1d.fits',
'2005ip_otfr/ocdd02040_x1d.fits',
'2005ip_otfr/ocdd02050_x1d.fits',
'2005ip_otfr/ocdd02060_x1d.fits',
'2005ip_otfr/ocdd02070_x1d.fits',
'2005ip_otfr/ocdd02080_x1d.fits',
#'2005ip_otfr/ocdd02090_x1d.fits', #remove from analysis until I can figure out what is going on
'2005ip_otfr/ocdd020a0_x1d.fits',
'2005ip_otfr/ocdd020b0_x1d.fits',
'2005ip_otfr/ocdd020c0_x1d.fits']
for ifile in flist:
add_dq_flags_to_edges(ifile)
splice_file_together(flist, '2005ip_all_x1dsum.fits')
#----------------------------
#----------------------------
def splice_2009ip_fuv():
'''
Combine all 2009ip FUV 1D extraction files
'''
flist = ['2009ip_otfr/ocdd01010_x1d.fits',
'2009ip_otfr/ocdd01020_x1d.fits',
'2009ip_otfr/ocdd01030_x1d.fits',
'2009ip_otfr/ocdd01040_x1d.fits',
'2009ip_otfr/ocdd01050_x1d.fits',
'2009ip_otfr/ocdd01060_x1d.fits',
'2009ip_otfr/ocdd01070_x1d.fits',
'2009ip_otfr/ocdd01080_x1d.fits']
for ifile in flist:
add_dq_flags_to_edges(ifile)
splice_file_together(flist, '2009ip_otfr/2009ip_fuv_x1dsum.fits')
#----------------------------
def splice_2009ip_nuv():
'''
Combine all 2009ip NUV 1D extraction files
'''
flist = [#'2009ip_otfr/ocdd02090_x1d.fits', #remove from analysis until I can figure out what is going on
'2009ip_otfr/ocdd020a0_x1d.fits',
'2009ip_otfr/ocdd020b0_x1d.fits',
'2009ip_otfr/ocdd020c0_x1d.fits']
for ifile in flist:
add_dq_flags_to_edges(ifile)
splice_file_together(flist, '2009ip_otfr/2009ip_nuv_x1dsum.fits')
#----------------------------
def combine_all_2009ip():
'''
Combine FUV and NUV 1D extraction files for 2009ip
'''
flist = ['2009ip_otfr/ocdd01010_x1d.fits',
'2009ip_otfr/ocdd01020_x1d.fits',
'2009ip_otfr/ocdd01030_x1d.fits',
'2009ip_otfr/ocdd01040_x1d.fits',
'2009ip_otfr/ocdd01050_x1d.fits',
'2009ip_otfr/ocdd01060_x1d.fits',
'2009ip_otfr/ocdd01070_x1d.fits',
'2009ip_otfr/ocdd01080_x1d.fits']
for ifile in flist:
add_dq_flags_to_edges(ifile)
splice_file_together(flist, '2009ip_all_x1dsum.fits')
#----------------------------
#----------------------------
if __name__ == "__main__":
splice_2010jl_fuv()
splice_2010jl_nuv()
combine_all_2010jl()
splice_2005ip_fuv()
splice_2005ip_nuv()
combine_all_2005ip()
splice_2009ip_fuv()
# splice_2009ip_nuv()
combine_all_2009ip()