Пример #1
0
def smhm(model, values, cosmo=cosmo, mdef='200c', z=0, sigma_h=0.15):
    """Joint prior from the stellar mass--halo mass relation.
    Modeled as a log-normal around the predicted stellar mass from fixed halo mass.
    Currently, the redshift dependent model of Rodriguez-Puebla is implemented.

    Parameters
    ----------
    model : DynamicalModel instance
    values : array_like
         values in parameter space at which to evaluate the prior
    cosmo : colossus.Cosmology instance
    mdef : string
        Colossus mass definition string for input halo parameters
        e.g., 'vir', '200m', '200c'
    z : float
        redshift
    """
    h = cosmo.h
    kwargs = model.construct_kwargs(values)
    if 'M200' in kwargs and 'c200' in kwargs:
        # should be '200c' def
        assert mdef == '200c'
        M200 = kwargs['M200']
        c200 = kwargs['c200']
        # colossus assumes halo masses are in Msun / h
        Mvir, rvir, cvir = mass_defs.changeMassDefinition(M200 * h,
                                                          c200,
                                                          z,
                                                          mdef_in=mdef,
                                                          mdef_out='vir')
        # convert back to Msun (no h scaling)
        Mvir = Mvir / h
    else:
        rho_crit = cosmo.rho_c(z) * h**2  # Msun / kpc3
        delta_c = mass_so.deltaVir(z)
        Mh_function = lambda r: model.mass_model['dm'](r, **kwargs)
        try:
            rvir = mass._rvir(Mh_function,
                              rhigh=1e8,
                              delta_c=delta_c,
                              rho_crit=rho_crit)
        except ValueError:
            # meh, approximate with M200 value
            rvir = (3 * kwargs['M200'] / (4 * np.pi * 200 * rho_crit))**(1 / 3)
        Mvir = Mh_function(rvir)
    Mst = model.mass_model['st'](np.inf, **kwargs)
    if sigma_h == 'variable':
        # use the relation from Munchi+2017
        gamma = -0.26
        sigma_flat = 0.2
        logM1 = 11.5  # median value from Moster+2013
        logMvir = np.log10(Mvir)
        if logMvir < logM1:
            sigma_h = sigma_flat + gamma * (logMvir - logM1)
        else:
            sigma_h = sigma_flat
    return _ln_pdf_rp(Mvir, Mst, z=z, sigma_h=sigma_h)
Пример #2
0
def calc_stat(mass, redshift, mass_definition="200m"):
    if mass_definition == "200m":
        M200m = mass
        c200m = concentration.concentration(M200m, mass_definition, redshift)
        M500c, R500c, c500c = changeMassDefinition(M200m,
                                                   c200m,
                                                   redshift,
                                                   '200m',
                                                   '500c',
                                                   profile='nfw')
    elif mass_definition == "500c":
        M500c = mass
        c500c = concentration.concentration(M500c, '500c', redshift)
        M200m, R200m, c200m = changeMassDefinition(M500c, c500c, redshift,
                                                   '500c', '200m')

    Rsp = sb.splashbackRadius(redshift, '200m', M=M200m)[0] * (1 + redshift)
    return M200m, M500c, R200m, Rsp
Пример #3
0
def convert_mass(m, z, mdef_in='200c', mdef_out='200m',
                 concentration_model='diemer19', profile='nfw'):
    '''
    Converts between mass definitions.
    '''
    c = concentration.concentration(m, mdef_in, z,
                                    model=concentration_model,
                                    conversion_profile=profile)
    return mass_defs.changeMassDefinition(m, c, z, mdef_in, mdef_out,
                                          profile=profile)[0]
Пример #4
0
 def r50(self, t):
     # Rdisk using formula from Mo, Mao & White 1998
     Mhh = self.Mh * self.cosmo.h
     cvir = concentration(Mhh, 'vir', self.z, model='diemer15')
     M200c, R200c, c200c = changeMassDefinition(Mhh, cvir, self.z, 'vir',
                                                '200c')
     md = self.Ms / (M200c / self.cosmo.h)
     jmlam = self.etar * 0.045  # assume etar fraction of the angular momentum lost
     eta50 = self.eta50_MMW98(c200c, jmlam, md)
     r_50 = eta50 * R200c / self.cosmo.h
     return r_50
