Пример #1
0
def modified_power_spectrum(b_1,
                            f_nl,
                            cosmo,
                            redshift=0.,
                            tracer_p=1.,
                            nbar=None,
                            contrast=None):
    r"""Return the tracer power spectrum modified by primordial
    non-Gaussianity.

    Parameters
    ----------
    b_1 : float
        Scale-independent linear bias at input redshift.
    f_nl : float
        Local primordial non-Gaussianity.
    cosmo : :class:`nbodykit.cosmology.cosmology.Cosmology`
        Cosmological model.
    redshift : float, optional
        Redshift at which quantities are evaluated (default is 0.).
    tracer_p : float, optional
        Tracer-dependent parameter :math:`p` (default is 1.).
    nbar : float or None, optional
        If not `None` (default), add ``1/nbar`` as shot noise to the
        resulting power spectrum.
    contrast : float or None, optional
        If not `None` (default), add additional ``1/(contrast*nbar)``
        as shot noise to the resulting power spectrum.

    Returns
    -------
    callable
        Tracer power spectrum modified by primordial non-Gaussianity as a
        function of wavenumber (in :math:`h`/Mpc).

    """
    bias = scale_dependent_bias(b_1,
                                f_nl,
                                cosmo,
                                redshift=redshift,
                                tracer_p=tracer_p)

    power_spectrum = cosmology.LinearPower(cosmo, redshift=redshift)

    alpha = 0. if contrast is None else 1 / contrast
    shot_noise = 0. if nbar is None else (1 + alpha) / nbar

    return lambda k: bias(k)**2 * power_spectrum(k) + shot_noise
Пример #2
0
    def __init__(self,
                 h=0.67556,
                 T0_cmb=2.7255,
                 Omega0_b=0.0482754208891869,
                 Omega0_cdm=0.26377065934278865,
                 N_ur=None,
                 m_ncdm=[0.06],
                 P_k_max=10.0,
                 P_z_max=100.0,
                 sigma8=0.8225,
                 gauge='synchronous',
                 n_s=0.9667,
                 nonlinear=False):

        # input parameters
        kw_cosmo = locals()
        kw_cosmo.pop('self')
        for kw, val in kw_cosmo.items():
            print(f'{kw:10s}: {val}')

        sigma8 = kw_cosmo.pop('sigma8')
        cosmo = cosmology.Cosmology(**kw_cosmo).match(sigma8=sigma8)

        # --- cosmology calculators
        redshift = 0.0
        delta_crit = 1.686  # critical overdensity for collapse from Press-Schechter
        DH = (
            cosmo.H0 / cosmo.C
        )  # in units of h/Mpc, eq. 4 https://arxiv.org/pdf/astro-ph/9905116.pdf
        Omega0_m = cosmo.Omega0_m

        k_ = np.logspace(-10, 10, 10000)
        Plin_ = cosmology.LinearPower(cosmo, redshift,
                                      transfer='CLASS')  # P(k) in (Mpc/h)^3
        self.Plin = IUS(k_, Plin_(k_), ext=1)
        Tlin_ = cosmology.transfers.CLASS(
            cosmo, redshift)  # T(k), normalized to one at k=0
        tk_ = Tlin_(k_)
        is_good = np.isfinite(tk_)
        self.Tlin = IUS(k_[is_good], tk_[is_good], ext=1)
        self.Dlin = cosmo.scale_independent_growth_factor  # D(z), normalized to one at z=0
        self.f = cosmo.scale_independent_growth_rate  # dlnD/dlna
        self.Dc = cosmo.comoving_distance
        self.h = cosmo.efunc
        self.inv_pi = 2.0 / np.pi

        # alpha_fnl: equation 2 of Mueller et al 2017
        self.alpha_fnl = 3.0 * delta_crit * Omega0_m * (DH**2)
Пример #3
0
def generate_data(x):
    redshift = 0.0
    r_vals = np.linspace(50, 140, 10)
    extra_input = {'redshift': redshift, 'r_vals': r_vals}

    n_data = x.shape[1]
    y = np.empty((len(r_vals), n_data))
    for i in range(n_data):
        print(i)
        om, s8, ob = x[:, i]
        ocdm = om - ob
        m_ncdm = []  #no massive neutrinos
        cosmo = cosmology.Cosmology(Omega0_b=ob,
                                    Omega0_cdm=ocdm,
                                    m_ncdm=m_ncdm)
        cosmo = cosmo.match(sigma8=s8)
        plin = cosmology.LinearPower(cosmo, redshift, transfer='EisensteinHu')
        cf = cosmology.correlation.CorrelationFunction(plin)
        y[:, i] = cf(r_vals)
    return y, extra_input
Пример #4
0
print(r"Nmesh = {:.0f}, a_sqrt = {:.0f}, BoxSize = {:.0f}".format(
    grid_mesh, a_sqrt, Boxsize))

mesh_6411 = cata_6411.to_mesh(Nmesh=grid_mesh,
                              BoxSize=Boxsize,
                              resampler='cic')
mesh_6411 = mesh_6411.compute()
print(mesh_6411.shape)

# xi_6411 = FFTCorr(mesh_6411, mode='1d')

redshift = cata_6411.attrs['Redshift']
cosmo = cosmology.Cosmology(
    h=cata_6411.attrs['HubbleParam'],
    P_k_max=200).match(Omega0_m=cata_6411.attrs['Omega0'])
pk_cosmo = cosmology.LinearPower(cosmo, redshift, transfer='EisensteinHu')


def VectorProjection(vector, direction):
    r"""
    Vector components of given vectors in a given direction.

    .. math::

        \mathbf{v}_\mathbf{d} &= (\mathbf{v} \cdot \hat{\mathbf{d}}) \hat{\mathbf{d}} \\
        \hat{\mathbf{d}} &= \frac{\mathbf{d}}{\|\mathbf{d}\|}

    Parameters
    ----------
    vector : array_like, (..., D)
        array of vectors to be projected