Пример #1
0
def plot_one(rates, plotname, *p, frac=0.05, age=13.6):
    brates = u.gimme_rebinned_data(rates,
                                   splits=arange(0, 1.167, 0.167).tolist())
    scale_k = quad(imf.salpeter, 3, 8)[0] / quad(imf.salpeter1, 0.1, 125)[0]
    scale = scale_k * 0.7**2. * 1e4  ## factors of h...
    dt = 0.05
    tt = arange(0.1, age, dt)  ## forward time
    lbt = age - tt
    zz = [ct.cosmoz(x) for x in lbt]

    sfh = rz.sfr_behroozi_12(tt)
    dtd = step_dtd(tt, *p)
    norm_dtd = sum(step_dtd(tt, *p)) * dt
    dtd = dtd / norm_dtd

    tmp = convolve(
        sfh, dtd,
        'full') * dt * frac * scale  ## now convolved result in forward time
    rate_fn = tmp[:len(dtd)]
    clf()
    ax = subplot(111)
    ax2 = ax.twinx()
    ax2.plot(zz, sfh, 'r-')
    ax.plot(zz, rate_fn, 'k-')
    ax.errorbar(rates[:, 0],
                rates[:, 1],
                yerr=[rates[:, 3], rates[:, 2]],
                fmt='o',
                color='0.6')
    ax.errorbar(brates[:, 0],
                brates[:, 1],
                yerr=[brates[:, 3], brates[:, 2]],
                xerr=[brates[:, 5], brates[:, 4]],
                fmt='o',
                color='0.0',
                zorder=10)

    pwrl = (-1.0, 1.0)
    ax.set_xlim(0, 2.5)
    ax.set_xlabel('Redshift')
    ax.set_ylabel(r'SN Ia Rate')
    ax.set_ylabel(r'$10^{-4}$ SNe Ia per year per Mpc$^3$')
    ax2.set_ylabel(r'SF Rate')

    ax3 = axes([0.65, 0.6, 0.23, 0.2])
    ax3.plot(tt, dtd, 'b-',
             label='Fit')  #label='Norm = %1.1f' %(simps(dtd,x=time)))
    ax3.plot(tt, rz.powerdtd(tt, *pwrl), 'b:', label=r'$t^{%.1f}$' % (pwrl[0]))
    pn = (-20, 8.8, 11)
    ax3.plot(tt, rz.dtdfunc(tt, *pn), 'b--', label='Best model')
    ax.set_title(r' $k=%.4f$ M$_{\odot}^{-1}$, $f=%2.1f\%%$' %
                 (scale_k, frac * 100))

    ax3.set_ylabel('$\Phi$')
    ax3.set_xlabel('Delay Time (Gyr)')
    ax3.set_xlim(0, 12)
    ax3.set_ylim(0, 1.3)
    ax3.legend(frameon=False)
    savefig(plotname)
    return ()
Пример #2
0
def lnprob(p, x, y, yerr):
    lp = lnprior(p)
    if not isfinite(lp):
        return (-np.inf)
    else:
        return (lp + lnlike(p, x, y, yerr))


if __name__ == '__main__':

    rates = loadtxt('SNeIa_rates.txt')
    rates[:, 1:] = rates[:, 1:]  #*1.0e-4 ## put on the right scale
    rates = rates[:, :4]
    brates = u.gimme_rebinned_data(rates,
                                   verbose=False,
                                   splits=arange(0, 1.167, 0.167).tolist())
    data = deepcopy(brates)
    tt = 13.6 - array([ct.cosmotime(x) for x in data[:, 0]])
    data[:, 0] = tt
    data = data[argsort(data[:, 0])]

    import time
    import multiprocessing as mpc
    ncore = mpc.cpu_count()
    ndim, nwalkers, nsteps = 5, 1000, 2000
    step_size = 1.0
    ## p0 = (0.05, 3.5, 2.5, 2.5, 0.01)
    ## p0 = (0.06, -100., 50, 20, -2.5)
    p0 = (-2.81, -1200, 50, 200, -2.5)