Пример #5
0
def test_mean_to_vir_nfw():
    mdef = md.SOMean(Planck15, z=0)
    mdef2 = md.SOVirial(Planck15, z=0)

    cduffy = mdef._duffy_concentration(1e12)

    mnew, rnew, cnew = mdef.change_definition(1e12, mdef2)
    mnew_, rnew_, cnew_ = changeMassDefinition(1e12, cduffy, 0, "200m", "vir",
                                               "nfw")

    assert np.isclose(mnew, mnew_, 1e-2)
    assert np.isclose(rnew * 1e3, rnew_, 1e-2)
    assert np.isclose(cnew, cnew_, 1e-2)
Пример #6
0
def test_mean_to_crit_z1_nfw():
    mdef = md.SOMean(Planck15, z=1, overdensity=200)
    mdef2 = md.SOCritical(Planck15, z=1, overdensity=300)

    cduffy = mdef._duffy_concentration(1e12)

    mnew, rnew, cnew = mdef.change_definition(1e12, mdef2)
    mnew_, rnew_, cnew_ = changeMassDefinition(1e12, cduffy, 1, "200m", "300c",
                                               "nfw")

    assert np.isclose(mnew, mnew_, 1e-2)
    assert np.isclose(rnew * 1e3, rnew_, 1e-2)
    assert np.isclose(cnew, cnew_, 1e-2)
Пример #7
0
def test_mean_to_crit_nfw(colossus_cosmo):
    mdef = md.SOMean(overdensity=200)
    mdef2 = md.SOCritical(overdensity=300)

    cduffy = mdef._duffy_concentration(1e12)

    mnew, rnew, cnew = mdef.change_definition(1e12, mdef2)
    mnew_, rnew_, cnew_ = changeMassDefinition(1e12, cduffy, 0, "200m", "300c",
                                               "nfw")

    assert np.isclose(mnew, mnew_, rtol=1e-2)
    assert np.isclose(rnew * 1e3, rnew_, rtol=1e-2)
    assert np.isclose(cnew, cnew_, rtol=1e-2)
Пример #8
0
def M200(Lambda,z):
     
     M0    = 2.21e14
     alpha = 1.33
     M200m = M0*((Lambda/40.)**alpha)
     
     from colossus.cosmology import cosmology
     from colossus.halo import mass_defs
     from colossus.halo import concentration
     
     c200m = concentration.concentration(M200m, '200m', z, model = 'duffy08')
     M200c, R200c, c200c = mass_defs.changeMassDefinition(M200m, c200m, z, '200m', '200c')
     
     return M200c
Пример #9
0
def test_mean_to_vir_nfw(colossus_cosmo):
    mdef = md.SOMean()
    mdef2 = md.SOVirial()

    cduffy = mdef._duffy_concentration(1e12)

    mnew, rnew, cnew = mdef.change_definition(1e12, mdef2)
    mnew_, rnew_, cnew_ = changeMassDefinition(1e12, cduffy, 0, "200m", "vir",
                                               "nfw")

    print(mnew, mnew_)

    assert np.isclose(mnew, mnew_, rtol=1e-2)
    assert np.isclose(rnew * 1e3, rnew_, rtol=1e-2)
    assert np.isclose(cnew, cnew_, rtol=1e-2)
Пример #10
0
def cNFW(m,z=0,virial=False,method='d15', wdm=False,mWDM=5.,massdef=None):
    """
    Returns the NFW concentration, calculated according to the given mass concentration relation 'method'.
    Written to use the versions from COLOSSUS by Diemer+ 2017, but can use versions I coded up by uncommenting them.
    Supports WDM concentrations as given by Schneider+ 2012's relation, given mWDM in keV.
    https://bdiemer.bitbucket.io/colossus/halo_concentration.html
    """

    if massdef==None:  massdef = 'vir' if virial else '200c'
    h0 = h(0,method=method)

    if   method=='d08':
        #return duffy08 (m,z=z,virial=virial)
        cosmology.setCurrent(cosmoWMAP5)
        c = colossus_cNFW(m/h0, massdef, z, model='duffy08')
    elif method=='d14':
        #return dutton14(m,z=z,virial=virial)
        cosmology.setCurrent(cosmoP13)
        c = colossus_cNFW(m/h0, massdef, z, model='dutton14')
    elif method=='d15': # Diemer & Joyce 2019
        cosmology.setCurrent(cosmoP18)
        #cosmology.setCurrent(cosmoWMAP5)
        c = colossus_cNFW(m/h0, massdef, z, model='diemer15')

    elif method=='d15+1s': # Diemer & Joyce 2019
        cosmology.setCurrent(cosmoP18)
        c = colossus_cNFW(m/h0, massdef, z, model='diemer15') * 10**0.16
    elif method=='d15-1s': # Diemer & Joyce 2019
        cosmology.setCurrent(cosmoP18)
        c = colossus_cNFW(m/h0, massdef, z, model='diemer15') / 10**0.16
    elif method=='d15-wmap':
        cosmology.setCurrent(cosmoWMAP5)
        c = colossus_cNFW(m/h0, massdef, z, model='diemer15')

    else:
        print('did not recognize given mass-concentration relation',relation,'!  Aborting...')
        exit()

    if not wdm:
        return c
    else:
        m1m_div_h, r1m_div_h, c1m = changeMassDefinition(m/h0, c, z, '200c', '1m')  # Schneider+ 2012 uses rho_bar in mass def
        m1m = m1m_div_h * h0
        return c * (1 + GAMMA1*mass_hm(mWDM,cNFW_method=method)/m1m)**(-GAMMA2)  # Schneider+ 2012
