Esempio n. 1
0
def check_Bessel_spectrum(l, k=None, r0=100):
    # Initialise survey and spectra
    cosmo = cosmicpy.cosmology()
    surv = cosmicpy.survey(nzparams={
        'type': 'gaussian',
        'cosmology': cosmo,
        'r0': r0
    },
                           zmax=5,
                           fsky=1.0)
    spectra = cosmicpy.spectra(cosmo, surv)
    survey_volume = pi**(3.0 / 2.0) * r0**3
    if k is None:
        k = np.logspace(log(0.0001) / log(10),
                        log(0.25) / log(10),
                        512,
                        endpoint=False)

    kw, w = spectra.W(l, k, evol=False)
    kw = kw.squeeze()
    w = w.squeeze()
    w_exact = np.zeros_like(w)
    for k1 in range(len(k)):
        w_exact[k1, :] = gaussian_bessel_window(l, r0, k[k1],
                                                kw[k1, :]) / survey_volume

    pk = cosmo.pk_lin(kw)
    integrand = np.square(kw * w_exact) * pk
    res = (2.0 / pi)**2 * trapz(integrand, x=kw)

    cl = spectra.cl_sfb(l, k)

    return k, cl, res
Esempio n. 2
0
def import_cosmology(filename, structure_name="fid"):
    r""" Loads an icosmo cosmology from a fiducial structure stored in an
    idl save file into a cosmicpy cosmology.

    Parameters
    ----------
    filename : str
        Name of the idl save from which to load the cosmology.
    structure_name : str, optional
        Name of the icosmo fiducial structure stored in the save file.

    Returns
    -------
    cosmo : cosmology
        cosmicpy cosmology corresponding to the icosmo input.
    """
    icosmo_file = readsav(filename)
    icosmo = icosmo_file.get(structure_name)

    h = icosmo['cosmo'][0]['h'][0]
    Omega_m = icosmo['cosmo'][0]['omega_m'][0]
    Omega_de = icosmo['cosmo'][0]['omega_l'][0]
    Omega_b = icosmo['cosmo'][0]['omega_b'][0]
    w0 = icosmo['cosmo'][0]['w0'][0]
    wa = icosmo['cosmo'][0]['wa'][0]
    tau = icosmo['cosmo'][0]['tau'][0]
    n = icosmo['cosmo'][0]['n'][0]
    sigma8 = icosmo['cosmo'][0]['sigma8'][0]

    cosmo = cosmicpy.cosmology(h=h, Omega_m=Omega_m, Omega_de=Omega_de,
                              Omega_b=Omega_b, w0=w0, wa=wa, tau=tau,
                              n=n, sigma8=sigma8)
    return cosmo
Esempio n. 3
0
def check_Bessel_spectrum(l, k=None, r0=100):
      # Initialise survey and spectra
    cosmo = cosmicpy.cosmology()
    surv = cosmicpy.survey(nzparams={'type': 'gaussian',
                                    'cosmology': cosmo,
                                    'r0': r0},
                          zmax=5,
                          fsky=1.0)
    spectra = cosmicpy.spectra(cosmo, surv)
    survey_volume = pi**(3.0 / 2.0) * r0**3
    if k is None:
        k = np.logspace(log(0.0001) / log(10), log(0.25) / log(10), 512,
                        endpoint=False)

    kw, w = spectra.W(l, k, evol=False)
    kw = kw.squeeze()
    w = w.squeeze()
    w_exact = np.zeros_like(w)
    for k1 in range(len(k)):
        w_exact[k1, :] = gaussian_bessel_window(l,r0, k[k1], kw[k1,:])/ survey_volume

    pk = cosmo.pk_lin(kw)
    integrand = np.square(kw * w_exact) * pk
    res = (2.0 / pi)**2 * trapz(integrand, x=kw)

    cl = spectra.cl_sfb(l, k)

    return k, cl, res
