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 [9]:
from StellarSpectra.model import Model
from StellarSpectra.spectrum import DataSpectrum
from StellarSpectra.grid_tools import SPEX, HDF5Interface
from StellarSpectra.utils import saveall
from StellarSpectra import utils
import scipy.sparse as sp
import numpy as np
myDataSpectrum = DataSpectrum.open("../../data/Gl51/Gl51RA.hdf5", orders=np.array([0]))
myInstrument = SPEX()
myHDF5Interface = HDF5Interface("../../libraries/PHOENIX_SPEX_M.hdf5")
myErrorHDF5Interface = HDF5Interface("../../libraries/PHOENIX_SPEX_M.hdf5")
In [4]:
#Load a model using the JSON file
myModel = Model.from_json("Gl51_model0_final.json", myDataSpectrum, myInstrument, myHDF5Interface, myErrorHDF5Interface)
myOrderModel = myModel.OrderModels[0]
spec = myModel.get_data()
wl = spec.wls[0]
fl = spec.fls[0]
model_fl = myOrderModel.get_spectrum()
residuals = fl - model_fl
cheb = myOrderModel.get_Cheb()
In [5]:
draws = np.load("Gl51_draws.npy").T
In [6]:
#Colorbrewer bands
s3 = '#fee6ce'
s2 = '#fdae6b'
s1 = '#e6550d'
In [14]:
fig, ax = plt.subplots(nrows=2, figsize=(7,3), sharex=True)
wlm = wl * 1e-4 #convert to microns
l0, = ax[0].plot(wlm, fl*1e14, "b")
l1, = ax[0].plot(wlm, model_fl*1e14, "r")
ax[0].annotate("data", (0.86, 0.75), xycoords="axes fraction", ha="right", color="b", size=9)
ax[0].annotate("model", (0.97, 0.75), xycoords="axes fraction", ha="right", color="r", size=9)
#ax[0].legend([l0, l1], ["data", "model"], loc="upper right", ncol=2, prop={'size':10})
ax[0].yaxis.set_major_locator(MaxNLocator(nbins=7, prune='lower'))
#Jump again and now plot the envelope of the draws
min_spec, max_spec = utils.std_envelope(draws)
ax[1].fill_between(wlm, 3e14*min_spec, 3e14*max_spec, zorder=0, color=s3)
ax[1].fill_between(wlm, 2e14*min_spec, 2e14*max_spec, zorder=0, color=s2)
ax[1].fill_between(wlm, 1e14*min_spec, 1e14*max_spec, zorder=0, color=s1)
ax[1].plot(wl, residuals*1e14, "w", lw=1.8, zorder=1, ls="steps-mid")
l2, = ax[1].plot(wlm, residuals*1e14, "k", zorder=1)
ax[1].xaxis.set_major_formatter(FSF("%.1f"))
ax[1].set_xlabel(r"$\lambda$ [$\mu$m]")
scale = 1.5 * np.max(np.abs(residuals)) * 1e14
ax[0].yaxis.set_major_locator(MaxNLocator(nbins=6, prune='lower'))
ax[1].yaxis.set_major_locator(MaxNLocator(nbins=6, prune='upper'))
ax[1].set_ylim(-scale, scale)
ax[1].set_xlim(np.min(wlm), np.max(wlm))
ax[1].annotate("residuals", (0.97, 0.8), xycoords="axes fraction", ha="right", color="k", size=9)
#ax[1].legend([l2], ["residuals"], loc="upper right", prop={'size':10})
fig.subplots_adjust(hspace=0, left=0.1, right=0.9, bottom=0.17, top=0.93)
fig.text(0.01, 0.83, r"$f_\lambda\, \times 10^{-14}\, \quad [\textrm{erg}\;\textrm{cm}^{-2}\;\textrm{s}^{-1}\;\textrm{\AA}^{-1}]$", rotation="vertical")
saveall(fig, "../../plots/residuals_Gl51_logg")
plt.show()
In [ ]: