예제 #1
0
def test_tinker10_dh():
    h = MassFunction(hmf_model="Tinker10")
    h1 = MassFunction(hmf_model="Tinker10",
                      mdef_model="SOMean",
                      mdef_params={"overdensity": 200.1})

    assert np.allclose(h.fsigma, h1.fsigma, rtol=1e-2)
예제 #2
0
파일: test_fits.py 프로젝트: mirochaj/hmf
class TestFitsCloseness(object):
    """
    This basically tests all implemented fits to check the form for three things:
    1) whether the maximum fsigma is less than in the PS formula (which is known to overestimate)
    2) whether the slope is positive below this maximum
    3) whether the slope is negative above this maximum

    Since it calls each class, any blatant errors should also pop up.
    """
    def __init__(self):

        self.hmf = MassFunction(Mmin=10, Mmax=15, dlog10m=0.1,
                       lnk_min=-16, lnk_max=10, dlnk=0.01,
                       hmf_model='PS', z=0.0, sigma_8=0.8, n=1,
                       cosmo_params={"Om0":0.3, "H0":70.0, "Ob0":0.05})

        self.ps_max = self.hmf.fsigma.max()

    def test_max_lt_ps(self):
        for redshift in [0.0, 2.0]:
            for fit in allfits:
                if fit is ff.PS:
                    continue
                # if fit is ff.AnguloBound:
                #     continue
                yield self.check_form, fit, redshift

    def check_form(self,fit,redshift):
        self.hmf.update(z=redshift, hmf_model=fit)
        maxarg = np.argmax(self.hmf.fsigma)
        assert self.ps_max >= self.hmf.fsigma[maxarg]
        assert np.all(np.diff(self.hmf.fsigma[:maxarg]) >= 0)
        assert np.all(np.diff(self.hmf.fsigma[maxarg:]) <= 0)
예제 #3
0
파일: test_fcoll.py 프로젝트: tbs1980/hmf
    def test_fcolls(self):

        pert = MassFunction(M=np.linspace(10, 15, 1301))
        fits = ['PS', 'Peacock']

        for fit in fits:
            pert.update(mf_fit=fit)
            yield self.check_fcoll, pert, fit
예제 #4
0
    def test_fcolls(self):
        # Note: if Mmax>15, starts going wrong because of numerics at high M
        pert = MassFunction(Mmin=10, Mmax=15, dlog10m=0.01)
        fits = ['PS', 'Peacock']

        for fit in fits:
            pert.update(hmf_model=fit)
            yield self.check_fcoll, pert, fit
예제 #5
0
파일: test_genmf.py 프로젝트: tbs1980/hmf
 def test_sigmas(self):
     hmf = MassFunction(M=np.linspace(7, 15, 801), omegab=0.05, omegac=0.25,
                         omegav=0.7, sigma_8=0.8, n=1, H0=70.0,
                         lnk=np.linspace(-21, 21, 500), transfer__kmax=10,
                         transfer__k_per_logint=50, mf_fit='ST', z=0.0)
     for redshift in [0.0, 2.0]:
         hmf.update(z=redshift)
         for origin in ['camb', 'hmf']:
             for col in ['sigma', 'lnsigma', 'n_eff']:
                 yield self.check_col, hmf, "ST", redshift, origin, col
예제 #6
0
class hmf(Theory):
    # params = {'omegabh2': None, 'omegach2': None, 'H0': None}

    def initialize(self):
        self._hmf_kwargs = {'use_splined_growth': True}
        self._hmf_kwargs.update(self.hmf_kwargs)
        # self.input_params = ['omegabh2', 'omegach2', 'H0']

        self.quants = ['dndm', 'rho_gtm', 'ngtm', 'power', 'growth_factor']

    def needs(self, **requirements):
        self._reqs = requirements.keys()

    def get_can_provide(self):
        return self.quants + ['MF']

    def get_requirements(self):
        print("Requirements")
        return {
            "Pk_interpolator": {
                "z": self.zarr,
                "k_max": 5.0,
                "nonlinear": False,
                "vars_pairs": [["delta_tot", "delta_tot"]],
            },
        }

    def initialize_with_params(self):
        print("params")
        pass

    def calculate(self, state, want_derived=True, **params_values_dict):
        self._hmf_kwargs['z'] = self.zarr[0]
        h = params_values_dict["H0"] / 100
        Oc = params_values_dict['omegach2'] / h**2
        Ob = params_values_dict['omegabh2'] / h**2
        Om = Oc + Ob
        Ode = 1 - Om
        self._hmf_kwargs['cosmo_params'] = {
            'H0': 100 * h,
            'Om0': Om,
            'Ob0': Ob,
        }
        self.MF = MassFunction(**self._hmf_kwargs)
        pk_interp = self.provider.get_Pk_interpolator(nonlinear=False)
        for q in self.quants:
            state[q] = []
        print("HERE")
        for i, z in enumerate(self.zarr):
            self.MF.update(z=z, custom_pk=pk_interp.P(z, self.MF.k))
            for q in self.quants:
                state[q].append(getattr(self.MF, q).copy())
        state["MF"] = self.MF
        state['zs'] = self.zarr