Пример #11
0
def mass_conversion(m200m, redshift, cosmology, mass_is_log=True):
    """Convert m200m to m500c

    Parameters
    ----------
    m200m : array_like
        Halo mass(es) calculated in a radius such that the mean density is 200 times
        the mean density of the universe.
    redshift : float
        Redshift of the halos used to calculate the concentration and perform
        the mass conversion
    cosmology : dict
        Cosmology parameters being used
    mass_is_log : bool
        Flag to tell the script if it should intake and output ln(M) or M

    Returns
    -------
    output : array_like
        Halo mass(es) calculated in a radius such that the mean density is 500 times
        the critical density of the universe.

    Notes
    -----
    We assume that every halo is at the same redshift.
    """
    setCosmology('myCosmo', cosmology)

    if mass_is_log:
        m200m = np.exp(m200m)

    m500c = changeMassDefinition(m200m, concentration(m200m, '200m', redshift),
                                 redshift, '200m', '500c')[0]

    if mass_is_log:
        m500c = np.log(m500c)

    return m500c
Пример #12
0
def cmb_test_data(nber_maps,
                  validation_analyis=False,
                  clus_position_analysis=False,
                  extragal_bias_analysis=False):
    nx, dx, ny, dy = 240, 0.25, 240, 0.25
    map_params = [nx, dx, ny, dy]
    l, cl = CosmoCalc().cmb_power_spectrum()
    l, bl = exp.beam_power_spectrum(1.4)
    l, nl = exp.white_noise_power_spectrum(2.0)

    if validation_analyis is True:
        sims_clus_2e14, sims_clus_6e14, sims_clus_10e14 = [], [], []
        kappa_map_2e14 = lensing.NFW(2e14, 3, 1,
                                     1100).convergence_map(map_params)
        kappa_map_6e14 = lensing.NFW(6e14, 3, 1,
                                     1100).convergence_map(map_params)
        kappa_map_10e14 = lensing.NFW(10e14, 3, 1,
                                      1100).convergence_map(map_params)
        alpha_vec_2e14 = lensing.deflection_from_convergence(
            map_params, kappa_map_2e14)
        alpha_vec_6e14 = lensing.deflection_from_convergence(
            map_params, kappa_map_6e14)
        alpha_vec_10e14 = lensing.deflection_from_convergence(
            map_params, kappa_map_10e14)
        for i in range(nber_maps):
            sim = tools.make_gaussian_realization(map_params, l, cl)
            sim_clus_2e14 = lensing.lens_map(map_params, sim, alpha_vec_2e14)
            sim_clus_6e14 = lensing.lens_map(map_params, sim, alpha_vec_6e14)
            sim_clus_10e14 = lensing.lens_map(map_params, sim, alpha_vec_10e14)
            sim_clus_2e14 = tools.convolve(sim_clus_2e14,
                                           l,
                                           np.sqrt(bl),
                                           map_params=map_params)
            sim_clus_6e14 = tools.convolve(sim_clus_6e14,
                                           l,
                                           np.sqrt(bl),
                                           map_params=map_params)
            sim_clus_10e14 = tools.convolve(sim_clus_10e14,
                                            l,
                                            np.sqrt(bl),
                                            map_params=map_params)
            noise_map = tools.make_gaussian_realization(map_params, l, nl)
            sim_clus_2e14 += noise_map
            sim_clus_6e14 += noise_map
            sim_clus_10e14 += noise_map
            sims_clus_2e14.append(sim_clus_2e14)
            sims_clus_6e14.append(sim_clus_6e14)
            sims_clus_10e14.append(sim_clus_10e14)
        return sims_clus_2e14, sims_clus_6e14, sims_clus_10e14

    if clus_position_analysis is True:
        sims_baseline, sims_centorid_shift = [], []
        kappa_map_6e14_baseline = lensing.NFW(2e14, 3, 1,
                                              1100).convergence_map(map_params)
        alpha_vec_6e14_baseline = lensing.deflection_from_convergence(
            map_params, kappa_map_6e14_baseline)
        for i in range(nber_maps):
            x_shift, y_shift = np.random.normal(
                loc=0.0, scale=0.5), np.random.normal(loc=0.0, scale=0.5)
            centroid_shift = [x_shift, y_shift]
            kappa_map_6e14_centroid_shift = lensing.NFW(
                6e14, 3, 1, 1100).convergence_map(map_params, centroid_shift)
            alpha_vec_6e14_centroid_shift = lensing.deflection_from_convergence(
                map_params, kappa_map_6e14_centroid_shift)
            sim = tools.make_gaussian_realization(map_params, l, cl)
            sim_baseline = lensing.lens_map(map_params, sim,
                                            alpha_vec_6e14_baseline)
            sim_centroid_shift = lensing.lens_map(
                map_params, sim, alpha_vec_6e14_centroid_shift)
            sim_baseline = tools.convolve(sim_baseline,
                                          l,
                                          np.sqrt(bl),
                                          map_params=map_params)
            sim_centroid_shift = tools.convolve(sim_centroid_shift,
                                                l,
                                                np.sqrt(bl),
                                                map_params=map_params)
            noise_map = tools.make_gaussian_realization(map_params, l, nl)
            sim_baseline += noise_map
            sim_centroid_shift += noise_map
            sims_baseline.append(sim_baseline)
            sims_centroid_shift.append(sim_centroid_shift)
        return sims_baseline, sims_centroid_shift

    if extragal_bias_analysis is True:
        sims_baseline, sims_tsz, sims_ksz, sims_tsz_ksz = [], [], [], []
        c500 = concentration.concentration(2e14, '500c', 0.7)
        M200c, _, c200c = mass_defs.changeMassDefinition(2e14,
                                                         c500,
                                                         0.7,
                                                         '500c',
                                                         '200c',
                                                         profile='nfw')
        kappa_map_M200c = lensing.NFW(M200c, c200c, 0.7,
                                      1100).convergence_map(map_params)
        alpha_vec_M200c = lensing.deflection_from_convergence(
            map_params, kappa_map_M200c)
        fname = '/Volumes/Extreme_SSD/codes/master_thesis/code/data/mdpl2_cutouts_for_tszksz_clus_detection_M1.7e+14to2.3e+14_z0.6to0.8_15320haloes_boxsize20.0am.npz'
        cutouts_dic = np.load(fname, allow_pickle=1,
                              encoding='latin1')['arr_0'].item()
        mass_z_key = list(cutouts_dic.keys())[0]
        cutouts = cutouts_dic[mass_z_key]
        scale_fac = fg.compton_y_to_delta_Tcmb(145, uK=True)
        tsz_cutouts, ksz_cutouts = [], []
        for kcntr, keyname in enumerate(cutouts):
            tsz_cutout = cutouts[keyname]['y'] * scale_fac
            tsz_cutouts.append(tsz_cutout)
            ksz_cutout = cutouts[keyname]['ksz'] * random.randrange(-1, 2, 2)
            ksz_cutouts.append(ksz_cutout)
        s, e = int((nx - 40) / 2), int((ny + 40) / 2)
        for i in range(nber_maps):
            sim = tools.make_gaussian_realization(map_params, l, cl)
            sim_M200c = lensing.lens_map(map_params, sim, alpha_vec_M200c)
            sim_baseline, sim_tsz, sim_ksz, sim_tsz_ksz = np.copy(
                sim_M200c), np.copy(sim_M200c), np.copy(sim_M200c), np.copy(
                    sim_M200c)
            tsz_cutout = tools.rotate(
                tsz_cutouts[random.randint(0,
                                           len(tsz_cutouts) - 1)],
                random.randint(-180, 180))
            ksz_cutout = tools.rotate(
                ksz_cutouts[random.randint(0,
                                           len(ksz_cutouts) - 1)],
                random.randint(-180, 180))
            tsz_ksz_cutout = tsz_cutout + ksz_cutout
            sim_tsz[s:e, s:e] = sim_tsz[s:e, s:e] + tsz_cutout
            sim_ksz[s:e, s:e] = sim_ksz[s:e, s:e] + ksz_cutout
            sim_tsz_ksz[s:e, s:e] = sim_tsz_ksz[s:e, s:e] + tsz_ksz_cutout
            sim_baseline = tools.convolve(sim_baseline,
                                          l,
                                          np.sqrt(bl),
                                          map_params=map_params)
            sim_tsz = tools.convolve(sim_tsz,
                                     l,
                                     np.sqrt(bl),
                                     map_params=map_params)
            sim_ksz = tools.convolve(sim_ksz,
                                     l,
                                     np.sqrt(bl),
                                     map_params=map_params)
            sim_tsz_ksz = tools.convolve(sim_tsz_ksz,
                                         l,
                                         np.sqrt(bl),
                                         map_params=map_params)
            noise_map = tools.make_gaussian_realization(map_params, l, nl)
            sim_baseline += noise_map
            sim_tsz += noise_map
            sim_ksz += noise_map
            sim_tsz_ksz += noise_map
            sims_baseline.append(sim_baseline)
            sims_tsz.append(sim_tsz)
            sims_ksz.append(sim_ksz)
            sims_tsz_ksz.append(sim_tsz_ksz)
        return sims_baseline, sims_tsz, sims_ksz, sims_tsz_ksz
# catalog is updated to that of SPT-SZ
if sptsz_sim:
    from astropy.io import fits
    data = fits.open('SPT2500d.fits')
    cluslist = data[1].data
    M500c = cluslist['M500']
    selectedinds = np.where(M500c >0)[0]
    M500list = M500c[selectedinds]*1e14
    zlist = cluslist['redshift'][selectedinds]
    z_L_list = np.ones(len(M500list))*0.7
    M_200_list = np.zeros(len(M500list))
    mdef = '500c'
    mdefout = '200m'
    for i,mm in enumerate(M500list):
        cval = concentration.concentration(mm, mdef, zlist[i])
        Mval, r200val, c200val = mass_defs.changeMassDefinition(mm, cval, zlist[i], mdef, mdefout, profile='nfw')
        M_200_list[i] = Mval
    totalclus = len(M_200_list)
np.random.seed(cmbrandomseedval)
randomseeds = np.unique(np.random.randint(1e6,size= 2 * totalclus))[0:totalclus]

# add tSZ either Arnaud profile, Sehgal simulations, or Takahashi simulations
# to be done -get Arnaud from the for loop as well"
if sehgal_sims:
    tSZ_emission, tSZ_emission_90ghz = cluster_stuff.fn_pick_add_sehgal_sims(M_200_list)
    tSZ_emission = tSZ_emission/1e6
    tSZ_emission_90ghz = tSZ_emission_90ghz/1e6