Пример #3
0
def plot_one(rates, plotname, *p, frac=0.05, age=13.6):
    brates = u.gimme_rebinned_data(rates,
                                   splits=arange(0, 1.125, 0.125).tolist())
    scale_k = quad(imf.salpeter, 3, 8)[0] / quad(imf.salpeter1, 0.1, 125)[0]
    scale = scale_k * 0.7**2. * 1e4  ## factors of h...
    dt = 0.05
    tt = arange(dt, age, dt)
    lbt = age - tt
    zz = [ct.cosmoz(x, ho=70) for x in lbt]

    par_model = [0.0134, 2.55, 3.3, 6.1]

    sfh = rz.csfh_time(tt, *par_model)
    dtd = rz.dtdfunc(tt, *p)
    pwrl = (-1.0, 1.0)
    dud = rz.powerdtd(tt, *pwrl)

    tmp = convolve(
        sfh, dtd,
        'full') * dt * frac * scale  ## now convolved result in forward time
    rate_fn = tmp[:len(dtd)]

    jdud = convolve(sfh, dud, 'full') * dt * scale * 0.065
    jdud = jdud[:len(dtd)]
    clf()
    ax = subplot(111)
    ax2 = ax.twinx()
    ax2.plot(zz, sfh, 'r-', label='CSFH')
    ax.plot(zz, rate_fn, 'k-', label='Fit', zorder=3)
    ax.plot(zz, jdud, 'k:', label=r'$t^{%.1f}$' % (pwrl[0]))

    ax.errorbar(rates[:, 0],
                rates[:, 1],
                yerr=[rates[:, 3], rates[:, 2]],
                fmt='o',
                color='0.6',
                alpha=0.4)
    ax.errorbar(brates[:, 0],
                brates[:, 1],
                yerr=[brates[:, 3], brates[:, 2]],
                xerr=[brates[:, 5], brates[:, 4]],
                fmt='o',
                color='0.0',
                zorder=10)

    pwrl = (-1.0, 1.0)
    ax.set_xlim(0, 2.6)
    ax.set_ylim(0, 1.8)
    ax2.set_ylim(0, 0.16)

    ax3 = axes([0.65, 0.62, 0.23, 0.2])
    ## ax3 = axes([0.55, 0.6, 0.33, 0.25])
    ax3.plot(tt, log10(dtd), 'b-',
             label='Fit')  #label='Norm = %1.1f' %(simps(dtd,x=time)))
    ax3.plot(tt,
             log10(rz.powerdtd(tt, *pwrl)),
             'b:',
             label=r'$t^{%.1f}$' % (pwrl[0]))
    ax3.set_ylabel('$\log(\Phi)$')
    ax3.set_xlabel('Delay Time (Gyr)')
    ax3.set_xlim(0, 12)
    ax3.set_ylim(-3, 0.5)
    ##ax3.set_ylim(0,1)
    ## ax3.legend(loc=1,ncol=1,frameon=False, fontsize=8)
    ax.set_xlabel('Redshift')
    ax.set_ylabel(r'$10^{-4}$ SNe Ia per year per Mpc$^3$')
    ax2.set_ylabel(r'M$_{\odot}$ per year per Mpc$^3$')
    ## ax.set_title(r' $k=%.4f$ M$_{\odot}^{-1}$, $f=%2.1f\%%$' %(scale_k,frac*100))
    ax.set_title(r'$k=%.4f\,M_{\odot}^{-1},\,\,\varepsilon=%2.1f\%%$' %
                 (scale_k, frac * 100))
    ax.legend(loc=2, frameon=False)
    ax2.legend(loc=4, frameon=False)

    savefig(plotname)
    return ()
