forked from abostroem/13287
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_labeled_combined_spec.py
117 lines (100 loc) · 4.27 KB
/
plot_labeled_combined_spec.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
from astropy.io import fits
from matplotlib import pyplot
import numpy as np
from datetime import datetime
from astropy.nddata.convolution import convolve, make_kernel
from helper_functions import add_date_to_plot
def label_spectra(ax):
'''
With a dictionary of SN spectral features, plot each feature a its wavelength making
each species a different color
Input:
ax: subplot object
object to plot lines onto
'''
line_list = {'Mg':[2796, 2802], 'SiIII/CIII':[1883, 1892, 1906, 1909],
'NIII':[1747, 1753], 'OIII':[1661, 1666], 'CIV':[1549, 1551],
'NIV':[1483, 1488], 'HeII':[1640], 'NeIII':[1815], 'NV':[1240],
'SiIV':[1394, 1403], 'CII':[2322, 2329]}
colors = ['r', 'orange', 'gold', 'g', 'c', 'purple', 'lime', 'pink', 'brown', 'grey', 'm']
for color_indx, elem in enumerate(line_list.keys()):
for iline in line_list[elem]:
ax.axvline(iline, color = colors[color_indx])
ax.axvline(iline, color = colors[color_indx], label = elem)
ax.legend()
return ax
def add_date_to_plot(ax):
today = datetime.today()
xlims = ax.get_xlim()
ylims = ax.get_ylim()
ax.text(xlims[1], -.06*(ylims[1] - ylims[0])+ylims[0], '{}-{}-{}'.format(today.year, today.month, today.day))
def deredshift_wavelength(wavelength, redshift):
deredshift_wl = wavelength/(redshift + 1.0)
return deredshift_wl
def plot_2010jl():
'''
Create a plot of the combined NUV and FUV spectrum of SN 2010jl, label the common SN
lines with different colors for different species and save
'''
redshift = 0.0107 #http://www.astronomy.ohio-state.edu/~stoll/stoll2011.pdf
tbdata = fits.getdata('2010jl_all_x1dsum.fits', 1)
sdqflags = fits.getval('2010jl_all_x1dsum.fits', 'sdqflags', 1)
good_indx = np.where(tbdata['dq'][0]&sdqflags == 0)
fig = pyplot.figure(figsize = [20, 10])
ax = fig.add_subplot(1,1,1)
deredshift_wl = deredshift_wavelength(tbdata['wavelength'][0][good_indx], redshift)
smoothed_signal = convolve.convolve(tbdata['flux'][0][good_indx], make_kernel.make_kernel([15],15,'boxcar'))
ax.plot(deredshift_wl, smoothed_signal, 'b')
ax = label_spectra(ax)
ax.set_xlabel('Rest Wavelength ($\AA$)')
ax.set_ylabel('Flux (ergs/cm^2/s/$\AA$)')
ax.set_title('Preliminary HST/STIS Spectrum of SN 2010jl (smoothed by 15 pix)')
ax.set_ylim(0, 0.25E-15)
add_date_to_plot(ax)
pyplot.savefig('2010jl_combined_labeled.pdf')
def plot_2005ip():
'''
Create a plot of the combined NUV and FUV spectrum of SN 2005ip, label the common SN
lines with different colors for different species and save
'''
redshift = 0.0072
tbdata = fits.getdata('2005ip_all_x1dsum.fits', 1)
sdqflags = fits.getval('2005ip_all_x1dsum.fits', 'sdqflags', 1)
good_indx = np.where(tbdata['dq'][0]&sdqflags == 0)
fig = pyplot.figure(figsize = [20, 10])
ax = fig.add_subplot(1,1,1)
deredshift_wl = deredshift_wavelength(tbdata['wavelength'][0][good_indx], redshift)
smoothed_signal = convolve.convolve(tbdata['flux'][0][good_indx], make_kernel.make_kernel([15],15,'boxcar'))
ax.plot(deredshift_wl, smoothed_signal, 'b')
ax = label_spectra(ax)
ax.set_xlabel('Rest Wavelength ($\AA$)')
ax.set_ylabel('Flux (ergs/cm^2/s/$\AA$)')
ax.set_title('Preliminary HST/STIS Spectrum of SN 2005ip (smoothed by 15 pix)')
ax.set_ylim(-0.1E-15, 0.25E-15)
add_date_to_plot(ax)
pyplot.savefig('2005ip_combined_labeled.pdf')
def plot_2009ip():
'''
Create a plot of the combined NUV and FUV spectrum of SN 2009ip, label the common SN
lines with different colors for different species and save
'''
redshift = 0.0072
tbdata = fits.getdata('2009ip_all_x1dsum.fits', 1)
sdqflags = fits.getval('2009ip_all_x1dsum.fits', 'sdqflags', 1)
good_indx = np.where(tbdata['dq'][0]&sdqflags == 0)
fig = pyplot.figure(figsize = [20, 10])
ax = fig.add_subplot(1,1,1)
deredshift_wl = deredshift_wavelength(tbdata['wavelength'][0][good_indx], redshift)
smoothed_signal = convolve.convolve(tbdata['flux'][0][good_indx], make_kernel.make_kernel([15],15,'boxcar'))
ax.plot(deredshift_wl, smoothed_signal, 'b')
ax = label_spectra(ax)
ax.set_xlabel('Rest Wavelength ($\AA$)')
ax.set_ylabel('Flux (ergs/cm^2/s/$\AA$)')
ax.set_title('Preliminary HST/STIS Spectrum of SN 2009ip (smoothed by 15 pix)')
ax.set_ylim(-0.1E-15, 0.25E-15)
add_date_to_plot(ax)
pyplot.savefig('2009ip_combined_labeled.pdf')
if __name__ == "__main__":
plot_2010jl()
plot_2005ip()
plot_2009ip()