예제 #7
0
파일: test_genmf.py 프로젝트: tbs1980/hmf
 def test_fits(self):
     hmf = MassFunction(M=np.linspace(7, 15, 801), omegab=0.05, omegac=0.25,
                        omegav=0.7, sigma_8=0.8, n=1, H0=70.0,
                        lnk=np.linspace(-21, 21, 500), transfer__kmax=10,
                        transfer__k_per_logint=50, mf_fit='ST', z=0.0)
     for redshift in [0.0, 2.0]:
         hmf.update(z=redshift)
         for fit in ["ST", "PS", "Reed03", "Warren", "Jenkins", "Reed07"]:
             hmf.update(mf_fit=fit)
             for origin in ['camb', 'hmf']:
                 for col in ['dndlog10m', 'ngtm', 'fsigma']:
                     yield self.check_col, hmf, fit, redshift, origin, col
예제 #8
0
def test_change_dndm(colossus_cosmo):
    h = MassFunction(mdef_model="SOVirial",
                     hmf_model="Warren",
                     disable_mass_conversion=False)

    with pytest.warns(UserWarning):
        h.mdef

    dndm = h.dndm

    h.update(mdef_model="FOF")

    assert not np.allclose(h.dndm, dndm, atol=0, rtol=0.15)
예제 #9
0
파일: test_fits.py 프로젝트: liuxx479/hmf-1
def test_tinker08_dh():
    h = MassFunction(
        hmf_model="Tinker08",
        mdef_model="SOMean",
        mdef_params={"overdensity": 200},
        transfer_model="EH",
    )
    h1 = MassFunction(
        hmf_model="Tinker08",
        mdef_model="SOMean",
        mdef_params={"overdensity": 200.1},
        transfer_model="EH",
    )

    assert np.allclose(h.fsigma, h1.fsigma, rtol=1e-2)
예제 #10
0
    def MF(self):
        if not hasattr(self, '_MF'):

            self.logMmin_tab = self.pf['hmf_logMmin']
            self.logMmax_tab = self.pf['hmf_logMmax']
            self.zmin = self.pf['hmf_zmin']
            self.zmax = self.pf['hmf_zmax']
            self.dlogM = self.pf['hmf_dlogM']
            self.dz = self.pf['hmf_dz']

            self.Nz = int((self.zmax - self.zmin) / self.dz + 1)
            self.z = np.linspace(self.zmin, self.zmax, self.Nz)

            # Initialize Perturbations class
            self._MF = MassFunction(Mmin=self.logMmin_tab,
                                    Mmax=self.logMmax_tab,
                                    dlog10m=self.dlogM,
                                    z=self.z[0],
                                    hmf_model=self.hmf_func,
                                    cosmo_params=self.cosmo_params,
                                    growth_params=self.growth_pars,
                                    sigma_8=self.cosm.sigma8,
                                    n=self.cosm.primordial_index,
                                    transfer_params=self.transfer_pars,
                                    dlnk=self.pf['hmf_dlnk'],
                                    lnk_min=self.pf['hmf_lnk_min'],
                                    lnk_max=self.pf['hmf_lnk_max'])

        return self._MF
예제 #11
0
def test_tinker10_neg_etaphi():
    h = MassFunction(hmf_model="Tinker10",
                     hmf_params={
                         "eta_200": -1,
                         "phi_200": 0
                     })
    h.fsigma
