def _compute_PF2P(self,R):
        """
        Compute and return the second order convolution term :math:`\int (2\pi)^{-3}d\vec p F_2(\vec p,\vec k-\vec p)P(\vec p)P(\vec k-\vec p)` where :math:`F_2` is the second order perturbation theory density kernel and :math:`P(\vec k)` are (windowed) power spectra. This is computed using FASTPT.

        Arguments:
            R (float): Smoothing scale in :math:\mathrm{Mpc}/h` units.

        Returns:
            np.ndarray: Array of values of the convolution integral.
        """

        # Prepare FASTPT
        if not hasattr(self,'fastpt'):
            min_k = np.max([np.min(self.kh_vector),1e-4]) # setting minimum to avoid zero errors
            max_k = np.min([np.max(self.kh_vector),1e2])
            self.kh_interp = np.logspace(np.log10(min_k)-1,np.log10(max_k)+1,int(1e4))
            # Compute the one-loop spectrum using FAST-PT
            self.fastpt = FASTPT.FASTPT(self.kh_interp,to_do=['dd_bias'],n_pad=len(self.kh_interp)*3);

        # Now compute the smoothing function
        Wk = 3.*(np.sin(self.kh_interp*R)-self.kh_interp*R*np.cos(self.kh_interp*R))/(self.kh_interp*R)**3.

        # Compute the FASPT spectrum and interpolate to output grid
        out=self.fastpt.one_loop_dd_bias((self.cosmology.compute_linear_power(self.kh_interp,self.kh_min)*Wk).copy(),C_window=0.65,P_window=[0.25,0.25])
        PF2P_power = out[2]/2.
        PF2P_int = InterpolatedUnivariateSpline(self.kh_interp,PF2P_power*Wk)

        return PF2P_int(self.kh_vector)
Example #2
0
    def _one_loop_only_power_interpolater(self,linear_spectrum):
        """
        Compute the one-loop SPT power interpolator, using the FAST-PT module. This is computed from an input linear power spectrum.

        Note that the FAST-PT output contains large oscillations at high-k. To alleviate this, we perform smoothing interpolation above some k.

        Args:
            linear_spectrum (function): Function taking input wavenumber in h/Mpc units and returning a linear power spectrum.

        Returns:
            scipy.interp1d: An interpolator for the SPT power given an input k (in :math:`h/\mathrm{Mpc}` units).

        """
        if self.verb: print("Computing one-loop power spectrum")
        # Define some k grid for interpolation (with edges well separated from k limits)
        min_k = np.max([np.min(self.kh_vector),1e-4]) # setting minimum to avoid zero errors
        max_k = np.max(self.kh_vector)
        kh_interp = np.logspace(np.log10(min_k)-0.5,np.log10(max_k)+0.5,self.OneLoop_N_k)

        # Compute the one-loop spectrum using FAST-PT
        fastpt = FASTPT.FASTPT(kh_interp,to_do=['one_loop_dd'],n_pad=len(kh_interp)*3,
                               verbose=0);
        initial_power=fastpt.one_loop_dd(linear_spectrum(kh_interp).copy(),C_window=0.65,P_window=[0.25,0.25])[0]

         # Now convolve k if necessary
        filt = kh_interp>self.OneLoop_k_cut
        if np.sum(filt)==0:
            combined_power = initial_power
            combined_k = kh_interp
        else:
            convolved_k = np.convolve(kh_interp[filt],np.ones(self.OneLoop_N_interpolate,)/self.OneLoop_N_interpolate,mode='valid')
            convolved_power = np.convolve(initial_power[filt],np.ones(self.OneLoop_N_interpolate,)/self.OneLoop_N_interpolate,mode='valid')

            # Concatenate to get an output
            combined_power = np.concatenate([initial_power[kh_interp<min(convolved_k)],convolved_power])
            combined_k = np.concatenate([kh_interp[kh_interp<min(convolved_k)],convolved_k])

        # Zero any power values with kh < kh_min
        combined_power[combined_k<self.kh_min] = 0.

        # Create and return an interpolator
        return interp1d(combined_k,combined_power)
Example #3
0
    def __init__(self,
                 with_NC=False,
                 with_IA=False,
                 with_dd=True,
                 log10k_min=-4,
                 log10k_max=2,
                 nk_per_decade=20,
                 pad_factor=1,
                 low_extrap=-5,
                 high_extrap=3,
                 P_window=None,
                 C_window=.75):
        assert HAVE_FASTPT, ("You must have the `FAST-PT` python package "
                             "installed to use CCL to get PT observables! "
                             "You can install it with pip install fast-pt.")

        self.with_dd = with_dd
        self.with_NC = with_NC
        self.with_IA = with_IA
        self.P_window = P_window
        self.C_window = C_window

        to_do = ['one_loop_dd']
        if self.with_NC:
            to_do.append('dd_bias')
        if self.with_IA:
            to_do.append('IA')

        nk_total = int((log10k_max - log10k_min) * nk_per_decade)
        self.ks = np.logspace(log10k_min, log10k_max, nk_total)
        n_pad = int(pad_factor * len(self.ks))

        self.pt = fpt.FASTPT(self.ks,
                             to_do=to_do,
                             low_extrap=low_extrap,
                             high_extrap=high_extrap,
                             n_pad=n_pad)
        self.one_loop_dd = None
        self.dd_bias = None
        self.ia_ta = None
        self.ia_tt = None
        self.ia_mix = None
