Exemplo n.º 1
0
def mass_to_avg_bias(m, zs, dndz):

    bh = bias.haloBias(M=m, z=zs, mdef='200c', model='tinker10')

    avg_bh = np.average(bh, weights=dndz)

    return avg_bh
Exemplo n.º 2
0
def bias_to_mass(inputbias, z):
    masses = np.logspace(10, 14, 1000)
    biases_from_masses = bias.haloBias(M=masses,
                                       z=z,
                                       mdef='200c',
                                       model='tinker10')
    return np.interp(inputbias, biases_from_masses, masses)
Exemplo n.º 3
0
def get_hbs(model, mdef):
    m_arr = np.geomspace(1E11, 1E15, 9)
    z_arr = np.array([0., 0.5, 1.])
    d_out = []
    d_out.append(m_arr)
    normfac = h**3 * np.log(10)
    for z in z_arr:
        d_out.append(bias.haloBias(m_arr * h, z=z, mdef=mdef, model=model))
    np.savetxt("../hbf_" + model + ".txt",
               np.transpose(d_out),
               header='M bh(z=0) bh(z=0.5) bh(z=1)')
Exemplo n.º 4
0
def get_dndm_bias(M_mat, z_array, mdef):

    dndm_array_Mz, bm_array_Mz = np.zeros(M_mat.shape), np.zeros(M_mat.shape)

    for j in range(len(z_array)):
        M_array = M_mat[j, :]
        dndm_array_Mz[j, :] = (1. / M_array) * mass_function.massFunction(
            M_array, z_array[j], mdef=mdef, model=dndm_model, q_out='dndlnM')

        bm_array_Mz[j, :] = bias.haloBias(M_array,
                                          z_array[j],
                                          model=bias_model,
                                          mdef=mdef)

    return dndm_array_Mz, bm_array_Mz
Exemplo n.º 5
0
peak_array = (peak_bins[:-1] + peak_bins[1:]) / 2.

h = cosmo.Hz(z=0) / 100
dc0 = peaks.collapseOverdensity(z=0)

M = np.logspace(12, 15, 100)
z = np.array([0.0, 0.1, 0.2, 0.4, 0.6, 0.8, 1.0])

Mdefs = ['200c', '500c']
for Mdef in Mdefs:
    print(Mdef)
    outfig = os.path.join('/home/rseppi/HMF_seppi20', 'figures',
                          'bias_' + Mdef + '.png')
    plt.figure(figsize=(6, 6))

    for z_ in z:
        b = bias.haloBias(M, model='tinker10', z=z_, mdef=Mdef)
        plt.plot(M, b, label='z={:.1f}'.format(z_))

    plt.xlabel(r'M' + Mdef + ' [M$_\odot$/h]', fontsize=13)
    plt.ylabel('b', fontsize=13)
    plt.xscale('log')
    plt.ylim(0, 6)
    plt.legend(fontsize=13)
    plt.tick_params(labelsize=13)
    plt.grid(True)
    plt.tight_layout()
    plt.savefig(outfig)

print('done!')
Exemplo n.º 6
0
 def bias_dm(self, m,z):
     #b = bias.haloBias(m/p.small_h, model = model, z = z, mdef = mdef)
 
     b = bias.haloBias(m,  z=z, model='tinker10', mdef=self.halo_model_mdef)
     return b
    # Write cosmological parameters to file.
    outputFile.write("# OmegaMatter = " + str(cosmo.Om0) + "\n")
    outputFile.write("# OmegaDarkEnergy = " + str(cosmo.Ode0) + "\n")
    outputFile.write("# OmegaBaryon = " + str(cosmo.Ob0) + "\n")
    outputFile.write("# HubbleConstant = " + str(cosmo.H0) + "\n")
    outputFile.write("# sigma_8 = " + str(cosmo.sigma8) + "\n")
    outputFile.write("# index = " + str(cosmo.ns) + "\n")
    outputFile.write("# temperatureCMB = " + str(cosmo.Tcmb0) + "\n")
    outputFile.write("# effectiveNumberNeutrinos = " + str(cosmo.Neff) + "\n")

    # Write bias parameters to file.
    outputFile.write("# biasModel = " + str(model[0]) + "\n")
    outputFile.write("# virialDensityContrast = " + str(model[1]) + "\n")

    # Output bias.
    outputFile.write("#\n")
    outputFile.write("# mass\t\tredshift\tbias\n")

    # Iterate over redshifts.
    for redshift in redshifts:

        # Construct the list of concentrations.
        b = bias.haloBias(mass, model=model[0], z=redshift, mdef=model[1])

        for x in zip(mass, b):
            outputFile.write("%12.6e\t%3.1f\t\t%9.6f\n" %
                             (x[0], redshift, x[1]))

    outputFile.close()