예제 #12
0
def getHMFz(z,
            H0=70.3,
            Om0=0.276,
            Ob0=0.0455,
            Tcmb0=2.725,
            Mmin=1e10,
            Mmax=1e15):
    """ Fast function to call the HMF from hmf, this function only has 
        7 variables and will return the dn/d(log10 M) and M array.
        z: redshift
        H0: Hubble constant
        Om0: Matter density
        Ob0: Baryon density
        Tcmb0: CMB temperature at z=0
        Mmin: minimum mass (solar masses)
        Mmax: Maximum mass (solar masses) 
    """
    new_model = FlatLambdaCDM(H0=H0, Om0=Om0, Ob0=Ob0, Tcmb0=Tcmb0)
    hmff = MassFunction(
        cosmo_model=new_model,
        Mmax=np.log10(Mmax),
        Mmin=np.log10(Mmin),
        z=z,
        hmf_model="ST",
    )
    return hmff.m, hmff.dndlog10m
예제 #13
0
 def test_ranges_cut(self):
     hmf = MassFunction(hmf_model="Peacock", dlog10m=0.01)
     TestCumulants.tol = 0.4
     for minm in [9, 10, 11]:  # below, equal and greater than peacock cut
         for maxm in [
                 14, 15, 16, 18, 19
         ]:  # below,equal,greater than peacock cut and integration limit
             yield self.check, hmf, minm, maxm
예제 #14
0
파일: test_fits.py 프로젝트: mirochaj/hmf
    def __init__(self):

        self.hmf = MassFunction(Mmin=10, Mmax=15, dlog10m=0.1,
                       lnk_min=-16, lnk_max=10, dlnk=0.01,
                       hmf_model='PS', z=0.0, sigma_8=0.8, n=1,
                       cosmo_params={"Om0":0.3, "H0":70.0, "Ob0":0.05})

        self.ps_max = self.hmf.fsigma.max()
예제 #15
0
class TestFitsCloseness(object):
    """
    This basically tests all implemented fits to check the form for three things:
    1) whether the maximum fsigma is less than in the PS formula (which is known to overestimate)
    2) whether the slope is positive below this maximum
    3) whether the slope is negative above this maximum

    Since it calls each class, any blatant errors should also pop up.
    """
    def __init__(self):

        self.hmf = MassFunction(Mmin=10,
                                Mmax=15,
                                dlog10m=0.1,
                                lnk_min=-16,
                                lnk_max=10,
                                dlnk=0.01,
                                hmf_model='PS',
                                z=0.0,
                                sigma_8=0.8,
                                n=1,
                                cosmo_params={
                                    "Om0": 0.3,
                                    "H0": 70.0,
                                    "Ob0": 0.05
                                })

        self.ps_max = self.hmf.fsigma.max()

    def test_max_lt_ps(self):
        for redshift in [0.0, 2.0]:
            for fit in allfits:
                if fit is ff.PS:
                    continue
                # if fit is ff.AnguloBound:
                #     continue
                yield self.check_form, fit, redshift

    def check_form(self, fit, redshift):
        self.hmf.update(z=redshift, hmf_model=fit)
        maxarg = np.argmax(self.hmf.fsigma)
        assert self.ps_max >= self.hmf.fsigma[maxarg]
        assert np.all(np.diff(self.hmf.fsigma[:maxarg]) >= 0)
        assert np.all(np.diff(self.hmf.fsigma[maxarg:]) <= 0)
