def test_fit_time_popov_SN1999em(self): jd_shift = 20. dm = -29.38 # D = 7.5e6 pc # dm = -30.4 # D = 12.e6 pc curves = sn1999em.read_curves() lc = curves.get('V') lc.mshift = dm time = lc.Time - lc.Tmin # time = np.exp(np.linspace(np.log(start), np.log(end), n)) popov = Popov('test', R=450., M=15., Mni=0.04, E=0.7) mags = popov.MagBol(time) # fit tshift = myfit(mags, lc) # plot ax = popov.plot_Lbol(time) x = lc.Time + tshift # x = lc.Time + jd_shift + res y = lc.Mag ax.plot(x, y, label='%s SN 1999em' % lc.Band.Name, ls=":", color='red', markersize=8, marker="o") plt.show()
def leastsq(p, fjac): mdl = Popov('test', R=p[0], M=p[1], Mni=p[2], E=p[3]) l_dt = p[4] t = time + l_dt m = mdl.MagBol(t) res = (lc.Mag - m)**2 / m w = np.exp(-(max(abs(lc.Mag)) - abs(lc.Mag)) * 2) # weight w = 1. # w = w / max(w) if lc.IsErr: res = res * w / lc.Err return 0, res
def plot(ax, dic=None): arg = [] if dic is not None and 'args' in dic: arg = dic['args'] r_init = 450. # M_sun m_tot = 15. # M_sun m_ni = 0.07 # M_sun e_tot = 0.7 # FOE if len(arg) > 0: r_init = float(arg.pop(0)) if len(arg) > 0: m_tot = float(arg.pop(0)) if len(arg) > 0: e_tot = float(arg.pop(0)) if len(arg) > 0: m_ni = float(arg.pop(0)) n = 100 start, end = map(lambda x: max(x, 0.1), ax.get_xlim()) time = np.exp(np.linspace(np.log(start), np.log(end), n)) ppv = Popov('plugin', R=r_init, M=m_tot, Mni=m_ni, E=e_tot) mags = ppv.MagBol(time) mags_ni = Lum2MagBol(ppv.e_rate_ni(time)) lbl = 'R M E Mni: %4.1f %2.1f %2.1f %3.2f' % (r_init, m_tot, e_tot, m_ni) print("Plot Popov model: %s " % lbl) times = { 'Diffusion time [d]': ppv.t_d, 'Expansion time [d]': ppv.t_e, 'T surf > Tion [d]': ppv.t_i, 'Max bol time [d]': ppv.t_max, 'Plateau duration time [d]': ppv.t_p } for k, v in times.items(): print(" %25s: %8.2f " % (k, v / phys.d2s)) ax.plot(time, mags, color='blue', ls='-.', label=lbl, lw=2.5) ax.plot(time, mags_ni, color='red', ls='-.', label='Ni56 & Co56', lw=2.)