-
Notifications
You must be signed in to change notification settings - Fork 0
/
telluric.py
157 lines (132 loc) · 6.27 KB
/
telluric.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
#!/usr/bin/env python
#!/user/covey/iraf/mypython
'''
Original code by Alejandro Nunez
Version 1.0 (Last Modified 2017-12-16)
'''
import os
import astropy.io.ascii as at
from pyraf import iraf
from pyraf.iraf import noao
from pyraf.iraf import imutil, imred, crutil, ccdred, echelle, images, tv
from pyraf.iraf import system, twodspec, longslit, apextract, onedspec, astutil
from list_utils import read_reduction_list
def telluric():
'''
Get subsets of spectra: flats, lamps, biases, objects and std spectra
Instrument can be Modspec or OSMOS.
instrument - String; can be Modspec or OSMOS.
imagelist - String; name of ascii file generated by list_utils.prep() function.
'''
# Read input file
image_dict = read_reduction_list(imagelist)
science_list = image_dict["science_list"]
science_names = image_dict["science_names"]
std_list = image_dict["std"]
std_names = image_dict["std_names"]
# Find the number of objects in each list
numscience = len(science_list)
numstds = len(std_list)
def fluxcal(instrument, imagelist="to_reduce.lis"):
'''
Get subsets of spectra: flats, lamps, biases, objects and std spectra
Instrument can be Modspec or OSMOS.
instrument - String; can be Modspec or OSMOS.
imagelist - String; name of ascii file generated by list_utils.prep() function.
'''
# Read input file
image_dict = read_reduction_list(imagelist)
science_list = image_dict["science_list"]
science_names = image_dict["science_names"]
std_list = image_dict["std"]
std_names = image_dict["std_names"]
# Find the number of objects in each list
numscience = len(science_list)
numstds = len(std_list)
# Do flux calibration - start with setting airmass to middle of exposure
iraf.astutil.setairmass.observatory = 'kpno'
iraf.astutil.setairmass.intype = 'middle'
iraf.astutil.setairmass.outtype = 'effective'
iraf.astutil.setairmass.ra = 'RA'
iraf.astutil.setairmass.dec = 'DEC'
iraf.astutil.setairmass.equinox = 'EQUINOX'
if instrument.upper() == 'OSMOS':
iraf.astutil.setairmass.st = 'LST'
else:
iraf.astutil.setairmass.st = 'ST'
iraf.astutil.setairmass.ut = 'TIME-OBS'
iraf.astutil.setairmass.date = 'DATE-OBS'
iraf.astutil.setairmass.exposure = 'EXPTIME'
iraf.astutil.setairmass.airmass = 'AIRMASS'
iraf.astutil.setairmass.utmiddle = 'MIDUT'
iraf.astutil.setairmass.scale = '750.0'
iraf.astutil.setairmass.show = 'yes'
iraf.astutil.setairmass.update = 'yes'
iraf.astutil.setairmass.override = 'yes'
for science_file in science_list:
iraf.astutil.setairmass(images='wavecal/dc.' + science_file)
# Run standard on our standard star observations
iraf.noao.onedspec.standard.samestar = 'no'
# Frequently observed different stars, changing that value
iraf.noao.onedspec.standard.beam_switch = 'no'
iraf.noao.onedspec.standard.apertures = ''
iraf.noao.onedspec.standard.bandwidth = '20'
iraf.noao.onedspec.standard.bandsep = '30'
iraf.noao.onedspec.standard.fnuzero = '3.68E-20'
iraf.noao.onedspec.standard.extinction = 'onedstds$kpnoextinct.dat'
if instrument.upper() == 'OSMOS':
iraf.noao.onedspec.standard.caldir = 'onedstds$irscal/'
else:
iraf.noao.onedspec.standard.caldir = 'onedstds$spec50cal/'
iraf.noao.onedspec.standard.observatory = 'KPNO'
iraf.noao.onedspec.standard.interact = 'yes'
iraf.noao.onedspec.standard.graphics = 'stdgraph'
iraf.noao.onedspec.standard.cursor = ''
for i,std_file in enumerate(std_list):
this_std_name = std_names[i].split(".")[0]
iraf.noao.onedspec.standard.star_name = this_std_name
iraf.noao.onedspec.standard(input = 'wavecal/dc.' + std_file,
output = 'stdfile')
# Run sensfunc to get sensitivity functions out
iraf.noao.onedspec.sensfunc.apertures = ''
iraf.noao.onedspec.sensfunc.ignoreaps = 'yes'
iraf.noao.onedspec.sensfunc.logfile = 'sensfunclog'
iraf.noao.onedspec.sensfunc.extinction = 'onedstds$kpnoextinct.dat'
iraf.noao.onedspec.sensfunc.observatory = 'KPNO'
iraf.noao.onedspec.sensfunc.function = 'chebyshev'
iraf.noao.onedspec.sensfunc.order = '3'
iraf.noao.onedspec.sensfunc.interactive = 'yes'
iraf.noao.onedspec.sensfunc.graphs = 'sr'
iraf.noao.onedspec.sensfunc.marks = 'plus cross box'
iraf.noao.onedspec.sensfunc.colors = '2 1 3 4'
iraf.noao.onedspec.sensfunc.cursor = ''
iraf.noao.onedspec.sensfunc.device = 'stdgraph'
iraf.noao.onedspec.sensfunc(standards = 'stdfile', sensitivity = 'sens', newextinction = 'extinct.dat')
# Use those sensitivity functions to calibrate the data
iraf.noao.onedspec.calibrate.extinct = 'yes'
iraf.noao.onedspec.calibrate.flux = 'yes'
iraf.noao.onedspec.calibrate.extinction = 'onedstds$kpnoextinct.dat'
iraf.noao.onedspec.calibrate.observatory = 'KPNO'
iraf.noao.onedspec.calibrate.ignoreaps = 'yes'
iraf.noao.onedspec.calibrate.fnu = 'no'
# iraf.noao.onedspec.calibrate.airmass = 'QAIRMASS'
# iraf.noao.onedspec.calibrate.exptime = 'QEXPTIME'
# Find the max and min regions used by the sensitivity function
# first, calculate the starting line of data in sensfunclog
# because it depends on the number of standard stars
sf_start = 7 + numstds
sensfunc_log = at.read("sensfunclog",data_start=sf_start)
sensfunc_wave = sensfunc_log['col1']
# Final flux calibration
# and trimming beyond the good flux calibration region
os.mkdir('finals')
for j,science_file in enumerate(science_list):
iraf.noao.onedspec.calibrate(input = 'wavecal/dc.' + science_file,
output = 'finals/' + science_names[j],
sensitivity = 'sens')
iraf.noao.onedspec.scopy(input='finals/' + science_names[j],
output = 'finals/trim.' + science_names[j],
w1=sensfunc_wave[0],w2=sensfunc_wave[-1],
format='multispec', rebin='no', apertures='',
bands='', verbose='no')
iraf.flprcache()