예제 #16
0
    def hmf(self, z,  Mmin, Mmax, q_out = 'dndlnM', hmf_code='colossus', print_cosmo=False):
        if(hmf_code=='colossus'):
            params = {'flat': True, 'H0': self.H0, 'Om0': self.om, 'Ob0': self.ob, 'sigma8': self.sigma8, 'ns': self.ns}
            col_cosmology.addCosmology('myCosmo', params)
            colcosmo=col_cosmology.setCosmology('myCosmo')
            
            if print_cosmo:
                print(colcosmo)
    
            #Mass_bin = np.logspace(np.log10(Mmin),np.log10(Mmax), num=500)
            
            Mh = 10**(np.linspace(np.log10(Mmin),np.log10(Mmax), num=200))
            
            Mh=Mh/self.h
            
            #mfunc = mass_function.massFunction(Mh, z, mdef = self.halo_model_mdef, model = self.halo_model, q_out = q_out)
            
            mfunc = mass_function.massFunction(Mh, z, mdef = '200m', model = 'tinker08', q_out = q_out)
            
            mpc_to_m= 3.086e+22
            
            mfunc*=(mpc_to_m)**-3
                    
            dndm=mfunc
            
            return Mh, dndm
        
        
        if(hmf_code=='hmf'):
            from hmf import cosmo as cosmo_hmf
            my_cosmo = cosmo_hmf.Cosmology()
            my_cosmo.update(cosmo_params={"H0":self.H0,"Om0":self.om,"Ode0":self.ol,"Ob0":self.ob})

            mf=MassFunction(Mmin=np.log10(Mmin), Mmax=np.log10(Mmax), hmf_model= 'ST')
            mf.update(z=z)
            
            mpc_to_m= 3.086e+22
            #hm, dndm= mf.m, mf.dndlnm
            
            hm, dndm= mf.m/self.h, mf.dndlnm *(mpc_to_m)**-3 #* self.h**4*(mpc_to_m)**-3
            
           # dndm*=(mpc_to_m)**-3
    
            return hm, dndm
예제 #17
0
    def __init__(self):

        self.hmf = MassFunction(Mmin=10,
                                Mmax=15,
                                dlog10m=0.1,
                                lnk_min=-16,
                                lnk_max=10,
                                dlnk=0.01,
                                hmf_model='PS',
                                z=0.0,
                                sigma_8=0.8,
                                n=1,
                                cosmo_params={
                                    "Om0": 0.3,
                                    "H0": 70.0,
                                    "Ob0": 0.05
                                })

        self.ps_max = self.hmf.fsigma.max()
예제 #18
0
def compute_HMF(redshift, hmf_model='SMT'):
    '''
    hmf_model = PS, Jenkins, SMT, Warren, Tinker08
    '''
    HMF_WMAP = MassFunction(cosmo_model=cosmo,
                            z=redshift,
                            Mmin=1,
                            Mmax=13,
                            hmf_model=hmf_model)
    HMF_Planck = MassFunction(cosmo_model=cosmoP,
                              z=redshift,
                              Mmin=1,
                              Mmax=13,
                              hmf_model=hmf_model)
    #hmf.update(hmf_model='Sheth-Tormen') #update baryon density and redshift
    masses = HMF_WMAP.m / cosmo.h
    MF_WMAP = HMF_WMAP.dndlog10m * cosmo.h**3
    MF_Planck = HMF_Planck.dndlog10m * cosmo.h**3
    return (masses, MF_WMAP, MF_Planck)
예제 #19
0
def P_k(k, z, cosmo):
    '''
	DM linear power spectrum, using transfer function from Eisenstein & Hu (1998) from hmf
	'''
    hmf = MassFunction(Mmin=9,
                       Mmax=16,
                       z=z,
                       cosmo_model=cosmo,
                       transfer_model='EH_BAO')
    f = interp1d(hmf.k, hmf.power, kind='cubic')
    return f(k)
예제 #20
0
파일: test_fits.py 프로젝트: liuxx479/hmf-1
def test_tinker10_neg_etaphi():
    with raises(ValueError):
        h = MassFunction(
            hmf_model="Tinker10",
            hmf_params={
                "eta_200": -1,
                "phi_200": 0
            },
            transfer_model="EH",
        )
        h.fsigma
예제 #21
0
 def __init__(self):
     self.hmf = MassFunction(Mmin=7,
                             Mmax=15.001,
                             dlog10m=0.01,
                             omegab=0.05,
                             omegac=0.25,
                             omegav=0.7,
                             sigma_8=0.8,
                             n=1,
                             H0=70.0,
                             lnk_min=-11,
                             lnk_max=11,
                             dlnk=0.01,
                             transfer_options={
                                 "fname":
                                 LOCATION +
                                 "/data/transfer_for_hmf_tests.dat"
                             },
                             mf_fit='ST',
                             z=0.0,
                             transfer_fit="FromFile")
예제 #22
0
class TestGenMF(object):
    def __init__(self):
        self.hmf = MassFunction(Mmin=7,
                                Mmax=15.001,
                                dlog10m=0.01,
                                sigma_8=0.8,
                                n=1,
                                cosmo_model=LambdaCDM(Ob0=0.05,
                                                      Om0=0.3,
                                                      Ode0=0.7,
                                                      H0=70.0,
                                                      Tcmb0=0),
                                lnk_min=-11,
                                lnk_max=11,
                                dlnk=0.01,
                                transfer_params={
                                    "fname":
                                    LOCATION +
                                    "/tests/data/transfer_for_hmf_tests.dat"
                                },
                                hmf_model='ST',
                                z=0.0,
                                transfer_model="FromFile",
                                growth_model="GenMFGrowth")

    def check_col(self, pert, fit, redshift, col):
        """ Able to check all columns"""
        data = np.genfromtxt(LOCATION + "/tests/data/" + fit + '_' +
                             str(int(redshift)))[::-1][400:1201]

        # We have to do funky stuff to the data if its been cut by genmf
        if col is "sigma":
            assert max_diff_rel(pert.sigma, data[:, 5], 0.004)
        elif col is "lnsigma":  # We just do diff on this one because it passes through 0
            assert max_diff(pert.lnsigma, data[:, 3], 0.001)
        elif col is "n_eff":
            assert max_diff_rel(pert.n_eff, data[:, 6], 0.001)
        elif col is "dndlog10m":
            assert rms_diff(pert.dndlog10m, 10**data[:, 1], 0.004)
        elif col is "fsigma":
            assert rms_diff(pert.fsigma, data[:, 4], 0.004)
        elif col is "ngtm":
            # # The reason this is only good to 5% is GENMF's problem -- it uses
            # # poor integration.
            assert rms_diff(pert.ngtm, 10**data[:, 2], 0.047)

    def test_sigmas(self):
        # # Test z=0,2. Higher redshifts are poor in genmf.
        for redshift in [0.0, 2.0]:  # , 10, 20]:
            self.hmf.update(z=redshift)
            for col in ['sigma', 'lnsigma', 'n_eff']:
                yield self.check_col, self.hmf, "ST", redshift, col

    def test_fits(self):
        for redshift in [0.0, 2.0]:  # , 10, 20]:
            self.hmf.update(z=redshift)
            for fit in ["ST", "PS", "Reed03", "Warren", "Jenkins", "Reed07"]:
                self.hmf.update(hmf_model=fit)
                for col in ['dndlog10m', 'ngtm', 'fsigma']:
                    yield self.check_col, self.hmf, fit, redshift, col
예제 #23
0
파일: lim.py 프로젝트: yuntingcheng/lim
 def h(self):
     '''
     Initialzes hmf MassFunction() model.  Note that, unlike other cached
     properties, h is NOT cleared when update() is called.  Properties of h
     are updated using the hmf built-in update methods.  This speeds up 
     calculations where the astrophysical model is updated without changing
     the underlying cosmology
     '''
     return MassFunction(cosmo_model=self.cosmo_model,
                         Mmin=hmf_logMmin,
                         Mmax=hmf_logMmax,
                         dlog10m=hmf_dlog10m,
                         z=self.z)
예제 #24
0
 def calculate(self, state, want_derived=True, **params_values_dict):
     self._hmf_kwargs['z'] = self.zarr[0]
     h = params_values_dict["H0"] / 100
     Oc = params_values_dict['omegach2'] / h**2
     Ob = params_values_dict['omegabh2'] / h**2
     Om = Oc + Ob
     Ode = 1 - Om
     self._hmf_kwargs['cosmo_params'] = {
         'H0': 100 * h,
         'Om0': Om,
         'Ob0': Ob,
     }
     self.MF = MassFunction(**self._hmf_kwargs)
     pk_interp = self.provider.get_Pk_interpolator(nonlinear=False)
     for q in self.quants:
         state[q] = []
     print("HERE")
     for i, z in enumerate(self.zarr):
         self.MF.update(z=z, custom_pk=pk_interp.P(z, self.MF.k))
         for q in self.quants:
             state[q].append(getattr(self.MF, q).copy())
     state["MF"] = self.MF
     state['zs'] = self.zarr