Пример #4
0
    lower = percentile(ysample, 2.5, axis=0)
    upper = percentile(ysample, 97.5, axis=0)
    ax2.fill_between(tta, log10(upper), log10(lower), color='green', alpha=0.2)

    pwrl = (-1., 1.)
    ax2.plot(tt,
             log10(rz.powerdtd(tt, *pwrl)),
             'b:',
             label=r'$t^{%.1f}$' % (pwrl[0]))

    frac = 0.065

    rates = loadtxt('SNeIa_rates.txt')
    rates[:, 1:] = rates[:, 1:]  #*1.0e-4 ## put on the right scale
    rates = rates[:, :4]
    brates = u.gimme_rebinned_data(rates,
                                   splits=arange(0, 1.125, 0.125).tolist())
    scale_k = quad(imf.salpeter, 3, 8)[0] / quad(imf.salpeter1, 0.1, 125)[0]
    scale = scale_k * 0.7**2. * 1e4  ## factors of h...
    lbt = age - tta
    zz = [ct.cosmoz(x, ho=70) for x in lbt]

    ax.errorbar(rates[:, 0],
                rates[:, 1],
                yerr=[rates[:, 3], rates[:, 2]],
                fmt='o',
                color='0.6',
                alpha=0.4)
    ax.errorbar(brates[:, 0],
                brates[:, 1],
                yerr=[brates[:, 3], brates[:, 2]],
                xerr=[brates[:, 5], brates[:, 4]],
Пример #5
0
def plot_one(rates, plotname, *p, frac=0.05, age=13.6):
    brates = u.gimme_rebinned_data(rates,
                                   splits=arange(0, 1.125, 0.125).tolist())
    scale_k = quad(imf.salpeter, 3, 8)[0] / quad(imf.salpeter1, 0.1, 125)[0]
    scale = scale_k * 0.7**2. * 1e4  ## factors of h...
    dt = 0.05
    tt = arange(dt, age, dt)  ## forward time
    lbt = age - tt
    zz = [ct.cosmoz(x) for x in lbt]

    par_model = [0.0134, 2.55, 3.3, 6.1]
    sfh = rz.csfh_time(tt, *par_model)
    dtd = rz.dtdfunc(tt, *p)
    pwrl = (-1.0, 1.0)
    dud = rz.powerdtd(tt, *pwrl)

    tmp = convolve(
        sfh, dtd,
        'full') * dt * frac * scale  ## now convolved result in forward time
    rate_fn = tmp[:len(dtd)]

    jdud = convolve(sfh, dud, 'full') * dt * scale * 0.065
    jdud = jdud[:len(dtd)]
    clf()
    ax = subplot(111)
    ax2 = ax.twinx()
    ax2.plot(zz, sfh, 'r-')
    ax.plot(zz, rate_fn, 'k-')
    ax.plot(zz, jdud, 'k:')

    ax.errorbar(rates[:, 0],
                rates[:, 1],
                yerr=[rates[:, 3], rates[:, 2]],
                fmt='o',
                color='0.6')
    ax.errorbar(brates[:, 0],
                brates[:, 1],
                yerr=[brates[:, 3], brates[:, 2]],
                xerr=[brates[:, 5], brates[:, 4]],
                fmt='o',
                color='0.0',
                zorder=10)

    ax.set_xlim(0, 2.5)
    ax.set_ylim(0, 1.8)
    ax.set_xlabel('Redshift')
    ax.set_ylabel(r'SN Ia Rate')
    ax.set_ylabel(r'$10^{-4}$ SNe Ia per year per Mpc$^3$')
    ax2.set_ylabel(r'SF Rate')

    ax3 = axes([0.65, 0.6, 0.23, 0.2])
    ax3.plot(tt, dtd, 'b-',
             label='Fit')  #label='Norm = %1.1f' %(simps(dtd,x=time)))
    ax3.plot(tt, dud, 'b:', label=r'$t^{%.1f}$' % (pwrl[0]))

    ax3.set_ylabel('$\Phi$')
    ax3.set_xlabel('Delay Time (Gyr)')
    ax3.set_xlim(0, 12)
    ax3.set_ylim(0, 1.3)
    ax3.legend(frameon=False)
    savefig(plotname)
    return ()