示例#1
0
文件: tools.py 项目: duducosmos/hmf
def get_transfer(transfer_file, camb_dict, transfer_fit, k_bounds=None):
    """
    We use either CAMB or the EH approximation to get the transfer function.
    The transfer function is in terms of k/h -- IN UNITS OF h/Mpc??!!
    """
    #If no transfer file uploaded, but it was custom, execute CAMB
    if transfer_file is None:
        if transfer_fit == "CAMB":
            k, T, sig8 = pycamb.transfers(**camb_dict)
            T = np.log(T[[0, 6], :, 0])
            del sig8, k
        elif transfer_fit == "EH":
            k = np.exp(np.linspace(np.log(k_bounds[0]), np.log(k_bounds[1]), 250))
            #Since the function natively calculates the transfer based on k in Mpc^-1,
            # we need to multiply by h.
            t, T = pert.transfer_function_EH(k * camb_dict['H0'] / 100,
                                             omega_M_0=(camb_dict['omegac'] + camb_dict['omegab']), omega_lambda_0=camb_dict['omegav'],
                                             h=camb_dict["H0"] / 100, omega_b_0=camb_dict['omegab'], omega_n_0=camb_dict['omegan'],
                                             N_nu=camb_dict['Num_Nu_massive'])
            T = np.vstack((np.log(k), np.log(T)))
            del t
    else:
        #Import the transfer file
        T = read_transfer(transfer_file)

    return T
示例#2
0
def powerspectrum(A):
    assert A.WhichSpectrum == 2
    import pycamb
    a = dict(H0=A.h * 100., 
          omegac=A.OmegaM- A.OmegaB, 
          omegab=A.OmegaB, 
          omegav=A.OmegaL, 
          omegak=0.0, omegan=0,
          scalar_index=A.PrimordialIndex
          )
    print a
    fakesigma8 = pycamb.transfers(scalar_amp=1, **a)[2]
    scalar_amp = fakesigma8 ** -2 * A.Sigma8 ** 2
    k, p = pycamb.matter_power(scalar_amp=scalar_amp, maxk=500, **a)
    p[numpy.isnan(p)] = 0
    numpy.savetxt(A.PowerSpectrumFile, zip(k, p), fmt='%g')
示例#3
0
def powerspectrum(A):
    assert A.WhichSpectrum == 2
    import pycamb
    a = dict(H0=A.h * 100.,
             omegac=A.OmegaM - A.OmegaB,
             omegab=A.OmegaB,
             omegav=A.OmegaL,
             omegak=0.0,
             omegan=0,
             scalar_index=A.PrimordialIndex)
    print a
    fakesigma8 = pycamb.transfers(scalar_amp=1, **a)[2]
    scalar_amp = fakesigma8**-2 * A.Sigma8**2
    k, p = pycamb.matter_power(scalar_amp=scalar_amp, maxk=500, **a)
    p[numpy.isnan(p)] = 0
    numpy.savetxt(A.PowerSpectrumFile, zip(k, p), fmt='%g')
示例#4
0
    def lnt(self, lnk):
        """
        Generate transfer function with CAMB
        
        .. note :: This should not be called by the user!
        """
        for k in self.option_defaults:
            if k not in self.t.transfer_options:
                self.t.transfer_options[k] = self.option_defaults[k]

        cdict = dict(self.t.pycamb_dict,
                     **self.t.transfer_options)
        T = pycamb.transfers(**cdict)[1]
        T = np.log(T[[0, 6], :, 0])

        lnkout, lnT = self._check_low_k(T[0, :], T[1, :])

        return spline(lnkout, lnT, k=1)(lnk)
示例#5
0
 def Pk(self):
   import pycamb
   a = dict(H0=self.h * 100., 
         omegac=self.M- self.B, 
         omegab=self.B, 
         omegav=self.L, 
         omegak=1 - self.M - self.L, omegan=0)
   DH = 299792.468 / 100.
   fakesigma8 = pycamb.transfers(scalar_amp=1, **a)[2]
   scalar_amp = fakesigma8 ** -2 * self.sigma8 ** 2
   k, p = pycamb.matter_power(scalar_amp=scalar_amp, maxk=500, **a)
   k *= DH
   p /= DH ** 3
   p[numpy.isnan(p)] = 0
   func = interp1d(k, p, kind=5, bounds_error=False, fill_value=0)
   func.__doc__ = \
   """power spectrum P(k) normalized to sigma8.
      k is in 1/DH and p is in DH**3
   """
   return func
示例#6
0
 def Pk(self):
     import pycamb
     a = dict(H0=self.h * 100.,
              omegac=self.M - self.B,
              omegab=self.B,
              omegav=self.L,
              omegak=1 - self.M - self.L,
              omegan=0)
     DH = 299792.468 / 100.
     fakesigma8 = pycamb.transfers(scalar_amp=1, **a)[2]
     scalar_amp = fakesigma8**-2 * self.sigma8**2
     k, p = pycamb.matter_power(scalar_amp=scalar_amp, maxk=500, **a)
     k *= DH
     p /= DH**3
     p[numpy.isnan(p)] = 0
     func = interp1d(k, p, kind=5, bounds_error=False, fill_value=0)
     func.__doc__ = \
     """power spectrum P(k) normalized to sigma8.
    k is in 1/DH and p is in DH**3
 """
     return func
示例#7
0
    def lnt(self, lnk):
        """
        Natural log of the transfer function

        Parameters
        ----------
        lnk : array_like
            Wavenumbers [Mpc/h]

        Returns
        -------
        lnt : array_like
            The log of the transfer function at lnk.
        """

        pycamb_dict = {
            "w_lam": self.cosmo.w(0),
            "TCMB": self.cosmo.Tcmb0.value,
            "Num_Nu_massless": self.cosmo.Neff,
            "omegab": self.cosmo.Ob0,
            "omegac": self.cosmo.Om0 - self.cosmo.Ob0,
            "H0": self.cosmo.H0.value,
            "omegav": self.cosmo.Ode0,
            "omegak": self.cosmo.Ok0,
            "omegan": self.cosmo.Onu0,
            #                        "scalar_index":self.n,
        }

        cdict = dict(pycamb_dict, **self.params)
        T = pycamb.transfers(**cdict)[1]
        T = np.log(T[[0, 6], :, 0])

        if lnk[0] < T[0, 0]:
            lnkout, lnT = self._check_low_k(T[0, :], T[1, :], lnk[0])
        else:
            lnkout = T[0, :]
            lnT = T[1, :]
        return spline(lnkout, lnT, k=1)(lnk)
示例#8
0
    def lnt(self, lnk):
        """
        Natural log of the transfer function

        Parameters
        ----------
        lnk : array_like
            Wavenumbers [Mpc/h]

        Returns
        -------
        lnt : array_like
            The log of the transfer function at lnk.
        """

        pycamb_dict = {
            "w_lam": self.cosmo.w(0),
            "TCMB": self.cosmo.Tcmb0.value,
            "Num_Nu_massless": self.cosmo.Neff,
            "omegab": self.cosmo.Ob0,
            "omegac": self.cosmo.Om0 - self.cosmo.Ob0,
            "H0": self.cosmo.H0.value,
            "omegav": self.cosmo.Ode0,
            "omegak": self.cosmo.Ok0,
            "omegan": self.cosmo.Onu0,
            #                        "scalar_index":self.n,
        }

        cdict = dict(pycamb_dict, **self.params)
        T = pycamb.transfers(**cdict)[1]
        T = np.log(T[[0, 6], :, 0])

        if lnk[0] < T[0, 0]:
            lnkout, lnT = self._check_low_k(T[0, :], T[1, :], lnk[0])
        else:
            lnkout = T[0, :]
            lnT = T[1, :]
        return spline(lnkout, lnT, k=1)(lnk)
示例#9
0
文件: __init__.py 项目: Jravis/gaepsi
 def power(self, OmegaB, sigma8):
   """ returns matter power spectrum. need pycamb 
       the power spectrum will be in GADGET normalization,
       normalized to (2 * numpy.pi) ** -3 * P_phys(k)
       This takes a long time to calculate; and no caching
       is implemented.
       returns a function P_k(k).
   """
   import pycamb
   from scipy.interpolation import interp1d
   assert self.M + self.L + self.K == 1.0
   args = dict(H0=self.h * 100, 
         omegac=self.M - OmegaB, 
         omegab=OmegaB, 
         omegav=self.L, 
         omegak=0,
         omegan=0)
   fakesigma8 = pycamb.transfers(scalar_amp=1, **args)[2]
   scalar_amp = fakesigma8 ** -2 * sigma8 ** 2
   k, p = pycamb.matter_power(scalar_amp=scalar_amp, maxk=10, **args)
   k /= self.U.MPC_h
   p *= (self.U.MPC_h) ** 3 * (2 * numpy.pi) ** -3 # xiao to GADGET
   return interp1d(k, p, kind='linear', copy=True, 
             bounds_error=False, fill_value=0)