Example #4
0
    def __init__(self,
                 with_NC=False,
                 with_IA=False,
                 with_dd=True,
                 log10k_min=-4,
                 log10k_max=2,
                 nk_per_decade=20,
                 pad_factor=1,
                 low_extrap=-5,
                 high_extrap=3,
                 P_window=None,
                 C_window=.75):
        """ This class implements a set of methods that can be
        used to compute the various components needed to estimate
        perturbation theory correlations. These calculations are
        currently based on FAST-PT
        (https://github.com/JoeMcEwen/FAST-PT).

        Args:
            with_NC (bool): set to True if you'll want to use
                this calculator to compute correlations involving
                number counts.
            with_IA(bool): set to True if you'll want to use
                this calculator to compute correlations involving
                intrinsic alignments.
            with_dd(bool): set to True if you'll want to use
                this calculator to compute the one-loop matter power
                spectrum.
            log10k_min (float): decimal logarithm of the minimum
                Fourier scale (in Mpc^-1) for which you want to
                calculate perturbation theory quantities.
            log10k_max (float): decimal logarithm of the maximum
                Fourier scale (in Mpc^-1) for which you want to
                calculate perturbation theory quantities.
            pad_factor (float): fraction of the log(k) interval
                you want to add as padding for FFTLog calculations
                within FAST-PT.
            low_extrap (float): decimal logaritm of the minimum
                Fourier scale (in Mpc^-1) for which FAST-PT will
                extrapolate.
            high_extrap (float): decimal logaritm of the maximum
                Fourier scale (in Mpc^-1) for which FAST-PT will
                extrapolate.
            P_window (array_like or None): 2-element array describing
                the tapering window used by FAST-PT. See FAST-PT
                documentation for more details.
            C_window (float): `C_window` parameter used by FAST-PT
                to smooth the edges and avoid ringing. See FAST-PT
                documentation for more details.
        """
        assert HAVE_FASTPT, ("You must have the `FASTPT` python package "
                             "installed to use CCL to get PT observables!")

        self.with_dd = with_dd
        self.with_NC = with_NC
        self.with_IA = with_IA
        self.P_window = P_window
        self.C_window = C_window

        to_do = ['one_loop_dd']
        if self.with_NC:
            to_do.append('dd_bias')
        if self.with_IA:
            to_do.append('IA')

        nk_total = int((log10k_max - log10k_min) * nk_per_decade)
        self.ks = np.logspace(log10k_min, log10k_max, nk_total)
        n_pad = int(pad_factor * len(self.ks))

        self.pt = fpt.FASTPT(self.ks,
                             to_do=to_do,
                             low_extrap=low_extrap,
                             high_extrap=high_extrap,
                             n_pad=n_pad)
        self.one_loop_dd = None
        self.dd_bias = None
        self.ia_ta = None
        self.ia_tt = None
        self.ia_mix = None
Example #5
0
lkmin = -4
lkmax = 2
n_per_decade = 20
z_s = np.array([0., 1.])
a_s = 1. / (1 + z_s)
ks = np.logspace(lkmin, lkmax, (lkmax - lkmin) * n_per_decade)
pk = ccl.linear_matter_power(cosmo, ks, 1.)
gf = ccl.growth_factor(cosmo, a_s)
g4 = gf**4
pklin = np.array([ccl.linear_matter_power(cosmo, ks, a) for a in a_s])

C_window = .75
P_window = None
n_pad = int(0.5 * len(ks))
to_do = ['one_loop_dd', 'dd_bias', 'IA']
pt_ob = fpt.FASTPT(ks, to_do=to_do, low_extrap=-5, high_extrap=3, n_pad=n_pad)
oloop_dd = pt_ob.one_loop_dd(pk, P_window=P_window, C_window=C_window)
Pd1d1 = pklin + g4[:, None] * oloop_dd[0][None, :]
dd_bias = pt_ob.one_loop_dd_bias(pk, P_window=P_window, C_window=C_window)

ia_ta = pt_ob.IA_ta(pk, P_window=P_window, C_window=C_window)
ia_tt = pt_ob.IA_tt(pk, P_window=P_window, C_window=C_window)
ia_mix = pt_ob.IA_mix(pk, P_window=P_window, C_window=C_window)

g4 = g4[:, None]
Pd1d2 = g4 * dd_bias[2][None, :]
Pd2d2 = g4 * dd_bias[3][None, :]
Pd1s2 = g4 * dd_bias[4][None, :]
Pd2s2 = g4 * dd_bias[5][None, :]
Ps2s2 = g4 * dd_bias[6][None, :]
a00e = g4 * ia_ta[0][None, :]