예제 #25
0
 def __init__(self):
     self.hmf = MassFunction(Mmin=7,
                             Mmax=15.001,
                             dlog10m=0.01,
                             sigma_8=0.8,
                             n=1,
                             cosmo_model=LambdaCDM(Ob0=0.05,
                                                   Om0=0.3,
                                                   Ode0=0.7,
                                                   H0=70.0,
                                                   Tcmb0=0),
                             lnk_min=-11,
                             lnk_max=11,
                             dlnk=0.01,
                             transfer_params={
                                 "fname":
                                 LOCATION +
                                 "/tests/data/transfer_for_hmf_tests.dat"
                             },
                             hmf_model='ST',
                             z=0.0,
                             transfer_model="FromFile",
                             growth_model="GenMFGrowth")
예제 #26
0
 def test_circular_emcee():
     h = MassFunction(sigma_8=0.8, mf_fit="ST")
     dndm = h.dndm.copy()
     f = fit.MCMC(priors=[fit.Uniform("sigma_8", 0.6, 1.0)],
                  data=dndm,
                  quantity="dndm",
                  sigma=dndm / 5,
                  guess=[0.8],
                  blobs=None,
                  verbose=0,
                  store_class=False,
                  relax=False)
     sampler = f.fit(h, nwalkers=16, nsamples=15, burnin=0, nthreads=0)
     print "Diff: ", np.abs(np.mean(sampler.chain) - 0.8)
     assert np.abs(np.mean(sampler.chain) - 0.8) < 0.01
예제 #27
0
def test_circular_minimize():
    h = MassFunction(sigma_8=0.8, mf_fit="ST")
    dndm = h.dndm.copy()
    f = fit.Minimize(priors=[fit.Uniform("sigma_8", 0.6, 1.0)],
                     data=dndm,
                     quantity="dndm",
                     sigma=dndm / 5,
                     guess=[0.9],
                     blobs=None,
                     verbose=0,
                     store_class=False,
                     relax=False)
    res = f.fit(h)
    print "Diff: ", np.abs(res.x - 0.8)
    assert np.abs(res.x - 0.8) < 0.01
예제 #28
0
파일: test_fits.py 프로젝트: inonchiu/hmf
def test_all_fits():
    hmf = MassFunction(Mmin=10,
                       Mmax=15,
                       dlog10m=0.1,
                       omegab=0.05,
                       omegac=0.25,
                       omegav=0.7,
                       sigma_8=0.8,
                       n=1,
                       H0=70.0,
                       lnk_min=-16,
                       lnk_max=10,
                       dlnk=0.01,
                       mf_fit='ST',
                       z=0.0)
    close_hmf = MassFunction(Mmin=10,
                             Mmax=15,
                             dlog10m=0.1,
                             omegab=0.05,
                             omegac=0.25,
                             omegav=0.7,
                             sigma_8=0.8,
                             n=1,
                             H0=70.0,
                             lnk_min=-16,
                             lnk_max=10,
                             dlnk=0.01,
                             mf_fit='ST',
                             z=0.0)
    hmf.fsigma
    close_hmf.fsigma
    ff._allfits.remove("AnguloBound")

    for redshift in [0.0, 2.0]:
        for fit in ff._allfits:
            yield check_close, hmf, close_hmf, fit, redshift
예제 #29
0
def get_hf(sigma_val=0.8228, boxRedshift=0., delta_wrt='mean'):
    """
    Halo mass function model for the MultiDark simulation.
    """
    #hf0 = MassFunction(cosmo_model=cosmo, sigma_8=sigma_val, z=boxRedshift)
    omega = lambda zz: cosmoMD.Om0 * (1 + zz)**3. / cosmoMD.efunc(zz)**2
    DeltaVir_bn98 = lambda zz: (18. * n.pi**2. + 82. * (omega(zz) - 1) - 39. *
                                (omega(zz) - 1)**2.) / omega(zz)
    print "DeltaVir", DeltaVir_bn98(boxRedshift), " at z", boxRedshift
    hf1 = MassFunction(cosmo_model=cosmoMD,
                       sigma_8=sigma_val,
                       z=boxRedshift,
                       delta_h=DeltaVir_bn98(boxRedshift),
                       delta_wrt=delta_wrt,
                       Mmin=7,
                       Mmax=16.5)
    return hf1