if takahashi_sims:
    tSZ_emission, tSZ_emission_90ghz = cluster_stuff.fn_add_daisuke_sims(M_200_list,z_L_list)

clra, cldec = 0., 0.
Пример #14
0
def gen_obs(cosmo, beta=beta_def, eta=eta_def):

    mah, redshifts, lbtime, masses = multimah_multiM(zobs, cosmo, Nmah)
    print("Loaded MAH", flush=True)
    zi_snap = np.where(redshifts <= zi)[0][-1] + 1 #first snap over z=6
    t0 = cosmo.age(0) # this way we can easily get proper times using the lookback times from Frank's files

    n_steps = zi_snap
    
    rads = np.logspace(np.log10(0.01),np.log10(N_r200m_mult), Nradii) # y_SZ goes out to 2x R_200m for LOS integration, close to splashback radius

    ds2dt    = np.zeros((n_steps, Nradii))
    sig2tots = np.zeros((n_steps, Nradii))
    sig2nth  = np.zeros((n_steps, Nradii))
    cvirs    = np.zeros(Nmah)
    Rvirs    = np.zeros(Nmah)
    R_2R200ms= np.zeros(Nmah)
    # The values that we will return and column_stack
    YSZv     = np.zeros((Nmah, len(radii_definitions)))
    YSZrv     = np.zeros((Nmah, len(radii_definitions)))
    Tmgasv   = np.zeros((Nmah, len(radii_definitions)))
    Mgasv    = np.zeros((Nmah, len(radii_definitions)))
    mass_enc = np.zeros((Nmah, len(radii_definitions)))

    for mc in range(0,Nmah):
        if(mc % 100 == 0):
            print(mc, flush=True)
        # get cvir so that we can get R500c/R200m
        t04_ind = np.where(mah[mc,:] > 0.04*masses[mc])[0][-1]
        cvir = conc_model(t0 - lbtime[0], t0 - lbtime[t04_ind])
        Mdf, R200m, _ = mass_defs.changeMassDefinition(masses[mc], c=cvir, z=zobs, mdef_in='vir', mdef_out='200m')
        R_2R200ms[mc] = 2.0*R200m
        rds  = rads*R200m #convert to physical units; using r200m, this goes out to 2x R200m
        # doing it this way ensures that we're using the same fractional radii for each cluster

        # integrate time to z=0 in order to get f_nth profile
        for i in range(zi_snap,0,-1):
            z_1 = redshifts[i] #first redshift
            z_2 = redshifts[i-1] #second redshift, the one we are actually at
            dt = lbtime[i] - lbtime[i-1] # in Gyr
            mass_1 = mah[mc, i] #dat = np.zeros((Nmah, nz))
            mass_2 = mah[mc, i-1]
            dM = mass_2 - mass_1
            dMdt = dM/dt # since the (i+1)th is computed between i+1 and i
            Rvir_1 = mass_so.M_to_R(mass_1, z_1, 'vir')
            Rvir_2 = mass_so.M_to_R(mass_2, z_2, 'vir')

            time_1 = t0 - lbtime[i]
            time_2 = t0 - lbtime[i-1]
            m04_1  = 0.04 * mass_1
            m04_2  = 0.04 * mass_2
            t04_ind_1 = np.where(mah[mc,:] > m04_1)[0][-1]
            t04_ind_2 = np.where(mah[mc,:] > m04_2)[0][-1]
            t04_1 = t0 - lbtime[t04_ind_1]
            t04_2 = t0 - lbtime[t04_ind_2]

            c_1 = conc_model(time_1, t04_1)
            c_2 = conc_model(time_2, t04_2)
            if(i==1): # final
                cvirs[mc] = c_2
                assert cvirs[mc] == cvir
            sig2tots[i-1,:] = sig2_tot(rds, mass_2, c_2, Rvir_2) # this function takes radii in physical kpc/h
            if(i==zi_snap):
                ds2dt[i-1,:] = (sig2tots[i-1,:] - sig2_tot(rds, mass_1, c_1, Rvir_1)) / dt # see if this works better, full change
                sig2nth[i-1,:] = eta * sig2tots[i-1,:] # starts at z_i = 6 roughly
            else:
                ds2dt[i-1,:] = (sig2tots[i-1,:] - sig2tots[i,:]) / dt
                td = t_d(rds, mass_2, z_2, c_2, Rvir_2, beta=beta_def) #t_d at z of interest z_2
                sig2nth[i-1,:] = sig2nth[i,:] + ((-1. * sig2nth[i,:] / td) + eta * ds2dt[i-1,:])*dt
                sig2nth[i-1, sig2nth[i-1,:] < 0] = 0 #can't have negative sigma^2_nth at any point in time
        fnth = sig2nth[0,:] / sig2tots[0,:]
        # Now, we have fnth, so we can compute the pressure profile and use it to compute the thermal pressure profile
        Rvir = mass_so.M_to_R(masses[mc], zobs, 'vir')
        assert Rvir == Rvir_2 # the final one, it should
        Rvirs[mc] = Rvir

        # for computing the enclosed mass out to arbitrary radii
        rhos, rs = profile_nfw.NFWProfile.fundamentalParameters(masses[mc], cvir, zobs, 'vir')
        # need M(<5R500c) for gas mass normalization
        M2R200m = quad(lambda x: 4. * np.pi * x**2 * nfw_prof(x, rhos, rs), 0, R_2R200ms[mc])[0]


        # compute rho_gas profile, use it to compute M_gas within Rdef and T_mgas within Rdef
        rho0_by_P0 = 3*eta0(cvirs[mc])**-1 * Rvir/(G*masses[mc])
        phi0 = -1. * (cvirs[mc] / NFWf(cvirs[mc]))
        phir = lambda rad: -1. * (cvirs[mc] / NFWf(cvirs[mc])) * (np.log(1. + cvirs[mc]*rad/Rvir) / (cvirs[mc]*rad/Rvir))
        theta = lambda rad: 1. + ((Gamma(cvirs[mc]) - 1.) / Gamma(cvirs[mc])) * 3. *eta0(cvirs[mc])**-1 * (phi0 - phir(rad))

        rho0_nume = nume = cbf * M2R200m
        rho0_denom = 4. * np.pi * quad(lambda x: theta(x)**(1.0 / (Gamma(cvirs[mc]) - 1.0)) * x**2, 0, R_2R200ms[mc])[0]
        # This now pegs the gas mass to be equal to cosmic baryon fraction at 5R500c
        # NOTE: Both rho0_nume and rho_denom need to be changed if the radius is changed
        rho0 = rho0_nume / rho0_denom
        rhogas = lambda rad: rho0 * theta(rad)**(1.0 / (Gamma(cvirs[mc]) - 1.0))

        Tg = mu_plasma * mp_kev_by_kms2 * (1. - fnth) * sig2tots[0,:]
        Tgf = interp(rds, Tg) # interpolator for Tgas

        Ptot = rhogas(rds) * sig2tots[0,:]
        Pth  = Ptot * (1.0 - fnth)
        # compute ySZ profile
        yprof = p_2_y(rds, Pth)
        Pth_interp = interp(rds, Pth, k=3)


        ### BELOW HERE IS WHERE WE CAN LOOP OVER DIFFERENT RADII ####

        # Loop over Rdef values, make them tuples
        for itR in range(0,len(radii_definitions)):
            mdef, mult = radii_definitions[itR]
            Mdf, Rdef, _ = mass_defs.changeMassDefinition(masses[mc], c=cvir, z=zobs, mdef_in='vir', mdef_out=mdef)
            Rdef = mult*Rdef

            # integrate ySZ profile out to Rdef
            YSZv[mc, itR] = YSZ(yprof, rds[:-1], Rdef) # uses an interpolator
            YSZrv[mc, itR] = YSZr(Pth_interp, Rdef)
            Mgasv[mc, itR] = 4.0 * np.pi * quad(lambda x: rhogas(x) * x**2, 0, Rdef)[0]
            Tweighted = 4. * np.pi * quad(lambda x: Tgf(x) * rhogas(x) * x**2, 0, Rdef)[0]
            Tmgasv[mc, itR] = Tweighted/Mgasv[mc, itR]
            mass_enc[mc, itR] = quad(lambda x: 4. * np.pi * x**2 * nfw_prof(x, rhos, rs), 0, Rdef)[0]


    return np.stack((mass_enc, Tmgasv, Mgasv, YSZv, YSZrv)), cvirs, Rvirs
