In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from astrotools.filters import Filters
from astrotools.models import BlackbodySED
from scipy.optimize import leastsq
%matplotlib inline
plt.rcParams['figure.figsize'] = 16, 8
In [45]:
sed = BlackbodySED(10000, 3e15, redshift=0.609, wavelength=np.arange(1000, 10000), template='/Users/szymon/Dropbox/SLSN/Templates/SLSN_12000.txt')
filters = Filters(load_all=True)
In [46]:
sed.synthesis_photometry(filter_name=['DES_g', 'DES_r', 'DES_i', 'DES_z'], filters=filters)
Out[46]:
In [47]:
sed.update_blackbody(temperature=15000)
In [48]:
sed.synthesis_photometry(filter_name=['DES_g', 'DES_r', 'DES_i', 'DES_z'], filters=filters)
Out[48]:
In [49]:
def R(t, R0, dR):
return (R0 + dR * t) * 1e15
In [50]:
df_list = pd.read_csv('/Users/szymon/Dropbox/SLSN/For_Szymon/SLSN_fitted.list')
df_list['snname'] = df_list['name'].map(lambda x : x.rstrip('.txt').split('_')[-1])
SN = 7
df_list.head()
Out[50]:
In [51]:
df = pd.read_csv('/Users/szymon/Dropbox/SLSN/For_Szymon/GP_fits_all/' + df_list['snname'][SN] + '.lc')
filter_names = df.columns[range(1, df.shape[1], 2)].values
df_matrix = df.as_matrix().T
mjd = df_matrix[0]
flux = df_matrix[range(1, df.shape[1], 2)].T
err = df_matrix[1:][range(1, df.shape[1], 2)].T
df.head()
Out[51]:
In [52]:
def res(T, sed, flux, err, i):
sed.update_blackbody(temperature=T)
return (flux[i] - sed.synthesis_photometry(filter_name=filter_names, filters=filters)) # / err[i]
In [53]:
fit = []
T_arr = []
R_arr = []
for i in range(mjd.size):
R_fit = R(mjd[i], df_list['p_0'][SN], df_list['p_1'][SN])
R_arr.append(R_fit)
sed.update_blackbody(radius=R_fit)
T_fit, out = leastsq(res, x0=20000, args=(sed, flux, err, i), full_output=0)
T_arr.append(T_fit)
fit.append(np.concatenate([[mjd[i]], sed.synthesis_photometry(filter_name=filter_names, filters=filters)]))
fit = np.array(fit)
fit = pd.DataFrame(fit, columns=['mjd']+list(filter_names))
fit.head()
Out[53]:
In [54]:
plt.plot(df['mjd'], df['DES_z'], label='Original')
plt.plot(fit['mjd'], fit['DES_z'], label='Re-fitted')
plt.legend(loc='best')
Out[54]:
In [55]:
df_T_R = pd.read_csv('/Users/szymon/Dropbox/SLSN/For_Szymon/' + df_list['name'][SN], header=None)
df_T_R.columns = ['mjd', 'R', 'dR', 'T', 'dT']
In [56]:
df_T_R.head()
Out[56]:
In [57]:
plt.plot(mjd, df_T_R['R'], label='Original')
plt.plot(mjd, R_arr, label='Re-fitted')
plt.legend(loc='best')
Out[57]:
In [58]:
plt.cla()
plt.plot(mjd, df_T_R['T'], label='Original')
plt.plot(mjd, T_arr, label='Re-fitted')
plt.legend(loc='best')
Out[58]:
In [59]:
i = 10
plt.plot(flux[i])
sed.update_blackbody(radius=R_arr[i], temperature=T_arr[i])
plt.plot(sed.synthesis_photometry(filter_name=filter_names, filters=filters))
Out[59]: