Пример #1
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
Пример #2
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]] )

    y = np.vstack( (y, xxy) )
Пример #3
0
def main():

    # set cosmology and linear power spectrum
    '''
    H0=70.0
    Omega_M=0.279000
    Omega_b=0.046100
    w0=-1.000000
    Omega_k=0.000000
    n_s=0.972000
    inputPk="../input_pk/wmap9_fid_matterpower_z0.dat"
    nH = 2.4e21
    opt = 1
    '''
    H0 = 67.32117
    Omega_M = 0.3158
    Omega_b = 0.0490
    w0 = -1.000000
    Omega_k = 0.000000
    n_s = 0.96605
    inputPk = "../input_pk/planck_2018_test_matterpower.dat"
    nH = 2.4e21
    opt = 1

    xx_power.init_cosmology(H0, Omega_M, Omega_b, w0, Omega_k, n_s, nH,
                            inputPk, opt)

    shot_noise = 0.00

    ell = 10.**np.linspace(np.log10(10.), np.log10(3.e4), 31)

    theta_fid = [
        4.0, 3.e-5, 0.0800, 0.120000, 1.000000, 0.180000, 0.800000, 0.500000,
        0.10000, 1.720000, 0.195000, 0.010000, 0.800000, 0.9, 1.0, 6.0, 3.0
    ]

    param_ind_dict = {
        'eps_f': 0,
        'eps_DM': 1,
        'f_star': 2,
        'S_star': 3,
        'A_C': 4,
        'alpha_nt': 5,
        'n_nt': 6,
        'beta_nt': 7,
        'gamma_mod0': 8,
        'gamma_mod_zslope': 9,
        'x_break': 10,
        'x_smooth': 11,
        'n_nt_mod': 12,
        'clump0': 13,
        'clump_zslope': 14,
        'x_clump': 15,
        'alpha_clump1': 16,
    }

    param_label_dict = {
        'eps_f': r'$\epsilon_f/10^{-6}$',
        'eps_DM': r'$\epsilon_{DM}$',
        'f_star': r'$f_\star$',
        'S_star': r'$S_\star$',
        'A_C': r'$A_C$',
        'alpha_nt': r'$\alpha_{nt}$',
        'n_nt': r'$n_{nt}$',
        'beta_nt': r'$\beta_{nt}$',
        'gamma_mod0': r'$\Gamma_0$',
        'gamma_mod_zslope': r'$\beta_\Gamma$',
        'n_nt_mod': '$n_{nt,mod}$',
        'clump0': r'$C_0$',
        'clump_zslope': r'$\beta_C$',
        'x_clump': r'$x_{C}$',
        'alpha_clump1': r'$\alpha_{C1}$',
        'alpha_clump2': r'$\alpha_{C2}$'
    }

    #rosat_ell, rosat_cl, rosat_var = read_data("../ROSAT/rosat_R4_R7_mask_hfi_R2_small_ell.txt")
    #rosat_cl *= rosat_ell*(rosat_ell+1.)/(2.0*math.pi)
    #rosat_cl_err = np.sqrt(rosat_var)*rosat_ell*(rosat_ell+1.)/(2.0*math.pi)

    #params = ['eps_f', 'f_star', 'S_star', 'alpha_nt', 'n_nt', 'beta_nt', 'gamma_mod0', 'gamma_mod_zslope', 'clump0', 'clump_zslope', 'x_clump', 'alpha_clump1', 'alpha_clump2' ]
    params = ['eps_f', 'f_star', 'clump0']

    redshift, dlz = np.linspace(-4, np.log10(3.0), 10, retstep=True)

    redshift = 10**redshift

    print(dlz)

    my_cosmo = cosmo.Cosmology()
    hubble = my_cosmo.cosmo.h
    print(hubble)

    mvir, dlm = np.linspace(13, 16, 20, retstep=True)
    flux, dlf = np.linspace(-20, -10, 20, retstep=True)

    mvir = 10**mvir
    flux = 10**flux

    Nsperster = np.zeros(flux.shape)

    redo = False

    if redo:
        for iv, f in enumerate(flux):
            for iz, z in enumerate(redshift):
                dVdz = my_cosmo.cosmo.differential_comoving_volume(
                    z).value * hubble**3
                s = []
                for mass in mvir:
                    ff, m500 = xray_flux(mass, z, theta_fid)
                    s.append(ff)
                s = np.array(s)
                mlim = np.interp(f, s, mvir)

                #h = hmf.MassFunction(z=z, Mmin=13, Mmax=16, dlog10m=0.1)
                h = hmf.MassFunction(z=z)

                Nm = 0.0
                for im, mass in enumerate(h.m):
                    if mass >= mlim:
                        Nm += h.dlog10m * h.dndlog10m[im] * dVdz * z * dlz
                Nsperster[iv] += Nm

        np.save("logNlogS.npy", Nsperster)

    surveys = ["CDFS", "COSMOS", "XXL", "S82", "RASS"]
    areas = [0.25, 2.0, 50.0, 31.0, 4.0 * 3.141592 * ster2sqdeg * 0.25]
    sens = [0.66e-15, 1.7e-15, 5e-15, 0.87e-15, 5.6e-13]

    fig = plt.figure(figsize=(4, 4))
    ax = fig.add_axes([0.21, 0.16, 0.75, 0.75])

    print(areas, sens)
    ax.scatter(areas, sens, s=1.0, marker='o')

    for i, txt in enumerate(surveys):
        ax.annotate(txt, (areas[i], sens[i]))

    ax.set_xlabel(r'Area [deg$^2$]')
    ax.set_ylabel(r'flux [erg/s/cm$^2$]')

    ax.set_xscale('log')
    ax.set_yscale('log')
    #ax.set_xlim(1e-2, 1e5 )
    #ax.set_ylim(1e-16, 1e-12)

    #ax.legend(loc='best')

    plt.show()

    fig.savefig("wedding_test.png")
    fig.clf()
Пример #4
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)