forked from abostroem/13287
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_2010jl.py
162 lines (134 loc) · 5.58 KB
/
extract_2010jl.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
from astropy.io import fits
from stistools.x1d import x1d
import numpy as np
import os
import sys
import shutil
import glob
from helper_functions import get_repository_path
def make_output_directory(extraction_box_height, extraction_box_start, sn_name, overwrite = False):
'''
Create an output directory for the extracted files to go into with the name
<sn_name>_loc_<extraction_box_start>_hgt_<extraction_box_height>
User will be asked before files are deleted if directory already exists
'''
output_dir = '{}_loc_{}_hgt_{}'.format(sn_name, extraction_box_start, extraction_box_height)
repo_path = get_repository_path()
new_dir_path = os.path.join(repo_path, output_dir)
if os.path.exists(new_dir_path):
if overwrite == False:
delete_dir = raw_input('{} exists, delete contents? y, n '.format(new_dir_path))
if delete_dir == 'n':
sys.exit('Output path already exists and you don\'t want to overwrite it')
flist = glob.glob(os.path.join(new_dir_path, 'ocdd*'))
for ifile in flist:
os.remove(ifile)
else:
os.makedirs(new_dir_path)
return new_dir_path
#----------------------------
def extract_for_a_single_dither_position(dither_exposure_names, dither_number, dither_step,
repo_path, output_dir,
extraction_box_start, extraction_box_height,
maxsearch = 0):
'''
Given a list of exposure names (corresponding to a dither number), extract a 1D spectrum
using Calstis.x1d.
Input:
dither_exposure_names: list
list of exposure numbers (as strings) to be extracted
dither_number: int
number to be multiplied by dither_step to create the offset from the extraction
box start
dither_step : float
the number of pixels in each dither step
repo_path : str
path to local repository
output_dir : str
directory where extracted files will be saved. flt and wave files are also copied
extraction_box_start : float
extraction location for the first dither position (y pixel)
extraction_box_height : int
height of the extraction box
maxsearch : int
the number of y offsets from the extraction_box_start which are searched to
find the spectrum.
Output:
x1d files
'''
os.environ['oref'] = os.path.join(repo_path, 'oref')+'/'
for exposure_number in dither_exposure_names:
input_filename = 'ocdd030{}_flt.fits'.format(exposure_number)
shutil.copy(os.path.join(repo_path, '2010jl_otfr', input_filename),
os.path.join(output_dir, input_filename))
shutil.copy(os.path.join(repo_path, '2010jl_otfr', input_filename.replace('flt', 'wav')),
os.path.join(output_dir, input_filename.replace('flt', 'wav')))
print input_filename
print output_dir
x1d(input = os.path.join(output_dir, input_filename),
a2center = extraction_box_start + (dither_number -1) * dither_step,
extrsize = extraction_box_height,
maxsrch = maxsearch,
verbose = True,
trailer = os.path.join(output_dir, input_filename.replace('flt.fits', 'trl.txt')))
#----------------------------
def extract_fuv_2010jl():
'''
Defines extraction location for 2010jl. Data taken with the FUV MAMA using 4 along
the slit dithers.
The MAMA along-the-slit dither pattern is specified with point spacing = 1 arcseconds
For the FUV plate scale = 0.0246 arcsec/pix --> 1 arcsecond = 40.6504065 pixels.
The dither position centers the target at ycenter = 340
'''
extraction_box_height = 21 #pixels
extraction_box_start = 195.+132. #340
dither_step = 40.65
repo_path = get_repository_path()
output_dir = make_output_directory(extraction_box_height, extraction_box_start, '2010jl')
extract_for_a_single_dither_position(['10', '50', '90'], 1, dither_step,
repo_path, output_dir,
extraction_box_start, extraction_box_height)
extract_for_a_single_dither_position(['20', '60', 'a0'], 2, dither_step,
repo_path, output_dir,
extraction_box_start, extraction_box_height)
extract_for_a_single_dither_position(['30', '70', 'b0'], 3, dither_step,
repo_path, output_dir,
extraction_box_start, extraction_box_height)
extract_for_a_single_dither_position(['40', '80', 'c0'], 4, dither_step,
repo_path, output_dir,
extraction_box_start, extraction_box_height)
#----------------------------
def extract_nuv_2010jl():
'''
Defines extraction location for 2010jl. Data taken with the NUV MAMA using 4 along
the slit dithers.
The MAMA along-the-slit dither pattern is specified with point spacing = 1 arcseconds
For the NUV plate scale = 0.0248 arcsec/pix --> 1 arcsecond = 40.32 pixels.
The dither position centers the target at ycenter = 461 (340 + 120.8)
'''
extraction_box_height = 21 #pixels
extraction_box_start = 262.+61.
dither_step = 40.32
repo_path = get_repository_path()
output_dir = make_output_directory(extraction_box_height, extraction_box_start, '2010jl')
extract_for_a_single_dither_position(['d0', 'h0'], 1, dither_step,
repo_path, output_dir,
extraction_box_start, extraction_box_height,
maxsearch = 0)
extract_for_a_single_dither_position(['e0', 'i0'], 2, dither_step,
repo_path, output_dir,
extraction_box_start, extraction_box_height,
maxsearch = 0)
extract_for_a_single_dither_position(['f0', 'j0'], 3, dither_step,
repo_path, output_dir,
extraction_box_start, extraction_box_height,
maxsearch = 0)
extract_for_a_single_dither_position(['g0', 'k0'], 4, dither_step,
repo_path, output_dir,
extraction_box_start, extraction_box_height,
maxsearch = 0)
#----------------------------
#----------------------------
if __name__ == "__main__":
extract_fuv_2010jl()
extract_nuv_2010jl()