Esempio n. 4
0
def check_Bessel_window(l, k=None, r0=100):
    r""" Checks the computation of the bessel window compared to the exact
    solution
    for Gaussian selection functions.

    Parameters
    ----------
    l : int
        Order of the multipole.
    r0 : real, optional
        Radius parameter for the survey Gaussian selection function in Mpc/h

    Returns
    -------
    (k, W, Wexact) : tuple of ndarrays
        Window compute the discrete spherical bessel transform and the exact
        window computed from theory
    """
    # Initialise survey and spectra
    cosmo = cosmicpy.cosmology()
    surv = cosmicpy.survey(nzparams={
        'type': 'gaussian',
        'cosmology': cosmo,
        'r0': r0
    },
                           zmax=0.5,
                           fsky=1.0)
    spectra = cosmicpy.spectra(cosmo, surv)
    survey_volume = pi**(3.0 / 2.0) * r0**3
    if k is None:
        k = np.logspace(log(0.001) / log(10),
                        log(0.20) / log(10),
                        512,
                        endpoint=False)
    W = spectra.W(l, k, k, evol=False, kmax=0.5)

    W = W.squeeze()
    Wexact = np.zeros_like(W)
    for k1 in range(len(k)):
        Wexact[k1, :] = (gaussian_bessel_window(l, r0, k[k1], k) /
                         survey_volume)
    print("Maximum absolute error vs maximum value: " +
          str(abs(W - Wexact).max()) + " " + str(Wexact.max()))
    return (k, W, Wexact)
Esempio n. 5
0
def check_Bessel_window(l, k=None, r0=100):
    r""" Checks the computation of the bessel window compared to the exact
    solution
    for Gaussian selection functions.

    Parameters
    ----------
    l : int
        Order of the multipole.
    r0 : real, optional
        Radius parameter for the survey Gaussian selection function in Mpc/h

    Returns
    -------
    (k, W, Wexact) : tuple of ndarrays
        Window compute the discrete spherical bessel transform and the exact
        window computed from theory
    """
    # Initialise survey and spectra
    cosmo = cosmicpy.cosmology()
    surv = cosmicpy.survey(nzparams={'type': 'gaussian',
                                    'cosmology': cosmo,
                                    'r0': r0},
                          zmax=0.5,
                          fsky=1.0)
    spectra = cosmicpy.spectra(cosmo, surv)
    survey_volume = pi**(3.0 / 2.0) * r0**3
    if k is None:
        k = np.logspace(log(0.001) / log(10), log(0.20) / log(10), 512,
                        endpoint=False)
    W = spectra.W(l, k, k, evol=False, kmax=0.5)

    W = W.squeeze()
    Wexact = np.zeros_like(W)
    for k1 in range(len(k)):
            Wexact[k1, :] = (gaussian_bessel_window(l, r0, k[k1], k) /
                             survey_volume)
    print("Maximum absolute error vs maximum value: " +
          str(abs(W - Wexact).max()) +
          " " +
          str(Wexact.max()))
    return (k, W, Wexact)
Esempio n. 6
0
def import_cosmology(filename, structure_name="fid"):
    r""" Loads an icosmo cosmology from a fiducial structure stored in an
    idl save file into a cosmicpy cosmology.

    Parameters
    ----------
    filename : str
        Name of the idl save from which to load the cosmology.
    structure_name : str, optional
        Name of the icosmo fiducial structure stored in the save file.

    Returns
    -------
    cosmo : cosmology
        cosmicpy cosmology corresponding to the icosmo input.
    """
    icosmo_file = readsav(filename)
    icosmo = icosmo_file.get(structure_name)

    h = icosmo['cosmo'][0]['h'][0]
    Omega_m = icosmo['cosmo'][0]['omega_m'][0]
    Omega_de = icosmo['cosmo'][0]['omega_l'][0]
    Omega_b = icosmo['cosmo'][0]['omega_b'][0]
    w0 = icosmo['cosmo'][0]['w0'][0]
    wa = icosmo['cosmo'][0]['wa'][0]
    tau = icosmo['cosmo'][0]['tau'][0]
    n = icosmo['cosmo'][0]['n'][0]
    sigma8 = icosmo['cosmo'][0]['sigma8'][0]

    cosmo = cosmicpy.cosmology(h=h,
                               Omega_m=Omega_m,
                               Omega_de=Omega_de,
                               Omega_b=Omega_b,
                               w0=w0,
                               wa=wa,
                               tau=tau,
                               n=n,
                               sigma8=sigma8)
    return cosmo
