In [1]:
#Import all of the relevant python modules
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter as FSF
from matplotlib.ticker import MaxNLocator
from matplotlib.ticker import MultipleLocator
In [2]:
from StellarSpectra.model import Model
from StellarSpectra.spectrum import DataSpectrum
from StellarSpectra.grid_tools import TRES, HDF5Interface
from StellarSpectra.utils import saveall
import scipy.sparse as sp
import numpy as np
myDataSpectrum = DataSpectrum.open("../../data/WASP14/WASP14-2009-06-14.hdf5", orders=np.array([22, 23]))
myInstrument = TRES()
myHDF5Interface = HDF5Interface("../../libraries/PHOENIX_TRES_F.hdf5")
myErrorInterface = HDF5Interface("../../libraries/PHOENIX_TRES_F.hdf5")
In [3]:
#Load a model using the JSON file
myModel = Model.from_json("../WASP14/model_final_22_23.json", myDataSpectrum, myInstrument, myHDF5Interface, myErrorInterface)
myOrderModel22 = myModel.OrderModels[0]
myOrderModel23 = myModel.OrderModels[1]
spec = myModel.get_data()
wl22 = spec.wls[0]
fl22 = spec.fls[0]
model_fl22 = myOrderModel22.get_spectrum()
wl23 = spec.wls[1]
fl23 = spec.fls[1]
model_fl23 = myOrderModel23.get_spectrum()
In [4]:
height = 1.8
texttop = 0.8
sargs = {"left":0.18, "right":0.82, "top":0.91, "hspace":0, "bottom":0.22}
In [13]:
ind = (wl22 >= 5144) & (wl22 <= 5150)
w = wl22[ind]
f = fl22[ind]
m = model_fl22[ind]
r = f - m
fig,ax = plt.subplots(nrows=2, figsize=(3.5,height), sharex=True)
ax[0].plot(w, f, "b", label="data", drawstyle="steps-mid")
ax[0].plot(w, m, "r", label="model", drawstyle="steps-mid")
ax[1].axhline(0, ls=":", color="0.5")
ax[1].plot(w, r, "k", drawstyle="steps-mid")
ax[1].set_xlabel(r"$\lambda$ [\AA]")
ax[1].xaxis.set_major_formatter(FSF("%.0f"))
for a in ax:
a.yaxis.set_major_locator(MaxNLocator(nbins=6, prune='both'))
fig.text(0.03, texttop, r"$f_\lambda \quad [\textrm{erg}\;\textrm{cm}^{-2}\;\textrm{s}^{-1}\;\textrm{\AA}^{-1}]$", rotation="vertical")
fig.subplots_adjust(**sargs)
saveall(fig, "../../plots/badlines0")
plt.show()
In [19]:
ind = (wl22 >= 5188) & (wl22 <= 5189.6)
w = wl22[ind]
f = fl22[ind]
m = model_fl22[ind]
r = f - m
fig,ax = plt.subplots(nrows=2, figsize=(3.5, height), sharex=True)
l0, = ax[0].plot(w, f, "b", label="data", drawstyle="steps-mid")
l1, = ax[0].plot(w, m, "r", label="model", drawstyle="steps-mid")
ax[0].legend(loc="lower right", prop={'size':10})
ax[1].axhline(0, ls=":", color="0.5")
l2, = ax[1].plot(w, r, "k", label="residuals", drawstyle="steps-mid")
ax[1].set_xlabel(r"$\lambda$ [\AA]")
ax[1].xaxis.set_major_formatter(FSF("%.1f"))
ax[1].xaxis.set_major_locator(MultipleLocator(0.4))
ax[1].legend(loc="lower right", prop={'size':10})
for a in ax:
a.yaxis.set_major_locator(MaxNLocator(nbins=5, prune='both'))
fig.text(0.03, texttop, r"$f_\lambda \quad [\textrm{erg}\;\textrm{cm}^{-2}\;\textrm{s}^{-1}\;\textrm{\AA}^{-1}]$", rotation="vertical")
fig.subplots_adjust(**sargs)
saveall(fig, "../../plots/badlines1")
plt.show()
In [16]:
ind = (wl23 >= 5257.8) & (wl23 <= 5260)
w = wl23[ind]
f = fl23[ind]
m = model_fl23[ind]
r = f - m
fig,ax = plt.subplots(nrows=2, figsize=(3.5,height), sharex=True)
ax[0].plot(w, f, "b", label="data", drawstyle="steps-mid")
ax[0].plot(w, m, "r", label="model", drawstyle="steps-mid")
ax[1].axhline(0, ls=":", color="0.5")
ax[1].plot(w, r, "k", drawstyle="steps-mid")
ax[1].set_xlabel(r"$\lambda$ [\AA]")
ax[1].xaxis.set_major_formatter(FSF("%.1f"))
ax[1].xaxis.set_major_locator(MultipleLocator(0.5))
for a in ax:
a.yaxis.set_major_locator(MaxNLocator(nbins=5, prune='both'))
ax[-1].set_xlim(5258, 5259.9)
fig.text(0.03, texttop, r"$f_\lambda \quad [\textrm{erg}\;\textrm{cm}^{-2}\;\textrm{s}^{-1}\;\textrm{\AA}^{-1}]$", rotation="vertical")
fig.subplots_adjust(**sargs)
saveall(fig, "../../plots/badlines2")
plt.show()
In [17]:
ind = (wl23 >= 5260) & (wl23 <= 5269)
w = wl23[ind]
f = fl23[ind]
m = model_fl23[ind]
r = f - m
fig,ax = plt.subplots(nrows=2, figsize=(3.5, height), sharex=True)
ax[0].plot(w, f, "b", label="data", drawstyle="steps-mid")
ax[0].plot(w, m, "r", label="model", drawstyle="steps-mid")
ax[1].axhline(0, ls=":", color="0.5")
ax[1].plot(w, r, "k", drawstyle="steps-mid")
ax[1].set_xlabel(r"$\lambda$ [\AA]")
ax[1].xaxis.set_major_formatter(FSF("%.0f"))
ax[1].xaxis.set_major_locator(MultipleLocator(2))
for a in ax:
a.yaxis.set_major_locator(MaxNLocator(nbins=5, prune='both'))
fig.text(0.03, texttop, r"$f_\lambda \quad [\textrm{erg}\;\textrm{cm}^{-2}\;\textrm{s}^{-1}\;\textrm{\AA}^{-1}]$", rotation="vertical")
fig.subplots_adjust(**sargs)
saveall(fig, "../../plots/badlines3")
plt.show()
In [8]:
ind = (wl23 >= 5260) & (wl23 <= 5269)
w = wl23[ind]
f = fl23[ind]
m = model_fl23[ind]
r = f - m
fig, ax = plt.subplots(nrows=2, sharex=True, figsize=(3.5, 2.7))
#Use the model and residuals from the previos plot.
l0, = ax[0].plot(w, f*1e13, "b", label="data", drawstyle="steps-mid")
l1, = ax[0].plot(w, m*1e13, "r", label="model", drawstyle="steps-mid")
l2, = ax[1].plot(w, r*1e13, "k", label="residuals", drawstyle="steps-mid")
for a in ax:
a.yaxis.set_major_locator(MaxNLocator(nbins=6))#, prune='lower'))
#ax[0].legend([l0, l1], ["data", "model"], loc="lower left", prop={'size':10})
#ax[1].legend([l2], ["residuals"], loc="upper left", prop={'size':10})
ax[1].set_ylim(-0.28, 0.28)
ax[1].set_xlabel(r"$\lambda$ [\AA]")
ax[1].xaxis.set_major_formatter(FSF("%.0f"))
ax[1].xaxis.set_major_locator(MultipleLocator(2))
fig.text(0.01, 0.8, r"$f_\lambda\, \times 10^{-13}\, [\textrm{erg}\;\textrm{cm}^{-2}\;\textrm{s}^{-1}\;\textrm{\AA}^{-1}]$", rotation="vertical")
fig.subplots_adjust(bottom=0.16, top=0.93, hspace=0, left=0.17, right=0.83)
saveall(fig, "../../plots/badlines")
plt.show()
In [ ]: