Beispiel #1
0
def stats_cens_func(cens_df,mass_to_plot_key):
    """
    Calculates statistics for array given the halo mass property that will be 
    used to plot SMHM relation
    
    Parameters
    ----------
    cens_df: Pandas dataframe
        Catalog consisting of only centrals

    Returns
    -------
    stats_cens: Tuple
        X-axis array, Y-axis array and std error for Y-axis
    """
    base = 0.4 #bin width in dex
    bin_statval = 'average'
    if mass_to_plot_key == 'halo_mvir':
        stats_cens = Stats_one_arr(np.log10(cens_df.halo_mvir_host_halo.\
                                            values),np.log10(cens_df.\
                                            stellar_mass.values),\
                                            base=base,bin_statval=bin_statval)
    elif mass_to_plot_key == 'halo_macc':
        stats_cens = Stats_one_arr(np.log10(cens_df.halo_macc_host_halo.\
                                            values),np.log10(cens_df.\
                                            stellar_mass.values),\
                                            base=base,bin_statval=bin_statval)
    return stats_cens
Beispiel #2
0
def assign_colour_mock(gals_df, catl, stat):
    """
    Assign colour to mock catalog

    Parameters
    ----------
    gals_df: pandas Dataframe
        Mock catalog
    catl: pandas Dataframe
        Data catalog
    stat: string
        Specify whether mean or median statistic is used to assign colour
        from data to mock catalog

    Returns
    ---------
    gals_df: pandas Dataframe
        Dataframe with model corrected (u-r) colour assigned as new column
    """

    logmstar_arr_mock = np.log10(gals_df.stellar_mass.values)
    logmstar_arr_data = catl.logmstar.values
    # Both measurements of stellar masses have to be in the same h=1 unit
    logmstar_arr_data = np.log10((10**logmstar_arr_data) / 2.041)
    u_r_arr_data = catl.modelu_rcorr.values

    # Either assign the mean or median colour within each bin of stellar mass
    if stat == 'mean':
        x, y, x_err, y_err = Stats_one_arr(logmstar_arr_data,
                                           u_r_arr_data,
                                           0.005,
                                           statfunc=np.nanmean)
    elif stat == 'median':
        x, y, x_err, y_err = Stats_one_arr(logmstar_arr_data,
                                           u_r_arr_data,
                                           0.005,
                                           statfunc=np.nanmedian)

    # Assign mean or median colour based on which data bin the mock stellar mass
    # falls in
    colour_arr = np.zeros(len(gals_df))
    for idx1, value1 in enumerate(logmstar_arr_mock):
        colour = 0
        for idx2, value2 in enumerate(x):
            if value1 > value2:
                colour = y[idx2]
                break

        colour_arr[idx1] = colour

    gals_df['modelu_rcorr'] = colour_arr

    return gals_df
Beispiel #3
0
def plot_xmhm_data_mocks(gals_data, halos_data, xmhm_mocks, gals_bf, halos_bf):
    """ This function plots mass relations from survey mocks and data"""
    x_bf, y_bf, y_std_bf, y_std_err_bf = Stats_one_arr(halos_bf,
                                                       gals_bf,
                                                       base=0.4,
                                                       bin_statval='center')
    x_data, y_data, y_std_data, y_std_err_data = Stats_one_arr(
        halos_data, gals_data, base=0.4, bin_statval='center')
    # y_std_err_data = err_data

    fig1 = plt.figure(figsize=(10, 10))
    x_mocks, y_mocks, y_std_err_mocks = xmhm_mocks[0], xmhm_mocks[1], \
        xmhm_mocks[2]
    y_std_err_data = np.std(y_mocks, axis=0)
    # for i in range(len(x_mocks)):
    #     plt.errorbar(x_mocks[i],y_mocks[i],yerr=y_std_err_mocks[i],
    #         color='lightgray',fmt='-s', ecolor='lightgray', markersize=4,
    #         capsize=5, capthick=0.5, label=r'mocks',zorder=5)
    plt.errorbar(x_data,y_data,yerr=y_std_err_data,color='k',fmt='s',
        ecolor='k',markersize=5,capsize=5,capthick=0.5,\
            label=r'data',zorder=10)
    plt.errorbar(x_bf,y_bf,color='mediumorchid',fmt='-s',
        ecolor='mediumorchid',markersize=5,capsize=5,capthick=0.5,\
            label=r'best-fit',zorder=20)

    plt.xlabel(
        r'\boldmath$\log_{10}\ M_{h} \left[\mathrm{M_\odot}\, \mathrm{h}^{-1} \right]$',
        fontsize=20)
    if mf_type == 'smf':
        if survey == 'eco' or survey == 'resolvea':
            plt.ylim(np.log10((10**8.9) / 2.041), )
        elif survey == 'resolveb':
            plt.ylim(np.log10((10**8.7) / 2.041), )
        plt.ylabel(
            r'\boldmath$\log_{10}\ M_\star \left[\mathrm{M_\odot}\, \mathrm{h}^{-1} \right]$',
            fontsize=20)
    elif mf_type == 'bmf':
        if survey == 'eco' or survey == 'resolvea':
            plt.ylim(np.log10((10**9.4) / 2.041), )
        elif survey == 'resolveb':
            plt.ylim(np.log10((10**9.1) / 2.041), )
        plt.ylabel(
            r'\boldmath$\log_{10}\ M_{b} \left[\mathrm{M_\odot}\, \mathrm{h}^{-1} \right]$',
            fontsize=20)
    handles, labels = plt.gca().get_legend_handles_labels()
    by_label = OrderedDict(zip(labels, handles))
    plt.legend(by_label.values(),
               by_label.keys(),
               loc='best',
               prop={'size': 15})
    # plt.savefig(path_to_figures + 'mocks_data_xmhm_{0}.png'.format(survey))
    plt.show()