Esempio n. 7
0
def check_cosmology(filename, structure_name="cosmo"):
    r""" Loads an icosmo cosmology from an idl save file and compares the
    content of the cosmology structure with results from cosmicpy.

    Parameters
    ----------
    filename : str
        Name of the idl save from which to load the cosmology.
    structure_name : str, optional
        Name of the icosmo cosmology structure stored in the save file.
    """
    icosmo_file = readsav(filename)
    icosmo = icosmo_file.get(structure_name)

    # Reading cosmological parameters and creating corresponding
    # cosmicpy object
    h = icosmo['const'][0]['h'][0]
    Omega_m = icosmo['const'][0]['omega_m'][0]
    Omega_de = icosmo['const'][0]['omega_l'][0]
    Omega_b = icosmo['const'][0]['omega_b'][0]
    w0 = icosmo['const'][0]['w0'][0]
    wa = icosmo['const'][0]['wa'][0]
    tau = icosmo['const'][0]['tau'][0]
    n = icosmo['const'][0]['n'][0]
    sigma8 = icosmo['const'][0]['sigma8'][0]

    cosmo = cosmicpy.cosmology(h=h, Omega_m=Omega_m, Omega_de=Omega_de,
                      Omega_b=Omega_b, w0=w0, wa=wa, tau=tau,
                      n=n, sigma8=sigma8)
    print(cosmo)

    # Comparing derived quantities
    Omega_k = icosmo['const'][0]['omega_k'][0]
    r0 = icosmo['const'][0]['r0'][0] * h
    gamma = icosmo['const'][0]['gamma'][0]
    sh = icosmo['const'][0]['sh'][0] * h

    print("\nComparing derived constants :")
    print("parameter:        [icosmo] |       [cosmicpy] |"
          "            diff | relative error in percents ")
    _print_diff("Omega_k  ", Omega_k, cosmo.Omega_k)
    _print_diff("gamma    ", gamma, cosmo.gamma)
    _print_diff("sh       ", sh, cosmo.sh_r)

    # Comparing evolved quantities
    rh = icosmo['const'][0]['rh'][0] * h
    z = icosmo['evol'][0]['z'][0]
    a = icosmo['evol'][0]['a'][0]
    chi = icosmo['evol'][0]['chi'][0] * rh
    hc = icosmo['evol'][0]['hc'][0] / h
    Omega_m = icosmo['evol'][0]['omega_m_a'][0]
    Omega_de_a = icosmo['evol'][0]['omega_l_a'][0]
    dzdr = icosmo['evol'][0]['dzdr'][0] / h
    da = icosmo['evol'][0]['da'][0] * h

    print("\nComparing evolved quantities, maximum relative error:")
    print("Radial Comoving Distance  :  " +
          str(abs((chi[1:] - cosmo.a2chi(a[1:])) / chi[1:]).max()))
    print("Angular Diameter Distance :  " +
          str(abs((da[1:] - a[1:] * cosmo.f_k(a[1:])) / da[1:]).max()))
    print("Hubble constant           :  " +
          str(abs((hc - cosmo.H(a)) / hc).max()))
    print("Omega_m(a)                :  " +
           str(abs((Omega_m - cosmo.Omega_m_a(a)) / Omega_m).max()))
    print("Omega_de(a)               :  " +
           str(abs((Omega_de_a - cosmo.Omega_de_a(a)) / Omega_de_a).max()))
    print("dzdr                      :  " +
           str(abs((dzdr - cosmo.dzoverda(a) /
                    cosmo.dchioverda(a)) / dzdr).max()))

    # Comparing Power spectrum
    k = icosmo['pk'][0]['k'][0]
    zpk = icosmo['pk'][0]['z'][0]
    pk = icosmo['pk'][0]['pk'][0]
    pk_l = icosmo['pk'][0]['pk_l'][0]

    print("\nComparing linear power spectra")
    pk2 = cosmo.pk_lin(k, cosmicpy.z2a(zpk))
    plt.figure()
    plt.contourf(k, zpk, abs(pk2.T - pk_l) / pk_l, 250)
    plt.xlabel(r"Scale in Mpc/h")
    plt.ylabel(r"Redshift")
    plt.xscale('log')
    plt.colorbar()
    plt.title('Relative Error in linear power specrum computation')
    plt.show()
    print("Maximum relative error on linear power specrum : " +
          str((abs(pk2.T - pk_l) / pk_l).max()))
