Beispiel #1
0
    def make_xiell_fixedbias(self,
                             f,
                             bvec,
                             apar=1,
                             aperp=1,
                             ngauss=4,
                             kmin=1e-3,
                             kmax=0.8,
                             nk=100,
                             nmax=5):

        kv, p0k, p2k, p4k = self.make_pell_fixedbias(f,
                                                     bvec,
                                                     apar=apar,
                                                     aperp=aperp,
                                                     ngauss=ngauss,
                                                     kmin=kmin,
                                                     kmax=kmax,
                                                     nk=nk,
                                                     nmax=nmax)

        damping = np.exp(-(self.kint / 10)**2)
        p0int = loginterp(kv, p0k)(self.kint) * damping
        p2int = loginterp(kv, p2k)(self.kint) * damping
        p4int = loginterp(kv, p4k)(self.kint) * damping

        ss0, xi0 = self.sphr.sph(0, p0int)
        ss2, xi2 = self.sphr.sph(2, p2int)
        xi2 *= -1
        ss4, xi4 = self.sphr.sph(4, p0int)

        return (ss0, xi0), (ss2, xi2), (ss4, xi4)
    def compute_cumulants(self, b1, b2, bs, b3, alpha, alpha_v, alpha_s0, alpha_s2, s2fog):
        '''
        Calculate velocity moments and turn into cumulants.
        '''
        # Compute each moment
        
        self.pars = np.array([b1, b2, bs, b3, alpha, alpha_v, alpha_s0, alpha_s2, s2fog])
        
        self.kv   = self.pktable[:,0]
        self.pzel = self.pktable[:,-1]
        
        self.peft = self.pktable[:,1] + b1*self.pktable[:,2] + b1**2*self.pktable[:,3]\
        + b2*self.pktable[:,4] + b1*b2*self.pktable[:,5] + b2**2 * self.pktable[:,6]\
        + bs*self.pktable[:,7] + b1*bs*self.pktable[:,8] + b2*bs*self.pktable[:,9]\
        + bs**2*self.pktable[:,10] + b3*self.pktable[:,11] + b1*b3*self.pktable[:,12] + alpha* self.kv**2 * self.pzel
        
        _integrand = loginterp(self.kv, self.peft)(self.kint) #at some point turn into theory extrapolation
        _integrand = self.weight * _integrand + (1-self.weight) * ((1+b1)**2 * self.plin)
        
        qint, xi = self.sph_gsm.sph(0,_integrand*self.window)
        self.xieft = np.interp(self.rint, qint, xi)
                
        self.vkeft = self.vktable[:,1] + b1*self.vktable[:,2] + b1**2*self.vktable[:,3]\
        + b2*self.vktable[:,4] + b1*b2*self.vktable[:,5] \
        + bs*self.vktable[:,7] + b1*bs*self.vktable[:,8] + b3 * self.vktable[:,11]\
        + alpha_v * self.kv * self.pzel
        
        _integrand = loginterp(self.kv, self.vkeft)(self.kint)
        _integrand = self.weight * _integrand + (1-self.weight) * (-2 * (1+b1) * self.plin/self.kint)

        qint, xi = self.sph_gsm.sph(1,_integrand*self.window)
        self.veft = np.interp(self.rint, qint, xi)
        
        self.s0keft =  self.s0[:,1] + b1*self.s0[:,2] + b1**2*self.s0[:,3]\
                                                           + b2*self.s0[:,4] \
                                                           + bs*self.s0[:,7] \
                                                           + alpha_s0 * self.pzel
        
        self.s2keft =  self.s2[:,1] + b1*self.s2[:,2] + b1**2*self.s2[:,3]\
                                                           + b2*self.s2[:,4] \
                                                           + bs*self.s2[:,7] \
                                                           + alpha_s2 * self.pzel
        
        _integrand = loginterp(self.kv, self.s0keft)(self.kint)
        _integrand = self.weight * _integrand + (1-self.weight) * (-2./3 * self.plin/self.kint**2)

        qint, xi = self.sph_gsm.sph(0,_integrand * self.window)
        self.s0eft = np.interp(self.rint, qint, xi)

        _integrand = loginterp(self.kv, self.s2keft)(self.kint)
        _integrand = self.weight * _integrand + (1-self.weight) * (-4./3 * self.plin/self.kint**2)

        qint2, xi = self.sph_gsm.sph(2,_integrand * self.window); xi *=-1
        self.s2eft = np.interp(self.rint, qint2, xi)
                                                           
        self.s0eft += (self.Xddot + self.Xloopddot + 2*b1*self.X10ddot + 2*bs*self.Xs2ddot)[-1] + s2fog #add in 0-lag term
 def update_power_spectrum(self, k, p):
     # Updates the power spectrum and various q functions. Can continually compute for new cosmologies without reloading FFTW
     self.k = k
     self.p = p
     self.pint = loginterp(k, p)(
         self.kint) * np.exp(-(self.kint / self.cutoff)**2)
     self.setup_powerspectrum()
Beispiel #4
0
    def xi_l_n(self,
               l,
               n,
               _int=None,
               IR_cut='all',
               extrap=False,
               qmin=1e-3,
               qmax=1000,
               side='both'):
        '''
        Calculates the generalized correlation function xi_l_n, which is xi when l = n = 0
        
        If _int is None assume integrating the power spectrum.
        '''
        if _int is None:
            integrand = self.p * self.k**n
        else:
            integrand = _int * self.k**n

        if IR_cut is not 'all':
            if IR_cut == 'gt':
                integrand *= self.ir_greater
            elif IR_cut == 'lt':
                integrand *= self.ir_less

        qs, xint = self.sph.sph(l, integrand)

        if extrap:
            qrange = (qs > qmin) * (qs < qmax)
            return loginterp(qs[qrange], xint[qrange], side=side)(self.qv)
        else:
            return np.interp(self.qv, qs, xint)
    def __init__(self, *args, kmin = 3e-3, kmax=0.5, nk = 100, kswitch=1e-2, jn = 5, cutoff=20, **kw):
        '''
        Same keywords and arguments as the other two classes for now.
        '''
        # Setup ffts etc.
        VelocityMoments.__init__(self, *args, third_order=True, **kw)

        self.kmin, self.kmax, self.nk = kmin, kmax, nk
        self.kv = np.logspace(np.log10(kmin), np.log10(kmax), nk); self.nk = nk
        
        self.kint = np.logspace(-5,3,4000)
        self.plin = loginterp(self.k, self.p)(self.kint)
        self.sph_gsm  = SphericalBesselTransform(self.kint,L=3,fourier=True)
        self.rint = np.logspace(-3,5,4000)
        self.rint = self.rint[(self.rint>0.1)*(self.rint<600)] #actual range of integration
        
        self.window = tukey(4000)
        self.weight =  0.5 * (1 + np.tanh(3*np.log(self.kint/kswitch)))
        self.weight[self.weight < 1e-3] = 0
        
        self.pars = np.array([0,0,0,0, 0,0,0,0, 0])
        self.peft = None
        self.veft = None
        self.s0eft = None
        self.s2eft = None
        
        self.setup_velocity_moments()
Beispiel #6
0
    def __init__(self, *args, kmin=1e-2, kmax=0.5, nk=100, **kw):

        # Initialize the velocity class
        KEVelocityMoments.__init__(self, *args, **kw)

        self.nk, self.kmin, self.kmax = nk, kmin, kmax
        self.make_tables(kmin=kmin, kmax=kmax, nk=nk)
        self.kv = self.pktable[:, 0]
        self.plin = loginterp(self.k, self.p)(self.kv)

        # Now convert to EPT table
        self.convert_ptable()
        self.convert_vtable()
        self.convert_stable()
        if self.beyond_gauss:
            self.convert_gtable()
Beispiel #7
0
    def __init__(self, k, p, third_order = True, shear=True, one_loop=True,\
                 kIR = None, cutoff=10, jn=5, N = 2000, threads=1, extrap_min = -5, extrap_max = 3):

        self.N = N
        self.extrap_max = extrap_max
        self.extrap_min = extrap_min

        self.kIR = kIR
        self.cutoff = cutoff
        self.kint = np.logspace(extrap_min, extrap_max, self.N)
        self.qint = np.logspace(-extrap_max, -extrap_min, self.N)

        self.third_order = third_order
        self.shear = shear or third_order
        self.one_loop = one_loop

        self.k = k
        self.p = p
        self.pint = loginterp(k, p)(
            self.kint) * np.exp(-(self.kint / self.cutoff)**2)
        self.setup_powerspectrum()

        self.pktables = {}

        if self.third_order:
            self.num_power_components = 13
        elif self.shear:
            self.num_power_components = 11
        else:
            self.num_power_components = 7

        self.jn = jn
        self.threads = threads
        self.sph = SphericalBesselTransform(self.qint,
                                            L=self.jn,
                                            ncol=self.num_power_components,
                                            threads=self.threads)
        self.sph1 = SphericalBesselTransform(self.qint,
                                             L=self.jn,
                                             ncol=1,
                                             threads=self.threads)
        self.sphr = SphericalBesselTransformNP(self.kint, L=5, fourier=True)
 def compute_xi_real(self, rr, b1, b2, bs, b3, alpha, alpha_v, alpha_s0, alpha_s2, s2fog):
     '''
     Compute the real-space correlation function at rr.
     '''
     # This is just the zeroth moment:
     self.kv   = self.pktable[:,0]
     self.pzel = self.pktable[:,-1]
     
     self.peft = self.pktable[:,1] + b1*self.pktable[:,2] + b1**2*self.pktable[:,3]\
     + b2*self.pktable[:,4] + b1*b2*self.pktable[:,5] + b2**2 * self.pktable[:,6]\
     + bs*self.pktable[:,7] + b1*bs*self.pktable[:,8] + b2*bs*self.pktable[:,9]\
     + bs**2*self.pktable[:,10] + b3*self.pktable[:,11] + b1*b3*self.pktable[:,12] + alpha* self.kv**2 * self.pzel
     
     _integrand = loginterp(self.kv, self.peft)(self.kint) #at some point turn into theory extrapolation
     _integrand = self.weight * _integrand + (1-self.weight) * ((1+b1)**2 * self.plin)
     
     qint, xi = self.sph_gsm.sph(0,_integrand)
     
     xir = Spline(qint,xi)(rr)
     return xir