Beispiel #4
0
def debug_xmhm():

    bf_params_bmf = np.array(
        [12.23321941, 10.53554995, 0.5430062, 0.57290598, 0.36211791])
    bf_params_smf = np.array(
        [12.32381675, 10.56581819, 0.4276319, 0.7457711, 0.34784431])
    behroozi10_params = np.array([12.35, 10.72, 0.44, 0.57, 0.15])

    mstar_min = np.round(np.log10((10**6.5) / 2.041), 1)
    mstar_max = np.round(np.log10((10**11.8) / 2.041), 1)
    logmstar_arr = np.linspace(mstar_min, mstar_max, 500)

    logmh_bary = behroozi10(logmstar_arr, bf_params_bmf)
    logmh_stellar = behroozi10(logmstar_arr, bf_params_smf)
    logmh_b10 = behroozi10(logmstar_arr, behroozi10_params)


    x_bary,y_bary,y_std_bary,y_std_err_bary = Stats_one_arr(logmh_bary,\
    logmstar_arr,base=0.4,bin_statval='center')
    x_star,y_star,y_std_star,y_std_err_star = Stats_one_arr(logmh_stellar,\
    logmstar_arr,base=0.4,bin_statval='center')
    x_b10,y_b10,y_std_b10,y_std_err_b10 = Stats_one_arr(logmh_b10,\
    logmstar_arr,base=0.4,bin_statval='center')

    fig3 = plt.figure(figsize=(10, 10))
    # plt.plot(logmh_bary, logmstar_arr, c='r')
    # plt.plot(logmh_stellar, logmstar_arr, c='b')
    # plt.plot(logmh_b10, logmstar_arr, c='k')
    plt.errorbar(x_bary,y_bary,yerr=y_std_err_bary,color='r',fmt='-s',ecolor='r',\
        markersize=4,capsize=5,capthick=0.5,label=r'baryonic',zorder=10)
    plt.errorbar(x_star,y_star,yerr=y_std_err_star,color='b',fmt='-s',ecolor='b',\
        markersize=4,capsize=5,capthick=0.5,label=r'stellar',zorder=20)
    plt.errorbar(x_b10,y_b10,yerr=y_std_err_b10,color='k',fmt='-s',ecolor='k',\
            markersize=4,capsize=5,capthick=0.5,label=r'Behroozi10',zorder=30)
    plt.xlabel(
        r'\boldmath$\log_{10}\ M_{h} \left[\mathrm{M_\odot}\, \mathrm{h}^{-1} \right]$',
        fontsize=15)
    plt.ylabel(
        r'\boldmath$\log_{10}\ M_\star \left[\mathrm{M_\odot}\, \mathrm{h}^{-1} \right]$',
        fontsize=15)
    plt.legend(loc='best', prop={'size': 10})
    plt.show()
Beispiel #5
0
def plot_smhm(gals_bf_red, halos_bf_red, gals_bf_blue, halos_bf_blue):
    """
    Plot red and blue best fit SMHM
    """
    x_bf_red,y_bf_red,y_std_bf_red,y_std_err_bf_red = \
        Stats_one_arr(halos_bf_red, gals_bf_red, base=0.4, bin_statval='center')
    x_bf_blue,y_bf_blue,y_std_bf_blue,y_std_err_bf_blue = \
        Stats_one_arr(halos_bf_blue, gals_bf_blue, base=0.4,
        bin_statval='center')

    fig1 = plt.figure(figsize=(10, 10))
    plt.errorbar(x_bf_red,y_bf_red,color='r',fmt='-s',ecolor='r',\
        markersize=4,capsize=5,capthick=0.5,zorder=10)
    plt.errorbar(x_bf_blue,y_bf_blue,color='b',fmt='-s',ecolor='b',\
        markersize=4,capsize=5,capthick=0.5,zorder=10)

    plt.xlabel(
        r'\boldmath$\log_{10}\ M_{h} \left[\mathrm{M_\odot}\, \mathrm{h}^{-1} \right]$',
        fontsize=20)
    plt.ylabel(
        r'\boldmath$\log_{10}\ M_\star \left[\mathrm{M_\odot}\, \mathrm{h}^{-1} \right]$',
        fontsize=20)
    plt.show()