Esempio n. 8
0
def check_cosmology(filename, structure_name="cosmo"):
    r""" Loads an icosmo cosmology from an idl save file and compares the
    content of the cosmology structure with results from cosmicpy.

    Parameters
    ----------
    filename : str
        Name of the idl save from which to load the cosmology.
    structure_name : str, optional
        Name of the icosmo cosmology structure stored in the save file.
    """
    icosmo_file = readsav(filename)
    icosmo = icosmo_file.get(structure_name)

    # Reading cosmological parameters and creating corresponding
    # cosmicpy object
    h = icosmo['const'][0]['h'][0]
    Omega_m = icosmo['const'][0]['omega_m'][0]
    Omega_de = icosmo['const'][0]['omega_l'][0]
    Omega_b = icosmo['const'][0]['omega_b'][0]
    w0 = icosmo['const'][0]['w0'][0]
    wa = icosmo['const'][0]['wa'][0]
    tau = icosmo['const'][0]['tau'][0]
    n = icosmo['const'][0]['n'][0]
    sigma8 = icosmo['const'][0]['sigma8'][0]

    cosmo = cosmicpy.cosmology(h=h,
                               Omega_m=Omega_m,
                               Omega_de=Omega_de,
                               Omega_b=Omega_b,
                               w0=w0,
                               wa=wa,
                               tau=tau,
                               n=n,
                               sigma8=sigma8)
    print(cosmo)

    # Comparing derived quantities
    Omega_k = icosmo['const'][0]['omega_k'][0]
    r0 = icosmo['const'][0]['r0'][0] * h
    gamma = icosmo['const'][0]['gamma'][0]
    sh = icosmo['const'][0]['sh'][0] * h

    print("\nComparing derived constants :")
    print("parameter:        [icosmo] |       [cosmicpy] |"
          "            diff | relative error in percents ")
    _print_diff("Omega_k  ", Omega_k, cosmo.Omega_k)
    _print_diff("gamma    ", gamma, cosmo.gamma)
    _print_diff("sh       ", sh, cosmo.sh_r)

    # Comparing evolved quantities
    rh = icosmo['const'][0]['rh'][0] * h
    z = icosmo['evol'][0]['z'][0]
    a = icosmo['evol'][0]['a'][0]
    chi = icosmo['evol'][0]['chi'][0] * rh
    hc = icosmo['evol'][0]['hc'][0] / h
    Omega_m = icosmo['evol'][0]['omega_m_a'][0]
    Omega_de_a = icosmo['evol'][0]['omega_l_a'][0]
    dzdr = icosmo['evol'][0]['dzdr'][0] / h
    da = icosmo['evol'][0]['da'][0] * h

    print("\nComparing evolved quantities, maximum relative error:")
    print("Radial Comoving Distance  :  " +
          str(abs((chi[1:] - cosmo.a2chi(a[1:])) / chi[1:]).max()))
    print("Angular Diameter Distance :  " +
          str(abs((da[1:] - a[1:] * cosmo.f_k(a[1:])) / da[1:]).max()))
    print("Hubble constant           :  " +
          str(abs((hc - cosmo.H(a)) / hc).max()))
    print("Omega_m(a)                :  " +
          str(abs((Omega_m - cosmo.Omega_m_a(a)) / Omega_m).max()))
    print("Omega_de(a)               :  " +
          str(abs((Omega_de_a - cosmo.Omega_de_a(a)) / Omega_de_a).max()))
    print("dzdr                      :  " + str(
        abs((dzdr - cosmo.dzoverda(a) / cosmo.dchioverda(a)) / dzdr).max()))

    # Comparing Power spectrum
    k = icosmo['pk'][0]['k'][0]
    zpk = icosmo['pk'][0]['z'][0]
    pk = icosmo['pk'][0]['pk'][0]
    pk_l = icosmo['pk'][0]['pk_l'][0]

    print("\nComparing linear power spectra")
    pk2 = cosmo.pk_lin(k, cosmicpy.z2a(zpk))
    plt.figure()
    plt.contourf(k, zpk, abs(pk2.T - pk_l) / pk_l, 250)
    plt.xlabel(r"Scale in Mpc/h")
    plt.ylabel(r"Redshift")
    plt.xscale('log')
    plt.colorbar()
    plt.title('Relative Error in linear power specrum computation')
    plt.show()
    print("Maximum relative error on linear power specrum : " +
          str((abs(pk2.T - pk_l) / pk_l).max()))