Exemplo n.º 8
0
def galaxybias(logM):
    Mh = 10.0**logM
    bs = bias.haloBias(Mh, model='tinker10', z=zl, mdef='vir')
    return bs
Exemplo n.º 9
0
def DStheo(theta, args):
    """
    Computes de theoretical :math:`\Delta\Sigma_{NFW}` profile for a given mass
    :math:`m_{200}`, z and cosmology.

    Parameters
    ----------
    theta: tuple
        Parameters for the mcmc
    args: dict
        Contains the cosmology and other mean values computed from the data

    Returns
    -------
    ds: np.array
        The thoretical :math:`\Delta\Sigma_{NFW}` profile

    Notes
    -----
    The parameters for the NFW function are the mass :math:`m_{200}` and the
    concentration :math:`c_{200}`. However, in this anlysis, we use the
    Duffy et al. (2008) concetration-mass relation to get the profile only
    as a function of the mass. See: https://github.com/joergdietrich/NFW for
    more details on the NFW function.
    """
    runtype = args['runtype']
    runconfig = args['runconfig']

    if runtype == 'data':
        if runconfig == 'Full':
            m200, pcc, Am, B0, Rs = theta  #M200c [Msun]
        elif runconfig == 'OnlyM':
            m200 = theta[0]
        elif runconfig == 'FixAm':
            m200, pcc, B0, Rs = theta
    elif runtype == 'cal':
        m200 = theta[0]
    elif runtype == 'calsys':
        if runconfig == 'Full':
            m200, pcc, Am, B0, Rs = theta  #M200c [Msun]

    h = args['h']
    z_mean = args['z_mean']
    R = args['R']  #in physical [Mpc]
    cosmo = args['cosmo']  #astropy cosmology object
    cmodel = args[
        'cmodel']  #diemer18 (obs.: lastest version of Colossus renamed to diemer19)
    twohalo = args['twohalo']
    factor2h = args['factor2h']  #boolean, if True multiply 2-halo term by h
    cosmodict = args['cosmodict']
    omega_m = cosmodict['om']
    sigma_crit_inv = args['Sigma_crit_inv']

    #Setting up the cosmology for Colossus
    params = {
        'flat': True,
        'H0': cosmodict['h'] * 100.,
        'Om0': cosmodict['om'],
        'Ob0': cosmodict['ob'],
        'sigma8': cosmodict['sigma8'],
        'ns': cosmodict['ns']
    }
    cosmology.addCosmology('myCosmo', params)
    cosmoc = cosmology.setCosmology('myCosmo')
    cmodel = cmodel

    c200c = concentration.concentration(
        m200 * h, '200c', z_mean, model=cmodel,
        conversion_profile='nfw')  #m200c_in is [Msun/h], m200c_out is [Msun/h]
    nfw = NFW(m200,
              c200c,
              z_mean,
              cosmology=cosmo,
              overdensity_type='critical')  #input mass should be in [Msun]

    #For DeltaSigma calculation, data and sim, the radius has to be in physical [Mpc]
    if runtype == 'cal':
        ds = (nfw.delta_sigma(R).value
              ) / 1.e12  #DeltaSigma is in units of physical [M_sun/Mpc^2]
        #This two-halo part was not used in the analysis, the compuation is too slow
        if twohalo:
            #Adding the 2-halo term
            b = bias.haloBias(m200 * h, z_mean, '200c',
                              model='tinker10')  #mass_in is [Msun/h]
            outer_term_xi = profile_outer.OuterTermCorrelationFunction(
                z=z_mean, bias=b)
            p_nfw = profile_nfw.NFWProfile(
                M=m200 * h,
                c=c200c,
                z=z_mean,
                mdef='200c',
                outer_terms=[outer_term_xi])  #mass_in is [Msun/h]

            #Radius in physical kpc/h
            two_nfw0 = p_nfw.deltaSigmaOuter((R * 1e3) * h,
                                             interpolate=True,
                                             interpolate_surface_density=False,
                                             min_r_interpolate=1.e-6 * h,
                                             max_r_integrate=2.e5 * h,
                                             max_r_interpolate=2.e5 * h)
            two_nfw1 = two_nfw0 / 1.e6  #in physical [h Msun/pc^2]

            if factor2h:
                two_nfw = h * (two_nfw1 * h
                               )  #something like physical [Msun/(h pc^2)]
            else:
                two_nfw = (
                    two_nfw1 * h
                )  #in physical [Msun/pc^2] #This should be the right one

            ds_model = ds + two_nfw  #NFW + 2-halo in physical [Msun/pc^2] if factor2h=False
        else:
            ds_model = ds
        return ds_model  #physical [M_sun/pc^2]

    if runtype == 'data' or runtype == 'calsys':

        ds = (
            nfw.delta_sigma(R).value
        ) / 1.e12  #units of h Msun/pc^2 physical (but h=1, so actually is M_sun/pc^2)
        sigma = (nfw.sigma(R).value) / 1.e12

        # Computing miscetering correction from data
        m200p = m200
        z = np.array([z_mean])

        if runtype == 'data':
            cluster = ClusterEnsemble(z,
                                      cosmology=FlatLambdaCDM(H0=100, Om0=0.3),
                                      cm='Diemer18',
                                      cmval=c200c)
            misc_off = 0.1326  #here in [Mpc], since h=1

        elif runtype == 'calsys':
            cluster = ClusterEnsemble(z,
                                      cosmology=FlatLambdaCDM(H0=h * 100,
                                                              Om0=omega_m),
                                      cm='Diemer18',
                                      cmval=c200c)
            misc_off = 0.1326 / h  #input needs to be in units of [Mpc]

        if np.shape(m200p) == (1, 1):
            m200p = np.reshape(m200p, (1, ))
        try:
            cluster.m200 = m200p  #M200c [Msun]
        except TypeError:
            cluster.m200 = np.array([m200p])

        rbins = R  # in physical [Mpc]

        offsets = np.ones(cluster.z.shape[0]) * misc_off
        cluster.calc_nfw(rbins, offsets=offsets)  #NFW with offset

        dsigma_offset = cluster.deltasigma_nfw.mean(
            axis=0)  #physical [M_sun/pc^2], but if h=1 is [h M_sun/pc**2]
        DSmisc = dsigma_offset.value  #physical [Msun/pc^2]

        sigma_offset = cluster.sigma_nfw.mean(
            axis=0)  #physical [M_sun/pc**2], but if h=1 is [h M_sun/pc**2]
        Smisc = sigma_offset.value  #physical [Msun/pc^2]

        if runconfig == 'OnlyM':
            pcc = 0.75
            B0 = 0.50
            Rs = 2.00

        #The final model
        full_Sigma = pcc * sigma + (1 - pcc) * Smisc

        full_model = pcc * ds + (1 - pcc) * DSmisc

        if runconfig == 'Full':
            full_model *= Am  #shear+photo-z bias correction
        elif runconfig == 'OnlyM' or 'FixAm':
            full_model = full_model

        #Note: R (rbins) and Rs are in physical [Mpc], need to be comoving [Mpc/h]
        boost_model = ct.boostfactors.boost_nfw_at_R(rbins * h * (1 + z_mean),
                                                     B0, Rs * h * (1 + z_mean))

        full_model /= boost_model  #boost-factor

        full_model /= (1 - full_Sigma * sigma_crit_inv)  #Reduced shear

        return full_model  # in physical [M_sun/pc^2]
Exemplo n.º 10
0
def bias(mvir,z,mode='tinker10',mdef='200m'):
    return col_bias.haloBias(mvir, model = 'tinker10', z = z,mdef=mdef)