Beispiel #6
0
### Convert to log
hmass_logmbary = np.log10(hmass_mbary_ham)
hmass_loggrpmb = np.log10(hmass_grpmb_ham)
logmbary = np.log10(mbary)
logmbaryc = np.log10(mbary_c)
loggrpmb = np.log10(grpmb)

hmass_logmstar = np.log10(hmass_mstar_ham)
hmass_loggrpms = np.log10(hmass_grpms_ham)
logmstar = np.log10(mstar)
loggrpms = np.log10(grpms)

### Get error bars
x_mbary,y_mbary,y_std_mbary,y_std_err_mbary = Stats_one_arr(hmass_logmbary,\
                                                                logmbaryc,\
                                                                base=0.3)
x_grpmb,y_grpmb,y_std_grpmb,y_std_err_grpmb = Stats_one_arr(hmass_loggrpmb,\
                                                            logmbaryc,base=0.3)

x_mstar,y_mstar,y_std_mstar,y_std_err_mstar = Stats_one_arr(hmass_logmstar,\
                                                                logmbaryc,\
                                                                base=0.3)
x_grpms,y_grpms,y_std_grpms,y_std_err_grpms = Stats_one_arr(hmass_loggrpms,\
                                                            logmbaryc,\
                                                            base=0.3)

x_mhs,y_mhs,y_std_mhs,y_std_err_mhs = Stats_one_arr(resolve_live18_subset.logmh_s.\
                                                    values,logmbaryc,base=0.3)
x_mh,y_mh,y_std_mh,y_std_err_mh = Stats_one_arr(resolve_live18_subset.logmh.values,\
                                                logmbaryc,base=0.3)
Beispiel #7
0
hmass_grpms_ham = [hmass_n_interp_func(val) for val in pbar(n_grpms_arr)]

### Convert to log
hmass_loggrpmb = np.log10(hmass_grpmb_ham)
hmass_loggrpms = np.log10(hmass_grpms_ham)

df_halomasses = {
    'baryonic': hmass_loggrpmb,
    'stellar': hmass_loggrpms,
    'absmag': logmh_arr,
    'resolve_stellar': logmh_s_arr
}
df_halomasses = pd.DataFrame(data=df_halomasses)

### Get error bars
x_grpmb,y_grpmb,y_std_grpmb,y_std_err_grpmb = Stats_one_arr(hmass_loggrpmb,\
    cenmstar_arr,base=0.3)

x_grpms,y_grpms,y_std_grpms,y_std_err_grpms = Stats_one_arr(hmass_loggrpms,\
    cenmstar_arr,base=0.3)

x_mhs,y_mhs,y_std_mhs,y_std_err_mhs = Stats_one_arr(logmh_s_arr,cenmstar_arr,\
    base=0.3)

x_mh, y_mh, y_std_mh, y_std_err_mh = Stats_one_arr(logmh_arr,
                                                   cenmstar_arr,
                                                   base=0.3)