예제 #30
0
def Tinker08(z=0):
    """Tinker halo mass function generator

    Returns
    ----------
    dict
        A dictionary contains of 'x' and 'y' keys, suitable to use with
        ..visualization.plot module
    """

    hmf = MassFunction(hmf_model=ff.Tinker08,
                       delta_h=200.0,
                       z=z,
                       filter_model=TopHat,
                       transfer_model=tm.EH,
                       cosmo_model=Planck15)

    return {'x': hmf.m, 'y': hmf.dndlnm}
예제 #31
0
파일: test_fits.py 프로젝트: liuxx479/hmf-1
def hmf():
    return MassFunction(
        Mmin=10,
        Mmax=15,
        dlog10m=0.1,
        lnk_min=-16,
        lnk_max=10,
        dlnk=0.01,
        hmf_model="PS",
        z=0.0,
        sigma_8=0.8,
        n=1,
        cosmo_params={
            "Om0": 0.3,
            "H0": 70.0,
            "Ob0": 0.05
        },
        transfer_model="EH",
    )
예제 #32
0
    def __init__(self, redshifts=None):

        self.hmf = MassFunction(dlog10m=0.02)
        self.mrange = self.hmf.m * u.solMass
        self.rho = self.hmf.rho_gtm[0] * u.solMass * u.Mpc**(
            -3)  # mean number of DM halos per Mpc^3
        self.m_star = (
            4 * np.pi * self.R_star**3 /
            3) * self.rho  # used as pivot mass for halo concentration
        self.kmax = 1e3 / self.h

        if redshifts is None:
            self.redshifts = np.array([0.0])
            self.linpars.set_matter_power(kmax=self.kmax)
        else:
            self.redshifts = redshifts
            self.linpars.set_matter_power(redshifts=redshifts, kmax=self.kmax)

        self.linpars.NonLinear = model.NonLinear_none
        self.lin_results = camb.get_results(self.linpars)
예제 #33
0
def _prepare_mf(M_min, M_max, mf_kwargs, boxsize=None):
    # Create the mass function object
    M = np.linspace(M_min, M_max, 500)
    if boxsize is not None:
        mf_kwargs['lnk'] = np.linspace(np.log(2 * np.pi / boxsize), 20, 500)

    mf_obj = MassFunction(M=M, **mf_kwargs)

    # Get the total density within limits
    total_rho = simps(mf_obj.M * mf_obj.dndlnm, M) * np.log(10)
    frac_in_bounds = total_rho / (mf_obj.cosmo.omegam * 2.7755e11)

    cumfunc = cumtrapz(mf_obj.dndlnm, M, initial=1e-20) * np.log(10)

    cdf = spline(M, cumfunc, k=3)
    icdf = spline(cumfunc, M, k=3)

    print "prepare mf: ", total_rho, frac_in_bounds, M_min, M_max, cumfunc.min(
    ), cumfunc.max()
    return cdf, icdf, mf_obj, frac_in_bounds
예제 #34
0
def load_massfunction(cosmo_model = default_cosmo, hmf_model_sel = 4, sigma_8 = 0.821, n = 0.972, \
                        delta_h = 500, delta_wrt_sel = 1, Mmin = 13, Mmax = 16, dlog10m = 0.001, \
                        transfer_model_sel = 3, lnk_min = -4, lnk_max = 2, dlnk = 0.0026, \
                        transfer_params = None, takahashi = True):

    hmf_model_array = ['SMT', 'Jenkins', 'Warren', 'Tinker08', 'Tinker10']
    hmf_model = hmf_model_array[hmf_model_sel]

    delta_wrt_array = ['mean', 'crit']
    delta_wrt = delta_wrt_array[delta_wrt_sel]

    transfer_model_array = ['BBKS', 'BondEfs', 'CAMB', 'EH']
    transfer_model = transfer_model_array[transfer_model_sel]

    h = MassFunction(cosmo_model = cosmo_model, hmf_model = hmf_model, sigma_8 = sigma_8, n = n, \
                    delta_h = delta_h, delta_wrt = delta_wrt, Mmin = Mmin, Mmax = Mmax, \
                    dlog10m = dlog10m, transfer_model = transfer_model, lnk_min = lnk_min, \
                    lnk_max = lnk_max, dlnk = dlnk, transfer_params = transfer_params, \
                    takahashi = takahashi)

    return h
