Example #1
0
def test_tau_instant():
    """Check the optical depth we get using the WMAP z_reion. 
    """
    dz = 0.1
    z = numpy.arange(80., 0. - 1.5 * dz, -1. * dz)

    # Can't match WMAP7 optical depths exactly. Need to look into new
    # treatment in CAMB as mentioned in the WMAP7 paper (see
    # parameters.py).
    cosmos = [
        cparam.WMAP7_BAO_H0_mean(flat=True),
        cparam.WMAP7_ML(flat=True),
        cparam.WMAP5_BAO_SN_mean(flat=True),
        cparam.WMAP5_ML(flat=True),
        cparam.WMAP5_mean(flat=True)
    ]

    # The WMAP5 numbers apparently assume He is neutral, while WMAP7
    # includes simultaneous singly ionized He plus Helium (double)
    # reionization at z=3.5.
    x_ionHe_list = [1.0, 1.0, 0, 0, 0]
    z_rHe_list = [3.5, 3.5, None, None, None]  #[3.5, None, None, None]
    for cosmo in cosmos:
        # Fully ionized H
        x_ionH = 1.0

        # He ionization with H?
        x_ionHe = x_ionHe_list.pop(0)

        # Redshift for Helium double reionization?
        z_rHe = z_rHe_list.pop(0)

        zr = cosmo['z_reion']
        tau_zr = cosmo['tau']
        tau_calc = cr.optical_depth_instant(zr,
                                            x_ionH=x_ionH,
                                            x_ionHe=x_ionHe,
                                            z_rHe=z_rHe,
                                            verbose=1,
                                            **cosmo)

        print "z_r = %f, testing tau:" % zr,
        print tu.fractional_diff_string(tau_zr, tau_calc, 3)

        ntest.assert_approx_equal(tau_calc,
                                  tau_zr,
                                  significant=2,
                                  err_msg="Optical depth doesn't match WMAP")
Example #2
0
def test_t_0():
    """Check the age of the universe we get using WMAP cosmologies.

    We only find agreement to 3 sig figs, not the 4 specified in the
    WMAP paper.

    The results of test_age.py show that we're doing the integral
    correctly, so I think the problem is that we're not taking into
    account some of the higher-order effects included in the WMAP
    numbers.

    """

    dz = 0.1
    z = numpy.arange(80., 0. - 1.5 * dz, -1. * dz)

    flat = True
    cosmos = [
        cparam.WMAP7_BAO_H0_mean(flat=True),
        cparam.WMAP7_ML(flat=True),
        cparam.WMAP5_BAO_SN_mean(flat=True),
        cparam.WMAP5_ML(flat=True),
        cparam.WMAP5_mean(flat=True)
    ]

    for cosmo in cosmos:
        age = cd.age(0.0, **cosmo)
        age_flat = cd.age_flat(0.0, **cosmo)
        gyr = 1e9 * cc.yr_s
        age /= gyr
        age_flat /= gyr

        print "integrated age: ",
        print tu.fractional_diff_string(age, cosmo['t_0'], 4)
        ntest.assert_approx_equal(age,
                                  cosmo['t_0'],
                                  significant=3,
                                  err_msg="Integrated age doesn't match WMAP")

        print "analytical age: ",
        print tu.fractional_diff_string(age_flat, cosmo['t_0'], 4)
        ntest.assert_approx_equal(age_flat,
                                  cosmo['t_0'],
                                  significant=3,
                                  err_msg="Analytical age doesn't match WMAP")
Example #3
0
def test_tau_BKP():
    """Reionization consistency check with BK&P 2009MNRAS.397..971B

    Bagla J.~S., Kulkarni G., Padmanabhan T., 2009 (2009MNRAS.397..971B).
    
    Take their cannonical set of cosmological parameters and ionization
    coefficients and make sure I get the same optical depth value.

    The first figure demonstrates the calculation of the ionization
    fraction and the optical depth (not shown in the paper).

    The second figure shows dependence of the f_* f_esc,gamma values on
    tau (actually calculated the other way around, f_* f_esc,gamma ->
    tau). The plotted point (x) marks the value from the paper. The
    agreement between the calculated optical depth and the WMAP tau value
    is printed in the text output.
    
    """
    N_gamma = 6804.

    # f_* f_esc N_gamma
    f_ion = numpy.transpose(numpy.atleast_2d(numpy.arange(10., 200., 10.)))
    
    alpha_B = 1e-13 # cm^3 s^-1
    m_min = 1e8 # M_sun

    x_ionHe = 2.0

    dz = 0.1
    z = numpy.arange(20., 6. - 1.5 * dz, -1. * dz)
    #z = numpy.arange(6., 20. + 1.5 * dz, dz)

    cosmos = [cparam.WMAP5_ML(flat=True),
              cparam.WMAP5_mean(flat=True)]    

    pylab.figure(figsize=(8,8))
    colors=['r', 'k']
    names = ["WMAP5 ML", "WMAP5 mean"]
    i = -1
    for cosmo in cosmos:
        i += 1

        print("\n%s" % (names[i]))
        # calculate ionized fraction, including recombinations
        x_rec, w_rec, t = cr.integrate_ion_recomb_collapse(z, f_ion,
                                                           m_min,
                                                           passed_min_mass=True,
                                                           alpha_B=alpha_B,
                                                           **cosmo)
        # calculate the optical depth in this scenario
        tau_z0 = cr.optical_depth_instant(z[-1],
                                          x_ionH=1.0,
                                          x_ionHe=2.0,
                                          **cosmo)

        tau_later = cr.integrate_optical_depth(x_rec, x_ionHe * x_rec, 
                                               z, **cosmo)
        tau_0 = tau_later[:, -1] + tau_z0

        tau = tau_later

        print("tau(WMAP) = %.3f" % (cosmo['tau']))
        for j in range(len(f_ion.flat)):
            if round(f_ion[j],1) != 50.0:
                continue
            print("with f_* f_esc_gamma N_gamma = %.1f:" % (f_ion[j]))
            pylab.plot(z, x_rec[j], ls='-', color=colors[i])
            pylab.plot(z, w_rec[j], ls=':', color=colors[i])
            #pylab.plot(z, 10. * tau[j], ls='--', color=colors[i])
            pylab.plot(z, 10. * (tau_0[j] - tau[j]), ls='--', color=colors[i])
            pylab.axhline(y=10. * tau_0[j], ls='--', color=colors[i])
            print("tau(z=0)  = %.4f" % (tau_0[j]))
            print("fractional diff. = %.3g" % ((tau_0[j] - cosmo['tau']) / 
                                                cosmo['tau']))
            if i==1:
                # Make sure we recover the WMAP value.
                ntest.assert_approx_equal(tau_0[j], cosmo['tau'], 2)

    pylab.ylim(0,1.01)
    pylab.xlabel("redshift z")
    pylab.ylabel(r"ionized fraction or optical depth $\tau \times 10$")

    pylab.figure(figsize=(8,8))
    pylab.plot(tau_0, f_ion / N_gamma, '-', color='k')
    pylab.plot([cosmo['tau']], [50.0 / N_gamma], 'x', color='b')
    pylab.xlim(0.06, 0.12)
    pylab.ylim(0., 0.022)
    pylab.xlabel(r'$\tau$')
    pylab.ylabel(r'$f_* f_{esc,\gamma}$')