y_std_err_grpmb = np.sqrt(y_std_err_grpmb**2 + (0.30**2))
y_std_err_grpms = np.sqrt(y_std_err_grpms**2 + (0.30**2))
y_std_err_mhs = np.sqrt(y_std_err_mhs**2 + (0.30**2))
y_std_err_mh = np.sqrt((y_std_err_mh**2) + (0.30**2))
Beispiel #8
0
def get_xmhm_mocks(survey, path, mf_type):
    """
    Calculate error in data SMF from mocks

    Parameters
    ----------
    survey: string
        Name of survey
    path: string
        Path to mock catalogs

    Returns
    ---------
    err_total: array
        Standard deviation of phi values between samples of 8 mocks
    """

    if survey == 'eco':
        mock_name = 'ECO'
        num_mocks = 8
        min_cz = 3000
        max_cz = 7000
        mag_limit = -17.33
        mstar_limit = 8.9
        volume = 151829.26  # Survey volume without buffer [Mpc/h]^3
    elif survey == 'resolvea':
        mock_name = 'A'
        num_mocks = 59
        min_cz = 4500
        max_cz = 7000
        mag_limit = -17.33
        mstar_limit = 8.9
        volume = 13172.384  # Survey volume without buffer [Mpc/h]^3
    elif survey == 'resolveb':
        mock_name = 'B'
        num_mocks = 104
        min_cz = 4500
        max_cz = 7000
        mag_limit = -17
        mstar_limit = 8.7
        volume = 4709.8373  # Survey volume without buffer [Mpc/h]^3

    x_arr = []
    y_arr = []
    y_std_err_arr = []
    for num in range(num_mocks):
        filename = path + '{0}_cat_{1}_Planck_memb_cat.hdf5'.format(
            mock_name, num)
        mock_pd = read_mock_catl(filename)

        # Using the same survey definition as in mcmc smf i.e excluding the
        # buffer
        if mf_type == 'smf':
            mock_pd = mock_pd.loc[(mock_pd.cz.values >= min_cz) & \
                (mock_pd.cz.values <= max_cz) & \
                (mock_pd.M_r.values <= mag_limit) & \
                (mock_pd.logmstar.values >= mstar_limit)]
            cen_gals = np.log10(
                10**(mock_pd.logmstar.loc[mock_pd.cs_flag == 1]) / 2.041)
            cen_halos = mock_pd.M_group.loc[mock_pd.cs_flag == 1]

            x, y, y_std, y_std_err = Stats_one_arr(cen_halos,
                                                   cen_gals,
                                                   base=0.4,
                                                   bin_statval='center')

        elif mf_type == 'bmf':
            mock_pd = mock_pd.loc[(mock_pd.cz.values >= min_cz) & \
                (mock_pd.cz.values <= max_cz) & \
                (mock_pd.M_r.values <= mag_limit)]
            cen_gals_stellar = np.log10(
                10**(mock_pd.logmstar.loc[mock_pd.cs_flag == 1]) / 2.041)
            cen_gals_gas = mock_pd.mhi.loc[mock_pd.cs_flag == 1]
            cen_gals_gas = np.log10((1.4 * cen_gals_gas) / 2.041)
            cen_gals_bary = calc_bary(cen_gals_stellar, cen_gals_gas)
            mock_pd['cen_gals_bary'] = cen_gals_bary
            if survey == 'eco' or survey == 'resolvea':
                limit = np.log10((10**9.4) / 2.041)
                cen_gals_bary = mock_pd.cen_gals_bary.loc\
                    [mock_pd.cen_gals_bary >= limit]
                cen_halos = mock_pd.M_group.loc[
                    (mock_pd.cs_flag == 1) & (mock_pd.cen_gals_bary >= limit)]
            elif survey == 'resolveb':
                limit = np.log10((10**9.1) / 2.041)
                cen_gals_bary = mock_pd.cen_gals_bary.loc\
                    [mock_pd.cen_gals_bary >= limit]
                cen_halos = mock_pd.M_group.loc[
                    (mock_pd.cs_flag == 1) & (mock_pd.cen_gals_bary >= limit)]

            x, y, y_std, y_std_err = Stats_one_arr(cen_halos,
                                                   cen_gals_bary,
                                                   base=0.4,
                                                   bin_statval='center')

        x_arr.append(x)
        y_arr.append(y)
        y_std_err_arr.append(y_std_err)

    x_arr = np.array(x_arr)
    y_arr = np.array(y_arr)
    y_std_err_arr = np.array(y_std_err_arr)

    return [x_arr, y_arr, y_std_err_arr]