예제 #35
0
 def hmf(self):
     return MassFunction(
         Mmin=7,
         Mmax=15.001,
         dlog10m=0.01,
         sigma_8=0.8,
         n=1,
         cosmo_model=LambdaCDM(Ob0=0.05,
                               Om0=0.3,
                               Ode0=0.7,
                               H0=70.0,
                               Tcmb0=0),
         lnk_min=-11,
         lnk_max=11,
         dlnk=0.01,
         transfer_params={"fname": "tests/data/transfer_for_hmf_tests.dat"},
         hmf_model="ST",
         z=0.0,
         transfer_model="FromFile",
         growth_model="GenMFGrowth",
     )
예제 #36
0
파일: test_genmf.py 프로젝트: inonchiu/hmf
class TestGenMF(object):
    def __init__(self):
        self.hmf = MassFunction(Mmin=7, Mmax=15.001, dlog10m=0.01, omegab=0.05, omegac=0.25,
                            omegav=0.7, sigma_8=0.8, n=1, H0=70.0,
                            lnk_min=-11, lnk_max=11, dlnk=0.01, transfer_options={"fname":LOCATION + "/data/transfer_for_hmf_tests.dat"},
                            mf_fit='ST', z=0.0, transfer_fit="FromFile")

    def check_col(self, pert, fit, redshift, col):
        """ Able to check all columns only dependent on base cosmology (not fit) """


        data = np.genfromtxt(LOCATION + "/data/" + fit + '_' + str(int(redshift)))[::-1][400:1201]

        # We have to do funky stuff to the data if its been cut by genmf
        if col is "sigma":
            assert max_diff_rel(pert.sigma, data[:, 5], 0.004)
        elif col is "lnsigma":  # We just do diff on this one because it passes through 0
            assert max_diff(pert.lnsigma, data[:, 3], 0.001)
        elif col is "n_eff":
            assert max_diff_rel(pert.n_eff, data[:, 6], 0.001)
        elif col is "dndlog10m":
            assert rms_diff(pert.dndlog10m, 10 ** data[:, 1], 0.004)
        elif col is "fsigma":
            assert rms_diff(pert.fsigma, data[:, 4], 0.004)
        elif col is "ngtm":
            # # The reason this is only good to 5% is GENMF's problem -- it uses
            # # poor integration.
            assert rms_diff(pert.ngtm, 10 ** data[:, 2], 0.046)

    def test_sigmas(self):
        # # Test z=0,2. Higher redshifts are poor in genmf.
        for redshift in [0.0, 2.0]:  # , 10, 20]:
            self.hmf.update(z=redshift)
            for col in ['sigma', 'lnsigma', 'n_eff']:
                yield self.check_col, self.hmf, "ST", redshift, col

    def test_fits(self):
        for redshift in [0.0, 2.0]:  # , 10, 20]:
            self.hmf.update(z=redshift)
            for fit in ["ST", "PS", "Reed03", "Warren", "Jenkins", "Reed07"]:
                self.hmf.update(mf_fit=fit)
                for col in ['dndlog10m', 'ngtm', 'fsigma']:
                    yield self.check_col, self.hmf, fit, redshift, col
예제 #37
0
파일: test_genmf.py 프로젝트: mirochaj/hmf
 def __init__(self):
     self.hmf = MassFunction(Mmin=7, Mmax=15.001, dlog10m=0.01,
                             sigma_8=0.8, n=1,
                             cosmo_model=LambdaCDM(Ob0=0.05, Om0=0.3, Ode0=0.7, H0=70.0,Tcmb0=0),
                             lnk_min=-11, lnk_max=11, dlnk=0.01, transfer_params={"fname":LOCATION + "/tests/data/transfer_for_hmf_tests.dat"},
                             hmf_model='ST', z=0.0, transfer_model="FromFile", growth_model="GenMFGrowth")
예제 #38
0
파일: test_genmf.py 프로젝트: inonchiu/hmf
 def __init__(self):
     self.hmf = MassFunction(Mmin=7, Mmax=15.001, dlog10m=0.01, omegab=0.05, omegac=0.25,
                         omegav=0.7, sigma_8=0.8, n=1, H0=70.0,
                         lnk_min=-11, lnk_max=11, dlnk=0.01, transfer_options={"fname":LOCATION + "/data/transfer_for_hmf_tests.dat"},
                         mf_fit='ST', z=0.0, transfer_fit="FromFile")