예제 #1
0
# set cosmology
redshift = 1/scale - 1
cosmo = Planck15
h = Planck15.h
conc = 5

# needs to run first to initialize package
# halotools.test_installation()

# determine dark mass and virial radius
model = PrebuiltSubhaloModelFactory('behroozi10', redshift = redshift)
stars_mass = 60850451172.24926
# stars_mass in units Msun from simulation
log_stars_mass = np.log10(stars_mass)
log_dark_mass = model.mean_log_halo_mass(log_stellar_mass=log_stars_mass)
dm_stellar = 10**log_dark_mass
virial = halo_mass_to_halo_radius(dm_stellar, cosmo, redshift, mdef)
virial_kpc = (virial * u.Mpc).to('kpc') / h
virial_rad = np.arange(radmin, virial_kpc.value, inc)
scaled_rad = virial_rad / np.max(virial_rad)

# calculate the density threshold for dimensionless mass density calculation
nfw = NFWProfile()
rho_thresh = density_threshold(cosmo, redshift, mdef)
# rho_thresh in units Msun*h^2/Mpc^3
rho_units = (rho_thresh * u.Msun / u.Mpc**3).to('Msun/kpc3') * h**2
dimless_massdens = nfw.dimensionless_mass_density(scaled_rad, conc)
mass_dens = dimless_massdens * rho_units
# mass_dens is in units Msun/kpc^3
예제 #2
0
def plot_SMHM(halocat_galcat_merged,mass_to_plot_key,populate_mock_key):
    """
    Plots SM-HM relation
    
    Parameters
    ----------
    halocat_galcat_merged: Pandas dataframe
        Merged dataframe containing halo and galaxy information   
        
    mass_to_plot_key: string
        Halo mass property that will be plotted on the X-axis
        
    populate_mock_key: string
        Halo mass property used to populate mock

    """
    print('    -> Separating centrals and satellites')
    cens = halocat_galcat_merged.loc[halocat_galcat_merged.C_S.values == 1]
    sats = halocat_galcat_merged.loc[halocat_galcat_merged.C_S.values == 0]
    
    print('    -> Overplotting Behroozi 2010 relation for centrals (halotools)')
    mstar_arr = np.linspace(cens.stellar_mass.values.min(),\
                            cens.stellar_mass.values.max(),\
                            1000000)
    log_mstar_arr_B10 = np.log10(mstar_arr)
    model = PrebuiltSubhaloModelFactory('behroozi10',redshift=0.0186,\
                                         prim_haloprop_key=populate_mock_key)   
    log_halo_mass_B10 = model.mean_log_halo_mass(log_stellar_mass=\
                                                 log_mstar_arr_B10,\
                                                 redshift=0.0186)
    
        
    if mass_to_plot_key == 'halo_mvir':
        print('    -> Calculating statistics using {0}'.format\
              (mass_to_plot_key))
        stats_cens = stats_cens_func(cens,mass_to_plot_key)


        print('    -> Plotting')
        fig1 = plt.figure()
        plt.scatter(np.log10(sats.halo_mvir_host_halo.values),\
                    np.log10(sats.stellar_mass.values),color='g',s=5,\
                    alpha=0.5,label='Satellites')
        plt.plot(log_halo_mass_B10,log_mstar_arr_B10,'-k',\
                 label='Behroozi 2010 cosmoutils')
        plt.errorbar(stats_cens[0],stats_cens[1],yerr=stats_cens[2],color='r',\
                     label='Centrals')
        plt.xlabel(r'$\mathrm{Halo\ mass\ (mvir)}/\mathrm{[\frac{M_\odot}{h}]'\
                              '})$')
        plt.ylabel(r'$\mathrm{Stellar\ mass}/\mathrm{[\frac{M_\odot}{h}]})$')
        plt.title('SM-HM relation using {0} to populate mocks'.format\
                  (populate_mock_key.split('_')[1]))


    elif mass_to_plot_key == 'halo_macc':
        print('    -> Calculating statistics using {0}'.format\
              (mass_to_plot_key))
        stats_cens = stats_cens_func(cens,mass_to_plot_key)
        print('    -> Plotting')
        fig1 = plt.figure()
        plt.scatter(np.log10(sats.halo_macc_host_halo.values),\
                    np.log10(sats.stellar_mass.values),color='g',s=5,\
                    alpha=0.5,label='Satellites')
        plt.plot(log_halo_mass_B10,log_mstar_arr_B10,'-k',\
                 label='Behroozi 2010 cosmoutils')
        plt.errorbar(stats_cens[0],stats_cens[1],yerr=stats_cens[2],color='r',\
                     label='Centrals')
        plt.xlabel(r'$\mathrm{Halo\ mass\ (macc)}/\mathrm{[\frac{M_\odot}{h}]'\
                              '})$')
        plt.ylabel(r'$\mathrm{Stellar\ mass}/\mathrm{[\frac{M_\odot}{h}]})$')
        plt.title('SM-HM relation using {0} to populate mocks'.format\
                  (populate_mock_key.split('_')[1]))

    
    plt.legend(loc='best',prop={'size': 6})
    fig1.tight_layout()
    print('    -> Saving figure')
    fig1.savefig('../reports/figures/SMHM_{0}_hosthalo.png'.format\
                 (mass_to_plot_key.split('_')[1]))