Пример #1
0
    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()
Пример #2
0
    def test_popov_SN1999em_emcee(self):
        n = 100
        start, end = 0.1, 200.
        jd_shift = 20.
        dm = -29.38  # D = 7.5e6 pc
        # dm = -30.4  # D = 12.e6 pc
        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)
        lc_m = popov.LCBol(time)

        # ax = popov.plot_Lbol(time)
        # sn1999em.plot_ubv(ax, path=sn1999em.sn_path, jd_shift=jd_shift, mshift=dm)
        # plt.show()
        curves_o = sn1999em.read_curves()
        lc_o = curves_o.get('V')
        lc_o.mshift = dm
        print("Run: find tshift with bayesian: obs band %s with %s ..." %
              (lc_o.Band.Name, popov))
        fitter = FitMCMC()
        fitter.is_debug = True
        res = fitter.fit_lc(lc_o, lc_m)
        tshift, tsigma = res.tshift, res.tsigma
        print("Result: tshift= %s tsigma= %s ..." % (tshift, tsigma))

        ax = popov.plot_Lbol(time)
        lcp.lc_plot(lc_m, ax)
        lcp.lc_plot(lc_o, ax, is_line=False)
        # sn1999em.plot_ubv(ax, path=sn1999em.sn_path, jd_shift=-tshift, mshift=dm)
        plt.show()
Пример #3
0
    def test_plot_lc(self):
        n = 100
        start, end = 0.1, 200.
        time = np.exp(np.linspace(np.log(start), np.log(end), n))

        popov = Popov('test', R=400., M=15., Mni=0.04, E=1.)
        popov.plot_Lbol(time)
        plt.show()
Пример #4
0
    def test_plot_lc(self):
        n = 100
        start, end = 0.1, 200.
        time = np.exp(np.linspace(np.log(start), np.log(end), n))

        popov = Popov('test', R=400., M=15., Mni=0.04, E=1.)
        popov.plot_Lbol(time)
        plt.show()
Пример #5
0
    def test_popov_SN87A(self):
        n = 100
        start, end = 0.1, 1200.
        jd_shift = -2446850.  # moment of explosion SN 1987A, Hamuy 1988, doi:10.1086/114613
        dm = -18.6  # D = 7.5e6 pc
        time = np.exp(np.linspace(np.log(start), np.log(end), n))

        popov = Popov('test', R=50., M=15., Mni=0.07, E=1.)
        ax = popov.plot_Lbol(time)
        sn87a.plot_ubv(ax, path=sn87a.sn_path, jd_shift=jd_shift, mshift=dm)
        plt.show()
Пример #6
0
 def test_popov_rednova(self):
     n = 100
     start, end = 0.1, 90.
     jd_shift = 10.
     dm = 24.38  # D = 7.5e5 pc
     # dm = -30.4  # D = 12.e6 pc
     time = np.exp(np.linspace(np.log(start), np.log(end), n))
     popov = Popov('test', R=35., M=6., Mni=0., E=0.008)
     ax = popov.plot_Lbol(time)
     rednova.plot_ubv(ax, path=rednova.sn_path, jd_shift=jd_shift, mshift=-dm)
     plt.show()
Пример #7
0
 def test_popov_SN1999em(self):
     n = 100
     start, end = 0.1, 200.
     jd_shift = 20.
     dm = -29.38  # D = 7.5e6 pc
     # dm = -30.4  # D = 12.e6 pc
     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)
     ax = popov.plot_Lbol(time)
     sn1999em.plot_ubv(ax, path=sn1999em.sn_path, jd_shift=jd_shift, mshift=dm)
     plt.show()
Пример #8
0
    def test_popov_SN87A(self):
        n = 100
        start, end = 0.1, 1200.
        jd_shift = -2446850.  # moment of explosion SN 1987A, Hamuy 1988, doi:10.1086/114613
        dm = -18.6  # D = 7.5e6 pc
        time = np.exp(np.linspace(np.log(start), np.log(end), n))

        popov = Popov('test', R=50., M=15., Mni=0.07, E=1.)
        ax = popov.plot_Lbol(time)
        sn87a.plot_ubv(ax, path=sn87a.sn_path, jd_shift=jd_shift, mshift=dm)
        plt.show()
Пример #9
0
 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
Пример #10
0
 def test_popov_rednova(self):
     n = 100
     start, end = 0.1, 90.
     jd_shift = -2500000 + 42963.
     dm = -24.38  # D = 7.5e5 pc
     # dm = -30.4  # D = 12.e6 pc
     time = np.exp(np.linspace(np.log(start), np.log(end), n))
     popov = Popov('test', R=35., M=1., Mni=0., E=0.002)
     ax = popov.plot_Lbol(time)
     rednova.plot_ubv(ax,
                      path=rednova.sn_path,
                      jd_shift=jd_shift,
                      mshift=dm)
     plt.show()
Пример #11
0
 def test_popov_SN1999em(self):
     n = 100
     start, end = 0.1, 200.
     jd_shift = 20.
     dm = -29.38  # D = 7.5e6 pc
     # dm = -30.4  # D = 12.e6 pc
     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)
     ax = popov.plot_Lbol(time)
     sn1999em.plot_ubv(ax,
                       path=sn1999em.sn_path,
                       jd_shift=jd_shift,
                       mshift=dm)
     plt.show()
Пример #12
0
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.)
Пример #13
0
    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()
Пример #14
0
def popov_fit(lc,
              R0,
              M0,
              Mni0=None,
              E0=None,
              dt0=None,
              is_verbose=True,
              xtol=1e-10,
              ftol=1e-10,
              gtol=1e-10):
    if is_verbose:
        quiet = 0
    else:
        quiet = 1

    time = lc.Time

    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

    parinfo = [
        {
            'value': R0,
            'limited': [1, 1],
            'limits': [10., 1500e0]
        }, {
            'value': M0,
            'limited': [1, 1],
            'limits': [1., 150.]
        }
        # {'value': Mni0, 'limited': [1, 1], 'limits': [0.0000001, 0.00001]},
        # , {'value': E0,   'limited': [1, 1], 'limits': [0.01, 5.]}
        # , {'value': dt0,  'limited': [1, 1], 'limits': [-200., 250.]}
    ]
    if Mni0 is not None:
        parinfo.append({'value': Mni0, 'limited': [1, 1], 'limits': [0., 15.]})
    else:
        parinfo.append({'value': 0.01, 'fixed': 1})
    if E0 is not None:
        parinfo.append({'value': E0, 'limited': [1, 1], 'limits': [0.01, 5.]})
    else:
        parinfo.append({'value': 1., 'fixed': 1})
    if dt0 is not None:
        parinfo.append({
            'value': dt0,
            'limited': [1, 1],
            'limits': [-200., 250.]
        })
    else:
        parinfo.append({'value': 0., 'fixed': 1})

    result = ps.mpfit.mpfit(leastsq,
                            parinfo=parinfo,
                            quiet=quiet,
                            maxiter=200,
                            ftol=ftol,
                            gtol=gtol,
                            xtol=xtol)
    if result.status == 5:
        print('Maximum number of iterations exceeded in mangle_spectrum')

    ppv = Popov('test',
                R=result.params[0],
                M=result.params[1],
                Mni=result.params[2],
                E=result.params[3])
    tshift = result.params[4]

    if is_verbose:
        print("The final params are: R=%f M=%f Mni=%f E=%f; dt = %f " %
              (result.params[0], result.params[1], result.params[2],
               result.params[3], tshift))
    return ppv, tshift