Beispiel #9
0
    def combine_bias_terms_xiell(self,bvec,method='loginterp'):
        '''
        Same as above but further transform the pkells into xiells.
        
        Again, the paramters f, AP are assumed to be what was input into p{ell}ktable.
        
        '''
        
        kv, p0, p2, p4 = self.combine_bias_terms_pkell(bvec)
        
        if method == 'loginterp':
        
            damping = np.exp(-(self.kint/10)**2)
            p0int = loginterp(kv, p0)(self.kint) * damping
            p2int = loginterp(kv, p2)(self.kint) * damping
            p4int = loginterp(kv, p4)(self.kint) * damping
            
        elif method == 'gauss_poly':
            # Add a point at k = 0 to the spline in k taper nicely
            
            frac = 1
            
            p0int = gaussian_poly_extrap( self.kint,\
                                          np.concatenate(([0], kv)),\
                                          np.concatenate(([0], p0)), frac=frac)
            
            p2int = gaussian_poly_extrap( self.kint,\
                                          np.concatenate(([0], kv)),\
                                          np.concatenate(([0], p2)), frac=frac )
            
            p4int = gaussian_poly_extrap( self.kint,\
                                          np.concatenate(([0], kv)),\
                                          np.concatenate(([0], p4)), frac=frac )
            
        elif method == 'min_cut':
            # Start log extrapolating when p_ell is below a threshold value:
            ftol = 1e-4
            damping = np.exp(-(self.kint/10)**2)
            
            pints = [np.zeros_like(self.kint), np.zeros_like(self.kint), np.zeros_like(self.kint),]
            
            for ii, pp in enumerate([p0,p2,p4]):
                
                iis = np.arange(len(kv))
                pval = np.max(pp)
                
                try:
                    zero_crossing = np.where(np.diff(np.sign(pp)))[0][0]
                except:
                    zero_crossing = len(pp)
                    
                cross_min = pp > (ftol * pval)

                # union is where we interpolate
                where_int = (iis < zero_crossing) * cross_min
                ktemp, ptemp = kv[where_int], pp[where_int]

                pints[ii] += loginterp(ktemp, ptemp)(self.kint) * damping

            p0int, p2int, p4int = pints
            
            
        ss0, xi0 = self.sphr.sph(0,p0int)
        ss2, xi2 = self.sphr.sph(2,p2int); xi2 *= -1
        ss4, xi4 = self.sphr.sph(4,p4int)
        
        return (ss0, xi0), (ss2, xi2), (ss4, xi4)
    def __init__(self,
                 k,
                 p,
                 pnw=None,
                 *args,
                 rbao=110,
                 kmin=1e-2,
                 kmax=0.5,
                 nk=100,
                 **kw):

        self.nk, self.kmin, self.kmax = nk, kmin, kmax
        self.rbao = rbao

        self.ept = EPT(k, p, kmin=kmin, kmax=kmax, nk=nk, **kw)
        if pnw is None:
            knw = self.ept.kint
            Nfilter = np.ceil(
                np.log(7) / np.log(knw[-1] / knw[-2])
            ) // 2 * 2 + 1  # filter length ~ log span of one oscillation from k = 0.01
            #print(Nfilter)
            pnw = savgol_filter(self.ept.pint, int(Nfilter), 4)
        else:
            knw, pnw = k, pnw

        self.ept_nw = EPT(knw, pnw, kmin=kmin, kmax=kmax, nk=nk, **kw)
        self.beyond_gauss = self.ept.beyond_gauss

        self.kv = self.ept.kv

        self.plin = loginterp(k, p)(self.kv)
        self.plin_nw = loginterp(knw, pnw)(self.kv)
        self.plin_w = self.plin - self.plin_nw
        self.sigma_squared_bao = np.interp(
            self.rbao, self.ept_nw.qint,
            self.ept_nw.Xlin + self.ept_nw.Ylin / 3.)
        self.damp_exp = -0.5 * self.kv**2 * self.sigma_squared_bao
        self.damp_fac = np.exp(self.damp_exp)
        self.plin_ir = self.plin_nw + self.plin_w * self.damp_exp

        self.pktable_nw = self.ept_nw.pktable_ept
        self.pktable_w = self.damp_fac[:, None] * (
            (self.ept.pktable_ept - self.pktable_nw) - self.damp_exp[:, None] *
            (self.ept.pktable_ept_linear - self.ept_nw.pktable_ept_linear))
        self.pktable_w[:, 0] = self.kv
        self.pktable = self.pktable_nw + self.pktable_w
        self.pktable[:, 0] = self.kv

        self.vktable_nw = self.ept_nw.vktable_ept
        self.vktable_w = self.damp_fac[:, None] * (
            (self.ept.vktable_ept - self.vktable_nw) - self.damp_exp[:, None] *
            (self.ept.vktable_ept_linear - self.ept_nw.vktable_ept_linear))
        self.vktable_w[:, 0] = self.kv
        self.vktable = self.vktable_nw + self.vktable_w
        self.vktable[:, 0] = self.kv

        self.s0ktable_nw = self.ept_nw.s0ktable_ept
        self.s0ktable_w = self.damp_fac[:, None] * (
            (self.ept.s0ktable_ept - self.s0ktable_nw) -
            self.damp_exp[:, None] *
            (self.ept.s0ktable_ept_linear - self.ept_nw.s0ktable_ept_linear))
        self.s0ktable_w[:, 0] = self.kv
        self.s0ktable = self.s0ktable_nw + self.s0ktable_w
        self.s0ktable[:, 0] = self.kv

        self.s2ktable_nw = self.ept_nw.s2ktable_ept
        self.s2ktable_w = self.damp_fac[:, None] * (
            (self.ept.s2ktable_ept - self.s2ktable_nw) -
            self.damp_exp[:, None] *
            (self.ept.s2ktable_ept_linear - self.ept_nw.s2ktable_ept_linear))
        self.s2ktable_w[:, 0] = self.kv
        self.s2ktable = self.s2ktable_nw + self.s2ktable_w
        self.s2ktable[:, 0] = self.kv

        if self.beyond_gauss:
            self.g1ktable_nw = self.ept_nw.g1ktable_ept
            self.g1ktable_w = self.damp_fac[:, None] * (
                self.ept.g1ktable_ept - self.ept_nw.g1ktable_ept)
            self.g1ktable_w[:, 0] = self.kv
            self.g1ktable = self.g1ktable_nw + self.g1ktable_w
            self.g1ktable[:, 0] = self.kv

            self.g3ktable_nw = self.ept_nw.g3ktable_ept
            self.g3ktable_w = self.damp_fac[:, None] * (
                self.ept.g3ktable_ept - self.ept_nw.g3ktable_ept)
            self.g3ktable_w[:, 0] = self.kv
            self.g3ktable = self.g3ktable_nw + self.g3ktable_w
            self.g3ktable[:, 0] = self.kv

            self.k0_nw, self.k2_nw, self.k4_nw = self.ept_nw.k0, self.ept_nw.k2, self.ept_nw.k4
            self.k0_w = self.damp_fac * (self.ept.k0 - self.ept_nw.k0)
            self.k2_w = self.damp_fac * (self.ept.k2 - self.ept_nw.k2)
            self.k4_w = self.damp_fac * (self.ept.k4 - self.ept_nw.k4)
            self.k0 = self.k0_nw + self.k0_w
            self.k2 = self.k2_nw + self.k2_w
            self.k4 = self.k4_nw + self.k4_w