Beispiel #9
0
def plot_xmhm(result, gals_bf, halos_bf, gals_data, halos_data, gals_b10, \
    halos_b10, bf_chi2):
    """
    Plot SMHM from data, best fit param values, param values corresponding to 
    68th percentile 1000 lowest chi^2 values and behroozi 2010 param values

    Parameters
    ----------
    result: multidimensional array
        Array of central galaxy and halo masses
    
    gals_bf: array
        Array of y-axis stellar mass values for best fit SMHM

    halos_bf: array
        Array of x-axis halo mass values for best fit SMHM
    
    gals_data: array
        Array of y-axis stellar mass values for data SMF

    halos_data: array
        Array of x-axis halo mass values for data SMF

    gals_b10: array
        Array of y-axis stellar mass values for behroozi 2010 SMHM

    halos_b10: array
        Array of x-axis halo mass values for behroozi 2010 SMHM

    Returns
    ---------
    Nothing; SMHM plot is saved in figures repository
    """
    if survey == 'resolvea':
        line_label = 'RESOLVE-A'
    elif survey == 'resolveb':
        line_label = 'RESOLVE-B'
    elif survey == 'eco':
        line_label = 'ECO'

    x_bf,y_bf,y_std_bf,y_std_err_bf = Stats_one_arr(halos_bf,\
    gals_bf,base=0.4,bin_statval='center')
    x_b10,y_b10,y_std_b10,y_std_err_b10 = Stats_one_arr(halos_b10,\
        gals_b10,base=0.4,bin_statval='center')
    x_data,y_data,y_std_data,y_std_err_data = Stats_one_arr(halos_data,\
        gals_data,base=0.4,bin_statval='center')
    # y_std_err_data = err_data

    fig1 = plt.figure(figsize=(10, 10))
    # NOT PLOTTING DATA RELATION
    # plt.errorbar(x_data,y_data,yerr=y_std_err_data,color='k',fmt='-s',\
    #     ecolor='k',markersize=4,capsize=5,capthick=0.5,\
    #         label='{0}'.format(line_label),zorder=10)

    plt.errorbar(x_b10,y_b10, color='k',fmt='--s',\
        markersize=3, label='Behroozi10', zorder=10, alpha=0.7)

    for idx in range(len(result[0][0])):
        x_model,y_model,y_std_model,y_std_err_model = \
            Stats_one_arr(result[0][4][idx],result[0][3][idx],base=0.4,\
                bin_statval='center')
        plt.plot(x_model,y_model,color='lightgray',linestyle='-',alpha=0.5,\
            zorder=0,label='model')
    for idx in range(len(result[1][0])):
        x_model,y_model,y_std_model,y_std_err_model = \
            Stats_one_arr(result[1][4][idx],result[1][3][idx],base=0.4,\
                bin_statval='center')
        plt.plot(x_model,y_model,color='lightgray',linestyle='-',alpha=0.5,\
            zorder=1)
    for idx in range(len(result[2][0])):
        x_model,y_model,y_std_model,y_std_err_model = \
            Stats_one_arr(result[2][4][idx],result[2][3][idx],base=0.4,\
                bin_statval='center')
        plt.plot(x_model,y_model,color='lightgray',linestyle='-',alpha=0.5,\
            zorder=2)
    for idx in range(len(result[3][0])):
        x_model,y_model,y_std_model,y_std_err_model = \
            Stats_one_arr(result[3][4][idx],result[3][3][idx],base=0.4,\
                bin_statval='center')
        plt.plot(x_model,y_model,color='lightgray',linestyle='-',alpha=0.5,\
            zorder=3)
    for idx in range(len(result[4][0])):
        x_model,y_model,y_std_model,y_std_err_model = \
            Stats_one_arr(result[4][4][idx],result[4][3][idx],base=0.4,\
                bin_statval='center')
        plt.plot(x_model,y_model,color='lightgray',linestyle='-',alpha=0.5,\
            zorder=4)

    # REMOVED ERROR BAR ON BEST FIT
    plt.errorbar(x_bf,y_bf,color='mediumorchid',fmt='-s',ecolor='mediumorchid',\
        markersize=4,capsize=5,capthick=0.5,label='best fit',zorder=10)

    if survey == 'resolvea' and mf_type == 'smf':
        plt.xlim(10, 14)
    else:
        plt.xlim(10, )
    plt.xlabel(
        r'\boldmath$\log_{10}\ M_{h} \left[\mathrm{M_\odot}\, \mathrm{h}^{-1} \right]$',
        fontsize=20)
    if mf_type == 'smf':
        if survey == 'eco':
            plt.ylim(np.log10((10**8.9) / 2.041), )
        elif survey == 'resolvea':
            plt.ylim(np.log10((10**8.9) / 2.041), 13)
        elif survey == 'resolveb':
            plt.ylim(np.log10((10**8.7) / 2.041), )
        plt.ylabel(
            r'\boldmath$\log_{10}\ M_\star \left[\mathrm{M_\odot}\, \mathrm{h}^{-1} \right]$',
            fontsize=20)
    elif mf_type == 'bmf':
        if survey == 'eco' or survey == 'resolvea':
            plt.ylim(np.log10((10**9.4) / 2.041), )
        elif survey == 'resolveb':
            plt.ylim(np.log10((10**9.1) / 2.041), )
        plt.ylabel(
            r'\boldmath$\log_{10}\ M_{b} \left[\mathrm{M_\odot}\, \mathrm{h}^{-1} \right]$',
            fontsize=20)
    handles, labels = plt.gca().get_legend_handles_labels()
    by_label = OrderedDict(zip(labels, handles))
    plt.legend(by_label.values(),
               by_label.keys(),
               loc='best',
               prop={'size': 20})
    plt.annotate(r'$\boldsymbol\chi ^2 \approx$ {0}'.format(
        np.round(bf_chi2, 2)),
                 xy=(0.8, 0.1),
                 xycoords='axes fraction',
                 bbox=dict(boxstyle="square",
                           ec='k',
                           fc='lightgray',
                           alpha=0.5),
                 size=15)
    if mf_type == 'smf':
        plt.savefig(path_to_figures + 'smhm_emcee_{0}.png'.format(survey))
    elif mf_type == 'bmf':
        plt.savefig(path_to_figures + 'bmhm_emcee_{0}.png'.format(survey))
        cen_colour_arr.append(cen_colour)
        grpn_arr.append(grp_N)