Пример #15
0
head_c += 'c(bhattacharya_200m)'
cs_200c_b = concentration.concentration(Ms * h, '200c',
                                        0.0, model = 'bhattacharya13')
head_c += 'c(bhattacharya_200c)'
cs_vir_k = concentration.concentration(Ms * h, 'vir',
                                       0.0, model = 'klypin11')
head_c += 'c(klypin_vir)'
cs_vir_b = concentration.concentration(Ms * h, 'vir',
                                       0.0, model = 'bhattacharya13')
head_c += 'c(bhattacharya_vir)'
cs_200c_p = concentration.concentration(Ms * h, '200c',
                                        0.0, model = 'prada12')
head_c += 'c(prada_200c)'
cs_200c_di = concentration.concentration(Ms * h, '200c',
                                         0.0, model = 'diemer15')
head_c += 'c(diemer_200c)'
Ms_500c, _, _ = mass_defs.changeMassDefinition(Ms * h, cs_200m_d,
                                               0., '200m', '500c')
Ms_500c /= h

np.savetxt("../mdef_bm.txt",
           np.transpose([Ms, Rs_200m, Rs_500c, Ms_500c]),
           header= 'Mass-(200m) Radius-(200m) Radius-(500c), Mass-(500c)')
np.savetxt("../conc_bm.txt",
           np.transpose([Ms,
                         cs_200m_d, cs_200c_d,
                         cs_200m_b, cs_200c_b,
                         cs_vir_k, cs_vir_b,
                         cs_200c_p, cs_200c_di]),
           header = head_c)