예제 #1
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)
예제 #2
0
파일: test_fcoll.py 프로젝트: mirochaj/hmf
    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
예제 #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
파일: 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
예제 #5
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
예제 #6
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
예제 #7
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
예제 #8
0
파일: HMFmockData.py 프로젝트: nesar/WL_emu
for idx in range(np.shape(AllCombinations)[0]):
    Om_a, H0_a, ns_a, sigma8_a, delta_a = AllCombinations[idx]

#for Om, dc in [(xi,yj) for xi in AllOm for yj in delta_h]:
    #print x, y
    print(Om_a, H0_a, ns_a, sigma8_a, delta_a)
    print '-----------------'
# Standard Cosmology
    #HaloMF = MassFunction(cosmo_model = cosmo.WMAP5)   
    #my_cosmo = cosmo.Cosmology(cosmo_model=cosmo.WMAP5)

# Custom cosmology
    #new_model = LambdaCDM(H0 = 75.0, Om0= 0.4, Tcmb0 = 2.7, Ob0 = 0.3, Ode0=0.4)
    new_model = LambdaCDM(H0 = H0_a, Om0= Om_a, Tcmb0 = 2.7, Ob0 = 0.1, Ode0=1-Om_a)
    HaloMF = MassFunction(cosmo_model = new_model, delta_h = delta_a, sigma_8 = sigma8_a)
    HaloMF.update(n = ns_a)  
    my_cosmo = cosmo.Cosmology(cosmo_model = new_model)



				k = np.logspace(np.log(1e-3), np.log(5), 100)
    delta_k = 
    sigma_8 = 0.8
    z = 0.0
				hmf.halofit.halofit(k, delta_k, sigma_8, z, cosmo=None, takahashi=True)

    print HaloMF.parameter_values    # Check for parameters properly

    cumulative_mass_func = HaloMF.ngtm
    xxy =  np.hstack( [Om_a, H0_a, ns_a, sigma8_a, delta_a , cumulative_mass_func[::10]] )
예제 #9
0
deltas = Delta_cr / Omz

cosmo_model = FlatLambdaCDM(H0=H0, Om0=Om0, Tcmb0=Tcmb0, Ob0=0.046)

hmf = MassFunction(Mmax=15.72,
                   Mmin=5.,
                   cosmo_model=cosmo_model,
                   hmf_model='Tinker10',
                   delta_wrt='mean',
                   delta_h=200.,
                   sigma_8=0.82,
                   n=0.96)

i = 0
for i in range(len(zs) - 1):
    hmf.update(z=zs[i], delta_h=deltas[i])

    mass_func = hmf.dndm

    #    outfile1='hmf_dndm_z'+str(zs[i])+'_200.txt'
    outfile1 = 'hmf_dndm_z' + str(zs[i]) + '.txt'
    dndmfile = open(outfile1, 'w')
    #    outfile2='hmf_pspec_z'+str(zs[i])+'_200.txt'
    outfile2 = 'hmf_pspec_z' + str(zs[i]) + '.txt'
    pspecfile = open(outfile2, 'w')

    for i in range(0, len(hmf.m) - 1):
        dndmfile.write(
            str(hmf.m[i]) + '  ' + str(hmf.sigma[i]) + '  ' +
            str(hmf.fsigma[i]) + '  ' + str(hmf.dndm[i]) + '\n')
예제 #10
0
        ## Meff  = np.array(Meff) / ns
        
        pl.loglog(Ms[:-1], ns, label=label)
    '''
    ## Load Martin's results.
    data = np.loadtxt('../dat/massfn_st_0.2000.dat')
    pl.loglog(data[:,0], data[:,1], label='Martin-ST')

    data = np.loadtxt('../dat/massfn_tin_0.2000.dat')
    pl.loglog(data[:,0], data[:,1], label='Martin-Tinker')
    
    ##  Murray et al. hmf python code. 
    mf   = MassFunction()

    for label, fitting, color in zip(['ST', 'Tinker'], [hmf.fitting_functions.ST, hmf.fitting_functions.Tinker08], ['c', 'r']):
        mf.update(z = 4.0, Mmin = 8., Mmax = np.log10(5.e14), cosmo_params = {'Om0': 0.30841}, hmf_model = fitting, delta_h = 200.)

        print(mf.parameter_values)
        print(mf.parameter_info())

        pl.loglog(mf.m, mf.ngtm, label='py-hmf: ' + label, c=color, alpha=0.6)


    ## Axis labels.
    ax   = pl.gca()

    ax.set_xlabel(r'$M_{\rm{min}} \ [M_\odot / h]$')
    ax.set_ylabel(r'$\bar n \ [(h^{-1} \ \rm{Mpc})^{-3}]$')

    pl.ylim(1.e-10, 1.e2)
예제 #11
0
    plt.axis([6, 11.5, 1e-6, 5e0])

    leg = plt.legend(loc='upper right', numpoints=1, labelspacing=0.1)
    leg.draw_frame(False)  # Don't want a box frame
    for t in leg.get_texts():  # Reduce the size of the text
        t.set_fontsize(PlotScripts.global_legendsize)

    outputFile = "hmf_z{0:.2f}.png".format(z)
    #plt.savefig(outputFile, bbox_inches='tight')  # Save the figure
    #print('Saved file to {0}'.format(outputFile))
    #plt.close()

if __name__ == '__main__':

    PlotScripts.Set_Params_Plot()
    filepath = '/lustre/projects/p004_swin/bsmith/1.6Gpc/means/halo_1721673/dm_gadget/data/'

    cosmol = AllVars.Set_Params_Britton(
    )  # Set the parameters for Britton's model.
    my_cosmo = cosmo.Cosmology(cosmo_model=cosmol)  # Update the hmf cosmology.
    britton_cosmo = FlatLambdaCDM(H0=69.5, Om0=0.285, Ob0=0.04845)
    hmf = MassFunction()
    hmf.update(cosmo_params={"H0": 69.5, "Om0": 0.285}, Mmax=11, Mmin=6)

    for snapshot_idx in range(snaplow, snaphigh + 1):
        #plot_snapshot(filepath, snapshot_idx, 0, 0)
        #plot_density_grid(filepath, snapshot_idx, 128)
        #plot_halos(filepath, snapshot_idx)
        #check_bounds(filepath, snapshot_idx)
        plot_hmf(filepath, snapshot_idx, hmf)