data = {
    'deltav': deltav_arr,
    'log_cen_stellar_mass': cen_stellar_mass_arr,
    'cen_colour_label': cen_colour_label_arr,
    'cen_ur_colour': cen_colour_arr
}
vel_col_mass_df = pd.DataFrame(data)
df_blue_cen = vel_col_mass_df.loc[vel_col_mass_df['cen_colour_label'] == 'B']
df_red_cen = vel_col_mass_df.loc[vel_col_mass_df['cen_colour_label'] == 'R']

# Stats_one_arr returns std from the mean
x_blue,y_blue,y_std_blue,y_std_err_blue = Stats_one_arr(df_blue_cen.\
    log_cen_stellar_mass,df_blue_cen.deltav,base=0.5,statfunc=np.std,
    bin_statval='left')

x_red,y_red,y_std_red,y_std_err_red = Stats_one_arr(df_red_cen.\
    log_cen_stellar_mass,df_red_cen.deltav,base=0.5,statfunc=np.std,
    bin_statval='left')

# Calculate same as above but std from 0 km/s
stellar_mass_bins = np.arange(7, 12, 0.5)
i = 0
std_blue_cen_arr = []
for index1, bin_edge in enumerate(stellar_mass_bins):
    df_blue_cen_deltav_arr = []
    if index1 == 9:
        break
    for index2, stellar_mass in enumerate(
cumu_smf_result_bf = cumu_num_dens(gals_df.stellar_mass.values, bins, None,
                                   v_sim, False)

## catl_grpcz_cut and catl_cz_cut were initialized in the terminal so if this
## script is run from scratch the following lines will result in an error and
## those objects will have to be initialized again
mass_data, phi_data, err_tot_data, bins_data, counts_data = \
    diff_smf(catl_grpcz_cut.logmstar.values, volume, False)
bins = np.logspace(8.6, 11.2, 7)
cumu_smf_result_data = cumu_num_dens(10**catl_grpcz_cut.logmstar.values, bins,
                                     None, volume, False)
cen_halos_data = catl_grpcz_cut.logmh.loc[catl_grpcz_cut.fc == 1]
cen_gals_data = catl_grpcz_cut.logmstar.loc[catl_grpcz_cut.fc == 1]
cen_gals_data = np.log10((10**cen_gals_data) / 2.041)
x, y, y_std, y_std_err = Stats_one_arr(cen_halos_data,
                                       cen_gals_data,
                                       base=0.4,
                                       bin_statval='center')

mass_data2, phi_data2, err_tot_data2, bins_data2, counts_data2 = \
    diff_smf(catl_cz_cut.logmstar.values, volume, False)
bins = np.logspace(8.6, 11.2, 7)
cumu_smf_result_data2 = cumu_num_dens(10**catl_cz_cut.logmstar.values, bins,
                                      None, volume, False)
cen_halos_data2 = catl_cz_cut.logmh.loc[catl_cz_cut.fc == 1]
cen_gals_data2 = catl_cz_cut.logmstar.loc[catl_cz_cut.fc == 1]
cen_gals_data2 = np.log10((10**cen_gals_data2) / 2.041)
x2, y2, y_std2, y_std_err2 = Stats_one_arr(cen_halos_data2,
                                           cen_gals_data2,
                                           base=0.4,
                                           bin_statval='center')
Beispiel #12
0
print('Getting data in specific percentile')
mcmc_table_pctl, bf_params, bf_chi2 = get_paramvals_percentile(
    mcmc_table, 68, chi2)

print('Getting best fit model and centrals')
maxis_bf, phi_bf, err_tot_bf, counts_bf, cen_gals_bf, cen_halos_bf = \
    get_best_fit_model(bf_params)

# Using abundance matched group halo mass from mocks for errors in data
xmhm_mocks = get_xmhm_mocks(survey, path_to_mocks, mf_type)

logmhalo_cen = np.log10(
    (10**catl.logmh_s.loc[catl.fc.values == 1].values) / 2.041)
logmstar_cen = np.log10(
    (10**catl.logmstar.loc[catl.fc.values == 1].values) / 2.041)
x_data, y_data, y_std_data, y_std_err_data = Stats_one_arr(
    logmhalo_cen, logmstar_cen, base=0.4, bin_statval='center')
x_mocks, y_mocks, y_std_err_mocks = xmhm_mocks[0], xmhm_mocks[1], \
    xmhm_mocks[2]
y_std_err_data = np.std(y_mocks, axis=0)

x_ham, y_ham, y_std_ham, y_std_err_ham = Stats_one_arr(ham_mass,
                                                       logmstar_sorted,
                                                       base=0.4,
                                                       bin_statval='center')

x_bf, y_bf, y_std_bf, y_std_err_bf = Stats_one_arr(cen_halos_bf,
                                                   cen_gals_bf,
                                                   base=0.4,
                                                   bin_statval='center')

fig1 = plt.figure(figsize=(10, 10))
cen_gals_eco_h2 = []
cen_halos_eco_h2 = []
for idx, val in enumerate(eco_nobuff.fc.values):
    if val == 1:
        stellar_mass_h07 = eco_nobuff.logmstar.values[idx]
        stellar_mass_h1 = np.log10((10**stellar_mass_h07) / 2.041)
        halo_mass_h07 = eco_nobuff.logmh_s.values[idx]
        halo_mass_h1 = np.log10((10**halo_mass_h07) / 2.041)
        cen_gals_eco_h2.append(stellar_mass_h1)
        cen_halos_eco_h2.append(halo_mass_h1)

cen_gals_eco_h2 = np.array(cen_gals_eco_h2)
cen_halos_eco_h2 = np.array(cen_halos_eco_h2)

# Bin data for all 3 cases: b10, best fit and data
x_bf,y_bf,y_std_bf,y_std_err_bf = Stats_one_arr(cen_halos_bf,\
    cen_gals_bf,base=0.4,bin_statval='center')
x_b10,y_b10,y_std_b10,y_std_err_b10 = Stats_one_arr(cen_halos_b10,\
    cen_gals_b10,base=0.4,bin_statval='center')
x_eco_h1,y_eco_h1,y_std_eco_h1,y_std_err_eco_h1 = Stats_one_arr(cen_halos_eco_h1,\
    cen_gals_eco_h1,base=0.4,bin_statval='center')
x_eco_h2,y_eco_h2,y_std_eco_h2,y_std_err_eco_h2 = Stats_one_arr(cen_halos_eco_h2,\
    cen_gals_eco_h2,base=0.4,bin_statval='center')

y_std_err_eco_h1 = np.sqrt(y_std_err_eco_h1**2 + cvar_eco**2)
y_std_err_eco_h2 = np.sqrt(y_std_err_eco_h2**2 + cvar_eco**2)
# Plot SMF comparisons between best fit and data
fig1 = plt.figure(figsize=(10, 10))
plt.errorbar(max_eco,
             phi_eco,
             yerr=err_eco,
             color='#921063',
Beispiel #14
0
                                                 0]
mock_catalog_tiled_cens = mock_catalog_tiled.loc[mock_catalog_tiled['C_S'] ==
                                                 1]

velocities_re_sats = velocity_re_func(mock_catalog_tiled_sats.Re.values,\
                                      mock_catalog_tiled_sats.halo_rs.values,\
                                      mock_catalog_tiled_sats.halo_rvir.values,\
                                      mock_catalog_tiled_sats.halo_mvir.values)

velocities_re_cens = velocity_re_func(mock_catalog_tiled_cens.Re.values,\
                                      mock_catalog_tiled_cens.halo_rs.values,\
                                      mock_catalog_tiled_cens.halo_rvir.values,\
                                      mock_catalog_tiled_cens.halo_mvir.values)

Stats_one_arr_vre_sats = Stats_one_arr(np.log10(mock_catalog_tiled_sats.\
                                                Re.values),\
                                       np.log10(velocities_re_sats),base=0.4)

Stats_one_arr_vre_cens = Stats_one_arr(np.log10(mock_catalog_tiled_cens.\
                                                Re.values),\
                                       np.log10(velocities_re_cens),base=0.4)

Stats_one_arr_vpeak_cens = Stats_one_arr(np.log10(mock_catalog_tiled_cens.\
                                                  Re.values),\
                                         np.log10(mock_catalog_tiled_cens.\
                                                  vpeak.values),base=0.4)

Stats_one_arr_vpeak_sats = Stats_one_arr(np.log10(mock_catalog_tiled_sats.\
                                                  Re.values),\
                                         np.log10(mock_catalog_tiled_sats.\
                                                  vpeak.values),base=0.4)
fig1 = plt.figure(figsize=(10,8))
for i in range(len(Mhalo_characteristic)):
    colour_arr = ['#53A48D', 'mediumorchid', 'cornflowerblue']
    label_arr = [r'$best\ fit$', r'$+5\% \Theta$', r'$-5\% \Theta$']  
    plt.errorbar(max_arr[i],phi_arr[i],
        color=colour_arr[i],fmt='-s',ecolor=colour_arr[i],markersize=10,
        capsize=5,capthick=0.5,label=label_arr[i],linewidth=5)
    plt.xlabel(r'\boldmath$\log_{10}\ M_\star \left[\mathrm{M_\odot}\, \mathrm{h}^{-1} \right]$', fontsize=20)
    plt.ylabel(r'\boldmath$\Phi \left[\mathrm{dex}^{-1}\,\mathrm{Mpc}^{-3}\,\mathrm{h}^{3} \right]$', fontsize=20)
    plt.legend(loc='best', prop={'size': 20})

fig2 = plt.figure(figsize=(10,8))
y_arr = []
x_arr = []
for i in range(len(Mhalo_characteristic)):
    x,y,y_std,y_std_err = Stats_one_arr(cen_halos_arr[i],
        cen_gals_arr[i],base=0.4,bin_statval='center')
    y_arr.append(y)
    x_arr.append(x)
    colour_arr = ['#53A48D', 'mediumorchid', 'cornflowerblue']
    label_arr = [r'$best\ fit$', r'$+5\% \Theta$', r'$-5\% \Theta$']  
    plt.errorbar(x,y,color=colour_arr[i],fmt='-s',ecolor=colour_arr[i],\
        markersize=10,capsize=5,capthick=0.5,label=label_arr[i],linewidth=5)
    plt.xlabel(r'\boldmath$\log_{10}\ M_{h} \left[\mathrm{M_\odot}\, \mathrm{h}^{-1} \right]$',fontsize=20)
    plt.ylabel(r'\boldmath$\log_{10}\ M_\star \left[\mathrm{M_\odot}\, \mathrm{h}^{-1} \right]$',fontsize=20)
    plt.legend(loc='best', prop={'size': 20})

## SMF percentage difference
p_percent_diff = ((phi_arr[1] - phi_arr[0])/np.abs(phi_arr[0]))*100
n_percent_diff = ((phi_arr[2] - phi_arr[0])/np.abs(phi_arr[0]))*100
fig3 = plt.figure(figsize=(10,8))
plt.plot(max_arr[0], p_percent_diff, c='mediumorchid', label=r'$+5\% \Theta$', lw=5)
Beispiel #16
0
### Log scaling
hmass_logmbary = np.log10(hmass_mbary_sham)
hmass_loggrpmb = np.log10(hmass_grpmb_sham)
hmass_logsmass = np.log10(hmass_smass_sham)
logmbary = np.log10(mbary)
logsmass = np.log10(stellarmass)

### Retrieving log values from resolve catalog
hmass_rlum = resolve_live18.logmh.values
hmass_stellarmass = resolve_live18.logmh_s.values
loggrpmb = resolve_live18.grpmb.values

### Using stats_one_arr to get error bars on mean
x_mbary,y_mbary,y_std_mbary,y_std_err_mbary = Stats_one_arr(hmass_logmbary,\
                                                            loggrpmb,\
                                                            base=0.5)

x_rlum,y_rlum,y_std_rlum,y_std_err_rlum = Stats_one_arr(hmass_rlum,loggrpmb,\
                                                        base=0.5)

x_smass,y_smass,y_std_smass,y_std_err_smass = Stats_one_arr(hmass_stellarmass,\
                                                            loggrpmb,base=0.5)

x_grpmb,y_grpmb,y_std_grpmb,y_std_err_grpmb = Stats_one_arr(hmass_loggrpmb,\
                                                            loggrpmb,\
                                                            base=0.5)

x_smass_sham,y_smass_sham,y_std_smass_sham,y_std_err_smass_sham = \
Stats_one_arr(hmass_logsmass,loggrpmb,base=0.5)
Beispiel #17
0
pbar = ProgressBar(maxval=len(grpmb_arr))
n_grpmb_arr = [grpmb_n_interp_func(val) for val in pbar(grpmb_arr)]
pbar = ProgressBar(maxval=len(n_grpmb_arr))
hmass_grpmb_ham = [hmass_n_interp_func(val) for val in pbar(n_grpmb_arr)]

pbar = ProgressBar(maxval=len(grpms_arr))
n_grpms_arr = [grpms_n_interp_func(val) for val in pbar(grpms_arr)]
pbar = ProgressBar(maxval=len(n_grpms_arr))
hmass_grpms_ham = [hmass_n_interp_func(val) for val in pbar(n_grpms_arr)]

### Convert to log
hmass_loggrpmb = np.log10(hmass_grpmb_ham)
hmass_loggrpms = np.log10(hmass_grpms_ham)

### Get error bars
x_grpmb,y_grpmb,y_std_grpmb,y_std_err_grpmb = Stats_one_arr(hmass_loggrpmb,\
    grpmb_arr,base=0.3,bin_statval='center')

x_grpms,y_grpms,y_std_grpms,y_std_err_grpms = Stats_one_arr(hmass_loggrpms,\
    grpms_arr,base=0.3,bin_statval='center')

x_mhs,y_mhs,y_std_mhs,y_std_err_mhs = Stats_one_arr(logmh_s_arr,grpms_arr,\
    base=0.3,bin_statval='center')

x_mh,y_mh,y_std_mh,y_std_err_mh = Stats_one_arr(logmh_arr,grprmag_arr,base=0.3,\
    bin_statval='center')

fig1 = plt.figure(figsize=(10, 10))
plt.errorbar(x_grpmb,y_grpmb,yerr=y_std_err_grpmb,\
             color='#1baeab',fmt='--s',ecolor='#1baeab',markersize=4,capsize=5,\
             capthick=0.5,label=r'$M_{bary,grp}$')
plt.errorbar(x_grpms,y_grpmb,yerr=y_std_err_grpms,\