Exemplo n.º 1
0
def plot_cluster_mass(hfile, data_cluster_fname):
    plt.figure()
    mass = np.log10(hfile['cluster/sod_mass'])
    h, xbins = np.histogram(mass, bins=64, normed=True)
    plt.plot(dtk.bins_avg(xbins),
             h,
             '-o',
             label='Simulation [{:}]'.format(mass.size))
    print("reading the data...")
    rm_cluster_hfile = h5py.File(data_cluster_fname, 'r')
    print("Data has been opened")
    i = 0
    mass_redmapper = np.zeros(26110, dtype='f4')
    while i < 26110:
        mass_redmapper[i] = rm_cluster_hfile['gal_prop' + str(i)]['mass'].value
        i += 1
    h, xbins = np.histogram(np.log10(mass_redmapper), bins=xbins, normed=True)
    plt.plot(dtk.bins_avg(xbins),
             h,
             '-o',
             label='RedMapper [{:}]'.format(mass_redmapper.size))
    plt.yscale('log')
    plt.legend(loc='best', framealpha=0.3)
    plt.xlabel('Halo M$_{200c}$ [Msun/h]')
    plt.ylabel('Normalized Counts')
    plt.grid()
Exemplo n.º 2
0
def plot_core_dist(param_filename):
    cores = get_cores(param_filename)
    mass_bins = np.logspace(10, 15, 5)
    mass_bins_cen = dtk.bins_avg(mass_bins)
    r_bins = np.logspace(-4,0, 64)
    r_bins_cen = dtk.bins_avg(r_bins)
    colors = plt.cm.copper(np.linspace(0,1,len(mass_bins_cen)))
    fig = plt.figure()
    for i in range(0, len(mass_bins_cen)):
        slct = (cores['mass'] > mass_bins[i]) & (cores['mass'] < mass_bins[i+1])
        h, _ = np.histogram(cores['radius'][slct], bins=r_bins, density=True)
        label = r"${:.2e}<M_{{200}}<{:.2e}$".format(mass_bins[i], mass_bins[i+1])
        plt.semilogx(r_bins_cen, h, color=colors[i], label=label)
    if "qc" in param_filename:
        plt.title("QContinuum Cores")
    else:
        plt.title("Outer Rim Cores")
    plt.ylabel("PDF")
    plt.xlabel("Core Radius [Mpc/h]")

    cmap = plt.cm.copper
    norm = clr.LogNorm(vmin=mass_bins_cen[0], vmax=mass_bins_cen[-1])
    cax, _ = matplotlib.colorbar.make_axes(plt.gca())
    cb = matplotlib.colorbar.ColorbarBase(cax, cmap=cmap, norm=norm)
    cb.set_label('Infall Mass [Msun/h]')
    plt.show()
Exemplo n.º 3
0
def corner_plot_mcmc(labels,
                     mcmc_loc,
                     fig,
                     axs,
                     colors=['tab:blue', 'k', 'tab:red'],
                     plot_hist=True,
                     alpha=0.3):
    mcmc_m_i = dtk.gio_read(mcmc_loc, "mcmc_mass_infall")
    mcmc_r_d = dtk.gio_read(mcmc_loc, "mcmc_r_disrupt")
    mcmc_id = dtk.gio_read(mcmc_loc, "mcmc_walker_id")
    mcmc_step = dtk.gio_read(mcmc_loc, "mcmc_walker_step")
    mcmc_val = dtk.gio_read(mcmc_loc, "mcmc_value")
    size = len(labels)
    data = []
    slct = mcmc_step > np.max(mcmc_step) / 2.0
    data.append(np.log10(mcmc_m_i[slct]))
    data.append(mcmc_r_d[slct])
    best_fit_indx = np.argmin(mcmc_val[slct])
    #Diagonal Covariance
    for i in range(0, len(labels)):
        ax = axs[i][i]
        h, xbins = np.histogram(data[i], bins=50, density=True)
        ax.plot(dtk.bins_avg(xbins), h, c=colors[0])

        # Calculate 1 simga limits
        b1, b2 = get_bounds_limits(h, xbins, 0)
        b2 += 0
        b1 += 0
        b1a = b1 - 1
        ylim = ax.get_ylim()
        ax.fill_between(dtk.bins_avg(bbins[b1a:b2]),
                        0,
                        h[b1:b2],
                        lw=0.0,
                        alpha=alpha,
                        color=colors[0])
        ax.set_xlim(np.min(xbins), np.max(xbins))
        ax.set_ylim(ylim)  #restore old ylims before fill_bewteen
        ax.axvline(data[i][best_fit_indx], c=colors[2], ls='--')
    for i in range(size):
        for j in range(size):
            if i <= j:
                continue
            ax = axs[i][j]
            h, xbins, ybins = np.histogram2d(data[j], data[i], bins=50)
            if plot_hist:
                ax.pcolor(xbins, ybins, h.T, cmap='Greys')
            dtk.quick_contour(xbins,
                              ybins,
                              h,
                              ax=ax,
                              levels=(0.68, 0.87),
                              colors=colors[1],
                              label=False,
                              smoothen=False,
                              bins_edges=True)
            ax.axvline(data[j][best_fit_indx], c=colors[2], ls='--')
            ax.axhline(data[i][best_fit_indx], c=colors[2], ls='--')
            plt.sca(ax)
            plt.xticks(rotation=45)
Exemplo n.º 4
0
def plot_radial(clusters):
    plt.figure()
    h, xbins, ybins = np.histogram2d(clusters.core_dr_r200,
                                     clusters.core_r * 1000,
                                     bins=(np.linspace(0, 1.5, 100),
                                           np.logspace(0, 3, 100)))
    plt.pcolor(xbins, ybins, h.T, cmap='Blues', norm=clr.LogNorm())
    median = dtk.binned_median(clusters.core_dr_r200, clusters.core_r * 1000.0,
                               xbins)
    plt.plot(dtk.bins_avg(xbins), median, 'r', label='Median')
    plt.legend(loc='best', framealpha=0.0)
    plt.yscale('log')
    plt.ylabel('Core radius [h$^{-1}$ kpc]')
    plt.xlabel('r/R$_{200c}$')

    plt.figure()
    h, xbins, ybins = np.histogram2d(clusters.core_dr_r200,
                                     clusters.core_r * 1000,
                                     bins=(np.logspace(-3, 0, 100),
                                           np.logspace(0, 3, 100)))
    plt.pcolor(xbins, ybins, h.T, cmap='Blues', norm=clr.LogNorm())
    median = dtk.binned_median(clusters.core_dr_r200, clusters.core_r * 1000.0,
                               xbins)
    plt.plot(dtk.bins_avg(xbins), median, 'r', label='Median')
    plt.legend(loc='best', framealpha=0.0)
    plt.ylabel('Core radius [h$^{-1}$ kpc]')
    plt.xlabel('r/R$_{200c}$')
    plt.yscale('log')
    plt.xscale('log')

    plt.figure()
    h, xbins, ybins = np.histogram2d(clusters.core_dr_2d_r200,
                                     clusters.core_r * 1000,
                                     bins=(np.linspace(0, 1.5, 100),
                                           np.logspace(0, 3, 100)))
    plt.pcolor(xbins, ybins, h.T, cmap='Blues', norm=clr.LogNorm())
    median = dtk.binned_median(clusters.core_dr_2d_r200,
                               clusters.core_r * 1000.0, xbins)
    plt.plot(dtk.bins_avg(xbins), median, 'r', label='Median')
    plt.legend(loc='best', framealpha=0.0)
    plt.yscale('log')
    plt.ylabel('Core radius [h$^{-1}$ kpc]')
    plt.xlabel('r/R$_{200c}$')

    plt.figure()
    h, xbins, ybins = np.histogram2d(clusters.core_dr_2d_r200,
                                     clusters.core_r * 1000,
                                     bins=(np.logspace(-3, 0, 100),
                                           np.logspace(0, 3, 100)))
    plt.pcolor(xbins, ybins, h.T, cmap='Blues', norm=clr.LogNorm())
    median = dtk.binned_median(clusters.core_dr_2d_r200,
                               clusters.core_r * 1000.0, xbins)
    plt.plot(dtk.bins_avg(xbins), median, 'r', label='Median')
    plt.legend(loc='best', framealpha=0.0)
    plt.ylabel('Core radius [h$^{-1}$ kpc]')
    plt.xlabel('r/R$_{200c}$')
    plt.yscale('log')
    plt.xscale('log')
Exemplo n.º 5
0
def calc_wetzel09_disruption(param_fname):
    clusters, central = get_clusters(param_fname, core_host_mass=True)
    fit_mi, fit_rd = get_fit_param(param_fname)
    stepz = dtk.StepZ(sim_name='AlphaQ')
    z = stepz.get_z(401)
    print(z)
    core_t_dyn = wetzel09_disruption_time(0.25, clusters.core_m,
                                          clusters.core_host_mass, z)
    print(core_t_dyn)
    plt.figure()
    lg_min = np.min(np.log10(core_t_dyn))
    lg_max = np.max(np.log10(core_t_dyn))
    print(lg_min, lg_max)
    xbins = np.logspace(lg_min, lg_max, 10)
    print(xbins)
    xbins_cen = dtk.log_bins_avg(xbins)
    h, _ = np.histogram(core_t_dyn, bins=xbins)
    plt.loglog(
        xbins_cen,
        h,
    )

    plt.figure()
    plt.hist2d(np.log10(clusters.core_m),
               np.log10(clusters.core_host_mass),
               bins=100,
               cmap='Blues',
               norm=clr.LogNorm())

    plt.figure()
    h, xbins = np.histogram(np.log10(clusters.core_host_mass /
                                     clusters.core_m),
                            bins=100)
    xbins_cen = dtk.bins_avg(xbins)
    plt.plot(xbins_cen, h, label='All Cores')

    plt.xlabel('log10(Mhost/Msat)')
    plt.ylabel('Counts')

    if fit_mi < 1e3:
        fit_mi = 10**fit_mi
    slct = clusters.core_m > fit_mi
    h, xbins = np.histogram(np.log10(clusters.core_host_mass[slct] /
                                     clusters.core_m[slct]),
                            bins=100)
    xbins_cen = dtk.bins_avg(xbins)
    plt.plot(xbins_cen, h, label='>M_infall')

    slct = (clusters.core_m > fit_mi) & (clusters.core_r < fit_rd)
    h, xbins = np.histogram(np.log10(clusters.core_host_mass[slct] /
                                     clusters.core_m[slct]),
                            bins=100)
    xbins_cen = dtk.bins_avg(xbins)
    plt.plot(xbins_cen, h, label='Fit Cores')

    plt.legend(loc='best')
Exemplo n.º 6
0
def plot_core_abundance(param_fname):
    param = dtk.Param(param_fname)
    cores = load_cores(param.get_string("core_loc"), param.get_int("step"))
    core_num = len(cores['infall_mass'])
    h, xbins, ybins = np.histogram2d(np.log10(cores['infall_mass']),
                                     np.log10(cores['radius']),
                                     bins=128)
    plt.figure()
    plt.pcolor(xbins, ybins, h.T, cmap="Blues", norm=clr.LogNorm())
    plt.ylabel("Log10 Core Radius")
    plt.xlabel("Log10 Infall Mass")

    h_sum = np.cumsum(h, axis=1)
    # h_sum = h_sum[-1,:] - h_sum
    # h_sum = h_sum.T
    plt.figure()
    plt.pcolor(xbins, ybins, h_sum.T, cmap="Blues", norm=clr.LogNorm())
    plt.ylabel("Log10 Core Radius")
    plt.xlabel("Log10 Infall Mass")

    h_sum2 = np.cumsum(h_sum, axis=0)
    h_sum2 = h_sum2[-1, :] - h_sum2
    plt.figure()
    plt.pcolor(xbins, ybins, h_sum2.T, cmap="Blues", norm=clr.LogNorm())
    plt.contour(dtk.bins_avg(xbins), dtk.bins_avg(ybins), h_sum2.T)
    plt.ylabel("Log10 Core Radius")
    plt.xlabel("Log10 Infall Mass")

    plt.figure()
    plt.pcolor(xbins, ybins, h_sum2.T, cmap="Blues", norm=clr.LogNorm())
    plt.contour(dtk.bins_avg(xbins),
                dtk.bins_avg(ybins),
                h_sum2.T / (500 * 500 * 500),
                levels=[0.0010, 0.0015, 0.002])
    plt.ylabel("Log10 Core Radius")
    plt.xlabel("Log10 Infall Mass")

    plt.figure()
    percentiles = [10, 20, 30, 40, 50, 60, 70, 80, 90]
    result1 = dtk.binned_percentile(np.log10(cores['infall_mass']),
                                    np.log10(cores['radius']),
                                    xbins,
                                    percentiles,
                                    minimum_number=100)
    print(result1.shape)
    plt.pcolor(xbins, ybins, h.T, cmap="Blues", norm=clr.LogNorm())
    plt.colorbar(label='Population Density')
    plt.plot(12.25, np.log10(0.05), "*", label='model fit')
    for i, percentile in enumerate(percentiles):
        plt.plot(dtk.bins_avg(xbins),
                 result1[:, i],
                 '-',
                 label="{}%".format(percentile))

    plt.legend(loc='best', framealpha=0)
    plt.show()
Exemplo n.º 7
0
def plot_cluster_cores2(hfile, mass_cuts, bins=100, log=False):
    print(hfile['cores'].keys())
    core_m = np.log10(hfile['cores']['core_m'].value)
    core_r = hfile['cores']['core_r'].value
    core_c = hfile['cores']['core_is_central'].value
    core_step = hfile['cores']['core_step'].value
    slct_sat = core_step != 401
    print(np.unique(core_step))
    xbins = 10**np.linspace(np.min(np.log10(core_r)), np.max(np.log10(core_r)),
                            100)
    plt.figure()
    h, xbins = np.histogram(core_r[slct_sat], bins=xbins, density=False)
    plt.plot(dtk.bins_avg(xbins), h, label='All')
    for mass_cut in mass_cuts:
        slct = core_m > mass_cut
        h, xbins = np.histogram(core_r[slct & slct_sat],
                                bins=xbins,
                                density=False)
        plt.plot(dtk.bins_avg(xbins),
                 h,
                 label='M_infall > {}'.format(mass_cut))
    plt.legend(loc=2, framealpha=0.3)
    plt.yscale('log')
    plt.xscale('log')
    plt.xlabel('Core Radius [Mpc/h]')
    plt.ylabel('Counts')
    plt.title("Satellite Cores")
    plt.figure()
    h, xbins = np.histogram(core_r[slct_sat], bins=xbins)
    xbins_log = np.log10(xbins)
    xbins_width = (xbins_log[1:] - xbins_log[:-1])
    plt.plot(dtk.bins_avg(xbins), h / xbins_width / np.sum(h), label='All')
    for mass_cut in mass_cuts:
        slct = core_m > mass_cut
        h, xbins = np.histogram(core_r[slct & slct_sat], bins=xbins)
        plt.plot(dtk.bins_avg(xbins),
                 h / xbins_width / np.sum(h),
                 label='M_infall > {}'.format(mass_cut))
    plt.legend(loc=2, framealpha=0.3)
    plt.xscale('log')
    plt.xlabel('Core Radius [Mpc/h]')
    plt.ylabel('Normalized Population Density')
    plt.title("Satellite Cores")

    plt.figure()
    h, xxbins, yybins = np.histogram2d(core_m[slct_sat],
                                       np.log10(core_r[slct_sat]),
                                       bins=100)
    plt.pcolor(xxbins, yybins, h.T, cmap='Blues', norm=clr.LogNorm())
    plt.grid()
    plt.ylabel('Core Radius [log10 Mpc/h]')
    plt.xlabel('M_infall [log10 Msun/h]')
    plt.title("Satellite Cores")
Exemplo n.º 8
0
def plot_mass_function(param_filename):
    cluster_data = ClusterData(param_filename)
    mass_bins = np.logspace(14, 16, 16)
    mass_bins_cen = dtk.bins_avg(mass_bins)
    h, _ = np.histogram(clusters.mass, bins=mass_bins)
    plt.figure()
    plt.plot(mass_bins_cen, h)
Exemplo n.º 9
0
def plot_hist(
    data,
    bins,
    style='-',
    label=None,
):
    h, xbins = np.histogram(data, bins=bins)
    bins_cen = dtk.bins_avg(xbins)
    plt.plot(bins_cen, h, style, label=label)
Exemplo n.º 10
0
def check_error_zmr(param_fname):
    zmr = load_zmr(param_fname)
    mass_bins = zmr['m_bins'].value
    r_bins = zmr['r_bins'].value
    r_bins_center = dtk.bins_avg(r_bins)
    for i in range(0, len(mass_bins) - 1):
        if zmr['zm_counts'][0][i] > 1:
            print("\n{:.2e} < M200 < {:.2e} ".format(mass_bins[i],
                                                     mass_bins[i + 1]))
            print("counts: ", zmr['zmr_counts'][0][i][:])
            print("density:", zmr['zmr_gal_density'][0][i][:])
            print("error:  ", zmr['zmr_gal_density_err'][0][i][:])
def plot_luminosity_dependence_survival_single(mstars, param_base, color, title=None):
    param_fnames = [param_base.replace("@val@", str(mstar)) for mstar in mstars]
    fits = load_fit_limits_set(param_fnames)
    mass_bins_list = [ ZMR('output/'+param_fname+'/zmr_lkhd_cores.param').m_bins for param_fname in param_fnames]
    survival_infos = [ get_survival_rate(param_fname, fit, mass_bins) for param_fname, fit, mass_bins in zip(param_fnames, fits, mass_bins_list)]
    colors = ['r', 'b', 'g', 'c']
    labels_dict = {-1: "2.50~L$_*$", 
              0: "1.00~L$_*$", 
              0.5: "0.63~L$_*$", 
              1: "0.40~L$_*$"}
    labels = [ labels_dict[mstar] for mstar in mstars ]
    x_centers = dtk.bins_avg(mass_bins)
    survival_rate = []
    survival_rate_err = []
    for survival_info, mass_bins, label, color in zip(survival_infos, mass_bins_list, labels, colors):
        print(label, survival_info[0])
        plt.plot(dtk.bins_avg(mass_bins), survival_info[0],  label=label, color=color)
        plt.fill_between(dtk.bins_avg(mass_bins), survival_info[0]+survival_info[1], survival_info[0]-survival_info[1], color=color, alpha=0.3)
        survival_rate.append(survival_info[0])
        survival_rate_err.append(survival_info[1])
    
    return x_centers, survival_rate, survival_rate_err
def plot_luminosity_dependent_ngal_all(param_file, title=None):
    param = dtk.Param(param_file)
    sdss_zmr_loc = param.get_string('zmrh5_loc')
    print(sdss_zmr_loc)
    hfile = h5py.File(sdss_zmr_loc, 'r')
    zmr_sdss = ZMR(file_loc="output/"+param_file+"/zmr_sdss.param")
    if dtk.file_exists("output/"+param_file+"/zmr_lkhd_cores.param"):
        fname = "output/"+param_file+"/zmr_lkhd_cores.param"
        zmr_cores = ZMR(file_loc=fname)
        print("likelihood zmrs")
    else:
        fname = "output/"+param_file+"/zmr_cores.param"
        zmr_cores = ZMR(file_loc=fname)
        print("fit zmrs")

    mass_bins = zmr_cores.m_bins 
    mass_bins_centers = dtk.bins_avg(mass_bins)
    zmr_Ngal = zmr_cores.zmr_gal_counts[0].sum(axis=1)/zmr_cores.zm_counts[0]
Exemplo n.º 13
0
def plot_cluster_redshift(core_redshift, data_cluster_fname):
    plt.figure()
    print("reading the data...")
    rm_cluster_hfile = h5py.File(data_cluster_fname, 'r')
    print("Data has been opened")
    i = 0
    redshift_redmapper = np.zeros(26110, dtype='f4')
    while i < 26110:
        redshift_redmapper[i] = rm_cluster_hfile['gal_prop' +
                                                 str(i)]['z'].value
        i += 1
    h, xbins = np.histogram(redshift_redmapper, bins=np.linspace(0, 0.6, 100))
    plt.plot(dtk.bins_avg(xbins),
             h,
             '-',
             label='RedMapper [{:}]'.format(redshift_redmapper.size))
    plt.axvline(core_redshift, ls='--', c='r', label='Core Redshift')
    plt.yscale('log')
    plt.legend(loc='best', framealpha=0.3)
    plt.xlabel('redshift')
    plt.ylabel('Counts')
    plt.grid()
Exemplo n.º 14
0
def compare_z_dep(param_fname):
    param = dtk.Param(param_fname)
    result_folder = param.get_string('result_folder')
    hfile = h5py.File(result_folder + 'type1_weight1_mag1_clr1_result.hdf5',
                      'r')

    zmr = hfile['zmr_gal_density'][()]
    zmr_err = hfile['zmr_gal_density_err'][()]
    zmr_cnt = hfile['zmr_counts'][()]
    r_bins = hfile['r_bins'][()]
    r_bins_cen = dtk.bins_avg(r_bins)
    z_bins = hfile['z_bins'][()]
    print(r_bins_cen)

    shape = zmr.shape
    for i in range(shape[1]):
        if not np.isfinite(np.sum(zmr[0, i, :])):
            continue
        plt.figure()
        for j in range(shape[0]):
            plt.plot(r_bins_cen,
                     zmr[j, i, :],
                     label='{:.2f}<z<{:.2f}'.format(z_bins[j], z_bins[j + 1]))
            plt.fill_between(r_bins_cen,
                             zmr[j, i, :] + zmr_err[j, i, :],
                             zmr[j, i, :] - zmr_err[j, i, :],
                             alpha=0.3)

        print(np.sum(zmr_cnt[0, i, :]), np.sum(zmr_cnt[1, i, :]),
              np.nanmean(np.sum(zmr_cnt[0, i, :]) / np.sum(zmr_cnt[1, i, :])))
        print(zmr[0, i, :])
        print(zmr[1, i, :])
        print(np.nanmean(zmr[0, i, :] / zmr[1, i, :]))
        print('\n')
        plt.yscale('log')
        plt.legend()
        np.log10(np.nanmean(zmr[0, i, :] / zmr[1, i, :]))
        plt.show()
Exemplo n.º 15
0
def plot_multiple_model_profiles_one_mass(sdss_zmr, model_zmrs, model_names, mass_i, spider_zmr=None):
    plt.figure()
    model_size = len(model_zmrs)
    colors = ['tab:blue', 'tab:orange', 'tab:green', 'tab:purple']
    for i in range(0, model_size):
        gal_density = model_zmrs[i].zmr_gal_density[0, mass_i, :]
        gal_density_err = model_zmrs[i].zmr_gal_density_err[0, mass_i, :]
        r_bins_cen = dtk.bins_avg(model_zmrs[i].r_bins)
        plt.plot(r_bins_cen, gal_density, label=model_names[i], color=colors[i], lw=2)
        plt.fill_between(r_bins_cen, gal_density-gal_density_err, gal_density+gal_density_err, color=colors[i], alpha=0.2)

    sdss_gal = sdss_zmr.zmr_gal_density[0, mass_i, :]
    sdss_gal_err = sdss_zmr.zmr_gal_density_err[0, mass_i, :]
    # plt.plot(r_bins_cen, sdss_zmr.zmr_gal_density[0, mass_i, :], 'k', label='SDSS', lw=2)
    # plt.fill_between(r_bins_cen, sdss_gal-sdss_gal_err, sdss_gal+sdss_gal_err, color='k', alpha=0.2)

    #offset for sdss vs spiders
    if spider_zmr is None: 
        offset = 0
    else:
        offset = .005
    plt.errorbar(r_bins_cen-offset, sdss_gal, yerr=+sdss_gal_err, fmt='o',
                 label='redMaPPer clusters', lw=2, color='k', capsize=0,
                 )
    if spider_zmr is not None:
        spider_gal = spider_zmr.zmr_gal_density[0, mass_i, :]
        spider_gal_err = spider_zmr.zmr_gal_density_err[0, mass_i, :]
        plt.errorbar(r_bins_cen+offset, spider_gal, yerr=+spider_gal_err, fmt='o',
                     label='SPIDERS clusters', lw=1, color='k', capsize=0, markerfacecolor='None')
       
    plt.yscale('log')
    plt.legend(loc='best', framealpha=0.0, ncol=2)
    title = r"{:.2f}$<$log$_{{10}}$(M$_{{200m}}$)$<${:.2f}".format(np.log10(sdss_zmr.m_bins[mass_i]), np.log10(sdss_zmr.m_bins[mass_i+1]))
    # plt.title(title)
    plt.text(0.05, 0.05, title, transform=plt.gca().transAxes)
    plt.xlabel(r'r/R$_{200}$')
    plt.ylabel(r"Galaxy Surface Density")
    plt.tight_layout()
def plot_multiple_model_profiles_one_mass(sdss_zmr, model_zmrs, model_names, mass_i):
    plt.figure()
    model_size = len(model_zmrs)
    colors = ['r', 'b', 'g', 'c']
    for i in range(0, model_size):
        gal_density = model_zmrs[i].zmr_gal_density[0, mass_i, :]
        gal_density_err = model_zmrs[i].zmr_gal_density_err[0, mass_i, :]
        r_bins_cen = dtk.bins_avg(model_zmrs[i].r_bins)
        plt.plot(r_bins_cen, gal_density, label=model_names[i], color=colors[i])
        plt.fill_between(r_bins_cen, gal_density-gal_density_err, gal_density+gal_density_err, color=colors[i], alpha=0.3)
    sdss_gal = sdss_zmr.zmr_gal_density[0, mass_i, :]
    sdss_gal_err = sdss_zmr.zmr_gal_density_err[0, mass_i, :]
    print(np.shape(sdss_gal))
    print(np.shape(sdss_gal_err))
    plt.plot(r_bins_cen, sdss_zmr.zmr_gal_density[0, mass_i, :], 'k', label='SDSS', lw=2)
    plt.fill_between(r_bins_cen, sdss_gal-sdss_gal_err, sdss_gal+sdss_gal_err, color='k', alpha=0.3)
    plt.yscale('log')
    plt.legend(loc='best')
    title = r"{:.2f}$<$log$_{{10}}$(M$_{{200m}}$)$<${:.2f}".format(np.log10(sdss_zmr.m_bins[i]), np.log10(sdss_zmr.m_bins[i+1]))
    # plt.title(title)
    plt.text(0.5, 0.9, title, horizontalalignment='center',
         verticalalignment='center', transform=plt.gca().transAxes)
    plt.xlabel(r'r/R$_{200}$')
    plt.ylabel(r"Galaxy Surface Density")
Exemplo n.º 17
0
def plot_zmr(param_fname):
    zmr = load_zmr(param_fname)
    mass_bins = zmr['m_bins'].value
    r_bins = zmr['r_bins'].value
    r_bins_center = dtk.bins_avg(r_bins)
    plt.figure()
    colors = ['b', 'g', 'r', 'c', 'm']
    for i in range(0, len(mass_bins) - 1):
        if zmr['zm_counts'][0][i] > 2:
            rad_profile = zmr['zmr_gal_density'].value[0, i]
            rad_profile_err = zmr['zmr_gal_density_err'].value[0, i]
            label = "--"  #"{:.2f} < log$_{{10}}$ M$_{{200c}}$ < {:.2f}".format(np.log(mass_bins[i]), np.log(mass_bins[i+1]))
            label = "{:.2f} $<$ log$_{{10}}$ M$_{{200c}}$ $<$ {:.2f}".format(
                np.log10(mass_bins[i]), np.log10(mass_bins[i + 1]))
            plt.errorbar(r_bins_center,
                         rad_profile,
                         yerr=rad_profile_err,
                         fmt='-o',
                         markeredgecolor='none',
                         label=label,
                         markerfacecolor=colors[i],
                         color=colors[i],
                         capsize=0)
            yerr_min = np.clip(rad_profile - rad_profile_err,
                               a_max=np.inf,
                               a_min=1e-3)
            plt.fill_between(r_bins_center,
                             rad_profile + rad_profile_err,
                             yerr_min,
                             color=colors[i],
                             alpha=0.3)
    plt.legend(loc='best', framealpha=0.0)
    plt.yscale('log')
    plt.xlabel('r/R$_{200c}$')
    plt.ylabel('$\Sigma_{galaxy} [(R_{200c})^{-2}$]')
    dtk.save_figs("figs/" + param_fname + "/" + __file__ + "/")
Exemplo n.º 18
0
def plot_profile(clusters):
    m_bins = np.logspace(14, 16, 9)
    cluster_mass_bin_count, _ = np.histogram(clusters.mass, bins=m_bins)
    print(cluster_mass_bin_count)
    slct_mass = (clusters.core_host_mass >
                 m_bins[0]) & (clusters.core_host_mass < m_bins[1])
    print(clusters.core_host_mass)
    print(np.sum(slct_mass))
    print(np.log10(m_bins))

    slct = slct_mass
    r_bins = np.linspace(0, 1, 32)
    r_bins_area = np.diff(r_bins**2 * np.pi)
    r_bins_volume = np.diff(r_bins**3 * 4.0 / 3.0 * np.pi)

    h2d, _ = np.histogram(clusters.core_dr_2d_r200[slct], bins=r_bins)
    h3d, _ = np.histogram(clusters.core_dr_r200[slct], bins=r_bins)
    # plt.figure()
    # plt.plot(dtk.bins_avg(r_bins), h2d/r_bins_area, '-')
    # plt.yscale('log')

    # plt.figure()
    # plt.plot(dtk.bins_avg(r_bins), h3d/r_bins_volume, '-')
    # plt.yscale('log')

    num_bins = 10
    color_map = plt.cm.coolwarm
    color_map_r = plt.cm.coolwarm_r
    colors = color_map(np.linspace(0, 1, num_bins))
    sm = plt.cm.ScalarMappable(cmap=color_map,
                               norm=clr.LogNorm(vmin=1e11, vmax=1e13))
    cluster_m_cut_count = np.sum((clusters.mass > m_bins[0])
                                 & (clusters.mass < m_bins[1]))
    sm._A = []
    plt.figure()
    for i, m_cut in enumerate(np.logspace(11, 13, num_bins)):
        slct_m_cut = clusters.core_m > m_cut
        h, _ = np.histogram(clusters.core_dr_r200[slct & slct_m_cut],
                            bins=r_bins)
        label = r'M$_{{infall}} >$ {:.2e}, reduction: {:.2e}'.format(
            m_cut,
            np.float(np.sum(h)) / np.sum(h3d))
        plt.plot(dtk.bins_avg(r_bins),
                 h / r_bins_volume / cluster_m_cut_count,
                 '-',
                 label=label,
                 color=colors[i])
        print(label)
    cb = plt.colorbar(sm)
    cb.set_label('M$_{infall}$')
    plt.yscale('log')
    plt.ylabel('Galaxy Density [R$_{200c}$$^{-3}$]')
    plt.xlabel('r/R$_{200c}$')
    plt.tight_layout()
    print('===')
    plt.figure()
    for i, m_cut in enumerate(np.logspace(11, 13, num_bins)):
        slct_m_cut = clusters.core_m > m_cut
        h, _ = np.histogram(clusters.core_dr_2d_r200[slct & slct_m_cut],
                            bins=r_bins)
        label = r'M$_{{infall}} >$ {:.2e}, reduction: {:.2e}'.format(
            m_cut,
            np.float(np.sum(h)) / np.sum(h2d))
        plt.plot(dtk.bins_avg(r_bins),
                 h / r_bins_area / cluster_m_cut_count,
                 '-',
                 label=label,
                 color=colors[i])
        print(label)
    cb = plt.colorbar(sm)
    cb.set_label('M$_{infall}$')
    plt.yscale('log')
    plt.ylabel('Galaxy Surface Density [R$_{200c}$$^{-2}$]')
    plt.xlabel('r/R$_{200c}$')
    plt.tight_layout()

    print("\n\n")
    slct_m_infall = clusters.core_m > -1

    colors = color_map_r(np.linspace(0, 1, num_bins))
    vmin = 10**-2
    vmax = 0.3
    sm = plt.cm.ScalarMappable(cmap=color_map_r,
                               norm=clr.LogNorm(vmin=vmin, vmax=vmax))
    sm._A = []
    plt.figure()
    for i, r_cut in enumerate(
            np.logspace(np.log10(vmin), np.log10(vmax), num_bins)):
        slct_r_cut = clusters.core_r < r_cut
        h, _ = np.histogram(clusters.core_dr_r200[slct & slct_r_cut
                                                  & slct_m_infall],
                            bins=r_bins)
        label = r'R$_{{disrupt}} <$ {:.2e}, reduction: {:.2e}'.format(
            r_cut,
            np.float(np.sum(h)) / np.sum(h2d))
        plt.plot(dtk.bins_avg(r_bins),
                 h / r_bins_volume / cluster_m_cut_count,
                 '-',
                 label=label,
                 color=colors[i])
        print(label)
    plt.yscale('log')
    cb = plt.colorbar(sm)
    cb.set_label('R$_{disrupt}$')
    plt.ylabel('Galaxy Density [R$_{200c}$$^{-3}$]')
    plt.xlabel('r/R$_{200c}$')
    plt.tight_layout()
    print('===')
    plt.figure()
    for i, r_cut in enumerate(
            np.logspace(np.log10(vmin), np.log10(vmax), num_bins)):
        slct_r_cut = clusters.core_r < r_cut
        h, _ = np.histogram(clusters.core_dr_2d_r200[slct & slct_r_cut
                                                     & slct_m_infall],
                            bins=r_bins)
        label = r'R$_{{disrupt}} <$ {:.2e}, reduction: {:.2e}'.format(
            r_cut,
            np.float(np.sum(h)) / np.sum(h2d))
        plt.plot(dtk.bins_avg(r_bins),
                 h / r_bins_area / cluster_m_cut_count,
                 '-',
                 label=label,
                 color=colors[i])
        print(label)
    plt.yscale('log')
    cb = plt.colorbar(sm)
    cb.set_label('R$_{disrupt}$')
    plt.ylabel('Galaxy Surface Density [R$_{200c}$$^{-2}$]')
    plt.xlabel('r/R$_{200c}$')
    plt.tight_layout()

    print("\n\n")

    number_tot = 10
    colors = color_map(np.linspace(0, 1, number_tot))
    vmin = 1e-3
    vmax = 1e-1
    sm = plt.cm.ScalarMappable(cmap=color_map,
                               norm=clr.LogNorm(vmin=vmin, vmax=vmax))
    sm._A = []
    # f, ax = plt.subplots()
    f_2d, ax_2d = plt.subplots()
    f_3d, ax_3d = plt.subplots()
    for i, r_merger in enumerate(
            np.logspace(np.log10(vmin), np.log10(vmax), number_tot)):
        # effectively no mass cut and radius cut n2 merger of cores
        clusters2 = clusters.create_compute_r_merger(0,
                                                     1e12,
                                                     r_merger,
                                                     clusters_number=-1)
        clusters2.set_host_halo_mass()
        clusters2.set_core_radial_distance(write_cache=False, force=True)
        slct_mass = (clusters2.core_host_mass >
                     m_bins[0]) & (clusters2.core_host_mass < m_bins[1])
        h_2d, _ = np.histogram(clusters2.core_dr_2d_r200[slct_mass],
                               bins=r_bins)
        h_3d, _ = np.histogram(clusters2.core_dr_r200[slct_mass], bins=r_bins)
        label = r'R$_{{merge}} <$ {:.2e}, reduction: {:.2e}'.format(
            r_merger,
            np.float(np.sum(h_2d)) / np.sum(h2d))
        print(label)
        ax_2d.plot(dtk.bins_avg(r_bins),
                   h_2d / r_bins_area / cluster_m_cut_count,
                   '-',
                   label=label,
                   color=colors[i])
        ax_3d.plot(dtk.bins_avg(r_bins),
                   h_3d / r_bins_volume / cluster_m_cut_count,
                   '-',
                   label=label,
                   color=colors[i])
    for fig, ax in [(f_2d, ax_2d), (f_3d, ax_3d)]:
        ax.set_yscale('log')
        cb = fig.colorbar(sm)
        cb.set_label('R$_{merge}$')
        if ax == ax_2d:
            ax.set_ylabel('Galaxy Surface Density [R$_{200c}$$^{-2}$]')
        else:
            ax.set_ylabel('Galaxy Density [R$_{200c}$$^{-3}$]')
        ax.set_xlabel('r/R$_{200c}$')
        fig.tight_layout()
Exemplo n.º 19
0
import dtk

hfile = h5py.File('output/mock_full_nocut_dust_elg_shear3_mod.hdf5', 'r')

conv = hfile['galaxyProperties/convergence'].value
mag = hfile['galaxyProperties/magnification'].value
shear1 = hfile['galaxyProperties/shear1'].value
shear2 = hfile['galaxyProperties/shear2'].value
ra = hfile['galaxyProperties/ra'].value
dec = hfile['galaxyProperties/dec'].value
conv_new = 1.0 - np.sqrt(1.0 / mag + shear1**2 + shear2**2)
print conv_new
xbins = np.linspace(-.05, .1, 100)
plt.figure()
h, xbins = np.histogram(conv, bins=xbins)
plt.plot(dtk.bins_avg(xbins), h, '-', label='old')
h, xbins = np.histogram(conv_new, bins=xbins)
plt.plot(dtk.bins_avg(xbins), h, '-', label='new')
plt.legend(loc='best')

print np.min(mag), np.max(mag)

plt.figure()
slct = mag < 0.5
xbins = np.linspace(-.1, 0.5, 100)
h, xbins = np.histogram(mag[slct], bins=xbins)
plt.plot(dtk.bins_avg(xbins), h)

plt.figure()
plt.plot(ra[slct], dec[slct], '.', alpha=0.3)
plt.show()
Exemplo n.º 20
0
def get_ngal_fit(param_fname,
                 cluster_num,
                 color,
                 plot_fit=True,
                 spider=False,
                 manual_calc=False):
    param = dtk.Param(param_fname)
    cluster_loc = param.get_string('cluster_loc')
    if cluster_num is None:
        cluster_num = param.get_int('cluster_load_num')
    zmrh5_loc = param.get_string('zmrh5_loc')
    zmr_sdss = ZMR(zmrh5_loc)
    zmr_fit = ZMR("output/" + param_fname + "/zmr_lkhd_cores.param")
    m_bins = zmr_fit.m_bins
    r_bins = zmr_fit.r_bins
    zmr_core_ngal, zmr_core_ngal_err = zmr_fit.get_ngal(
    )  # only one z-bin, so we don't select it out
    zmr_core_ngal = zmr_core_ngal[0]
    zmr_core_ngal_err = zmr_core_ngal_err[0]
    zmr_sdss_ngal, zmr_sdss_ngal_err = zmr_sdss.get_ngal()
    zmr_sdss_ngal = zmr_sdss_ngal[0]
    zmr_sdss_ngal_err = zmr_sdss_ngal_err[0]

    if manual_calc:
        model_fit_fname = "figs/" + param_fname + "/calc_likelihood_bounds.py/grid_fit_param.txt"
        model_fit = load_fit_limits(model_fit_fname)
        m_infall = 10**model_fit['mi']
        if 'rd' in model_fit:
            # print(model_fit['rd'])
            r_disrupt = model_fit['rd'] / 1000.0  #convert to mpc/h from kpc/h
        else:
            r_disrupt = np.inf
        # print("\ncalculating ngal for ", param_fname)
        # print("\tmodel_fit_fname:", model_fit_fname)
        # print("\tmodel params: {:.2e} {:.3f}".format(m_infall, r_disrupt))
        print(cluster_loc)
        cluster_data = load_clusters(cluster_loc)
        if cluster_num == -1:
            cluster_num = cluster_data.num
        cluster_ngal = np.zeros(cluster_num)
        cluster_m_i = np.zeros(cluster_num)
        for i in range(0, cluster_num):
            mass_index = cluster_data.get_cluster_mass_bin(i, m_bins)
            cluster_m_i[i] = mass_index
            cluster_ngal[i] = cluster_data.get_ngal(i, m_infall, r_disrupt)[1]
        ngal_mean = np.zeros(len(m_bins) - 1)
        ngal_err = np.zeros(len(m_bins) - 1)
        ngal_std = np.zeros(len(m_bins) - 1)
        for i in range(0, len(m_bins) - 1):
            slct = cluster_m_i == i
            ngal_mean[i] = np.mean(cluster_ngal[slct])
            ngal_std[i] = np.std(cluster_ngal[slct])
            ngal_err[i] = ngal_std[i] / np.sqrt(np.sum(slct))
            # print("{:.2e}->{:.2e}: {}".format(m_bins[i], m_bins[i+1], np.sum(slct)))
        plt.plot(dtk.bins_avg(m_bins),
                 ngal_mean,
                 '-x',
                 color=color,
                 label='Ngal recalc')
    if plot_fit:
        plt.plot(dtk.bins_avg(m_bins), zmr_core_ngal, '-', color=color)
        plt.fill_between(dtk.bins_avg(m_bins),
                         zmr_core_ngal - zmr_core_ngal_err,
                         zmr_core_ngal + zmr_core_ngal_err,
                         color=color,
                         alpha=0.3)
    offset_amount = 1.025
    if spider:
        markerfacecolor = 'None'
        markeredgecolor = color
        xaxis_offset = offset_amount
        lw = 1
    else:
        markerfacecolor = color
        markeredgecolor = 'None'
        xaxis_offset = 1. / offset_amount
        lw = 2

    # remove problematic 2.5 L* low mass cluster in the spider sample
    if "mstar-1" in param_fname and "spider" in param_fname:
        print("SPIDERSS!: ", zmr_sdss_ngal)
        zmr_sdss_ngal[zmr_sdss_ngal < 0.1] = np.nan
    plt.errorbar(dtk.bins_avg(m_bins) * xaxis_offset,
                 zmr_sdss_ngal,
                 yerr=zmr_sdss_ngal_err,
                 fmt='o',
                 capsize=0,
                 lw=lw,
                 color=color,
                 markeredgecolor=markeredgecolor,
                 markerfacecolor=markerfacecolor)
    # plt.fill_between(dtk.bins_avg(m_bins), ngal_mean-ngal_err, ngal_mean+ngal_err, color=color, alpha=0.3)
    plt.yscale('log')
    plt.xscale('log')
Exemplo n.º 21
0
def calc_ngal(param_fname):
    clusters, central = get_clusters(param_fname)
    fit_mi, fit_rd = get_fit_param(param_fname)
    # print(fit_fname)
    ngals = []
    ngals_proj = []
    masses = []
    print(clusters.num)
    for i in range(0, clusters.num):
        ngal, ngal_proj = clusters.get_ngal(i,
                                            fit_mi,
                                            fit_rd,
                                            compact_central=central)
        masses += [clusters.mass[i]]
        ngals += [ngal]
        ngals_proj += [ngal_proj]
    masses = np.array(masses)
    ngals = np.array(ngals)
    ngals_proj = np.array(ngals_proj)
    xbins = np.logspace(14, 15.5, 32)
    xbins_cen = dtk.bins_avg(xbins)
    plt.figure()
    # plt.plot(masses, ngals, ',b', alpha=0.01, label = 'Ngal')
    # plt.plot(masses, ngals_proj, ',g', alpha=0.01, label='Projected Ngal')
    ngal_avg = dtk.binned_average(masses, ngals, xbins)
    ngal_proj_avg = dtk.binned_average(masses, ngals_proj, xbins)

    plt.plot(xbins_cen, ngal_avg, 'b', lw=2, label="Core Ngal")
    plt.plot(xbins_cen,
             ngal_proj_avg,
             'g',
             lw=2,
             label="Core Ngal Avg Projected")
    plt.xscale('log')
    plt.yscale('log')

    ylim = plt.ylim()
    xlim = plt.xlim()
    mr_upper, mr_lower = get_mr_limits(param_fname)
    mass = np.logspace(11, 15.5, 100)
    model_lower = get_zeng07_hod(mr_lower)
    hod_tot_lower = model_lower.hod(mass)
    plt.plot(mass,
             hod_tot_lower,
             '--r',
             lw=1,
             label="Mr<{:.1f} HOD".format(mr_lower))
    model_upper = get_zeng07_hod(mr_upper)
    hod_tot_upper = model_upper.hod(mass)
    plt.plot(mass,
             hod_tot_upper,
             'r--',
             lw=1,
             label="Mr<{:.1f} HOD".format(mr_upper))
    plt.plot(mass,
             calc_log_mean(hod_tot_lower, hod_tot_upper),
             'r',
             label='Mr<{:.1f} HOD'.format((mr_upper + mr_lower) / 2.0))
    plt.legend(loc='best')

    plt.xlim(xlim)
    plt.ylim(ylim)

    plt.show()
Exemplo n.º 22
0
def convert_halo_m200c_to_m200m( sod_location, sod_output, time_step, redshift , h_scaling, write_catalog=False):
    a = 1.0/(1.0+redshift)
    # rho_mean = get_rho_mean_over_rho_crit(redshift)
    
    # This catalog has h=0.7
    cat = load_halo_cat(sod_location.replace("${step}", str(time_step)), h_scaling)

    M200m_col, R200m_col, c200m_col = mass_adv.changeMassDefinitionCModel(cat['sod_halo_mass']/0.7, redshift,
                                                                          "200c","200m", c_model='child18')#cat['sod_cdelta']
    M200c_col, R200c_col, c200c_col = mass_adv.changeMassDefinitionCModel(cat['sod_halo_mass']/0.7, redshift,
                                                                          "200c","200c", c_model='child18')#cat['sod_cdelta']
    R_200m = R200m_col/1000.0/0.7
    M_200m = M200m_col*0.7

    R_200c = R200c_col/1000.0/0.7
    M_200c = M200c_col*0.7

    cat['sod_halo_radius_r200m'] = R_200m*a
    cat['sod_halo_mass_m200m']   = M_200m
    cat['sod_halo_cdelta_200m']  = c200m_col

    cat['sod_halo_radius_r200c'] = R_200c*a
    cat['sod_halo_mass_m200c']   = M_200c
    cat['sod_halo_cdelta_200c']  = c200c_col


    if( write_catalog):
        print("writing catalog")
        write_halo_cat(sod_output.replace("${step}", str(time_step)), cat, h_scaling)
        exit()
    else:
        print("plotting tests")

    h, xbins, ybins = np.histogram2d(np.log10(cat['sod_halo_mass']), np.log10(M_200c), bins = 250)
    plt.figure()
    plt.pcolor(xbins, ybins, h.T, cmap = 'Blues', norm = clr.LogNorm())
    plt.plot([np.min(xbins), np.max(xbins)], [np.min(xbins), np.max(xbins)], '--k')
    plt.ylabel('Col M200c')
    plt.xlabel('SOD M200c')

    print(np.mean(R_200c*a/cat['sod_halo_radius']), np.mean(cat['sod_halo_radius']/R_200c/a), a)
    h, xbins, ybins = np.histogram2d(cat['sod_halo_radius'],R_200c*a, bins = 250)
    plt.figure()
    plt.pcolor(xbins, ybins, h.T, cmap = 'Blues', norm = clr.LogNorm())
    plt.plot([np.min(xbins), np.max(xbins)], [np.min(xbins), np.max(xbins)], '--k')
    plt.ylabel('Col R200c')
    plt.xlabel('SOD R200c')


    plt.show()

    h, xbins, ybins = np.histogram2d(np.log10(M_200c), R_200m/R_200c, bins = 250)
    plt.figure()
    plt.pcolor(xbins, ybins, h.T, cmap = 'Blues', norm = clr.LogNorm())
    plt.ylabel('R_200m/R_200c')
    plt.xlabel('M_200c')

    h, xbins, ybins = np.histogram2d(np.log10(M_200c), M_200m/M_200c, bins = 250)
    plt.figure()
    plt.pcolor(xbins, ybins, h.T, cmap = 'Blues', norm = clr.LogNorm())
    plt.ylabel('M_200m/M_200c')
    plt.xlabel('M_200c')

    h, xbins = np.histogram(cat['sod_halo_cdelta'], bins = 100)
    plt.figure()
    plt.plot(dtk.bins_avg(xbins), h, '-x')

    
    M200m_col, R200m_col, c200m_col = mass_adv.changeMassDefinitionCModel(cat['sod_halo_mass']/0.7, redshift,
                                                                          "200c","200m", c_model='child18')#cat['sod_cdelta']

    plt.figure()
    h, xbins,ybins = np.histogram2d(np.log10(M_200m), np.log10(M200m_col), bins =256)
    plt.pcolor(xbins, ybins, h.T, cmap='Blues', norm=clr.LogNorm())
    plt.plot([np.min(xbins), np.max(xbins)], [np.min(xbins), np.max(xbins)], '--k')
    plt.xlabel("my m200m")
    plt.ylabel('colossus m200m')


    plt.figure()
    h, xbins, ybins = np.histogram2d(np.log10(M_200c), M_200c/M_200m, bins=100)
    plt.pcolor(xbins, ybins, h.T, cmap='Blues', norm=clr.LogNorm())
    xbins_cen = dtk.bins_avg(xbins)
    median = dtk.binned_median(np.log10(M_200c), M_200c/M_200m, xbins)
    plt.plot(xbins_cen, median, '-k', label='median')
    plt.legend(loc='best', framealpha=0.0)
    plt.xlabel("M200c")
    plt.ylabel("M200c/M200m")

    plt.figure()
    h, xbins, ybins = np.histogram2d(np.log10(M_200m), M_200c/M_200m, bins=100)
    plt.pcolor(xbins, ybins, h.T, cmap='Blues', norm=clr.LogNorm())
    xbins_cen = dtk.bins_avg(xbins)
    median = dtk.binned_median(np.log10(M_200m), M_200c/M_200m, xbins)
    plt.plot(xbins_cen, median, '-k', label='median')
    plt.legend(loc='best', framealpha=0.0)
    plt.xlabel("M200m")
    plt.ylabel("M200c/M200m")

    plt.figure()
    M200m_col_lin, R200m_col_lin, c200m_col_lin =  mass_adv.changeMassDefinitionCModel(np.logspace(12,15,100), redshift,
                                                                                       "200c", "200m", c_model='child18')
    h, xbins, ybins = np.histogram2d(np.log10(M_200m), np.log10(R_200m), bins=100)
    plt.pcolor(xbins, ybins, h.T, cmap='Blues', norm=clr.LogNorm())
    plt.plot(np.log10(M200m_col_lin), np.log10(R200m_col_lin), '--k', label='Colossus')
    plt.xlabel('M200m')
    plt.ylabel('R200m')

    plt.show()
Exemplo n.º 23
0
def plot_core_trajectory(core_fname_pattern, steps):
    cat = get_full_core_catalog(core_fname_pattern, steps)

    slct = cat['step']==steps[0]
    print('select size: ', slct.size/ np.sum(slct))

    # sort ids by infall tree node mass
    core_masses = cat['infall_tree_node_mass'][slct]
    srt = np.argsort(core_masses)[::-1]
    srt = np.argsort(srt)
    core_tags = cat['core_tag'][slct][srt]
    core_masses = core_masses[srt]

    for core_tag, core_mass in zip(core_tags, core_masses):
        slct = cat['core_tag']==core_tag
        srt = np.argsort(cat['step'][slct])
        x = cat['x'][slct][srt]
        y = cat['y'][slct][srt]
        z = cat['z'][slct][srt]
        vx = cat['vx'][slct][srt]
        vy = cat['vy'][slct][srt]
        vz = cat['vz'][slct][srt]
        step = cat['step'][slct][srt]
        radius = cat['radius'][slct][srt]
        mass = cat['infall_tree_node_mass'][slct][srt]
        central = cat['central'][slct][srt] == 1
        print(list(zip(x,y)))
        print(cat['step'][slct][srt])
        step_mid = dtk.bins_avg(step)
        central_step = np.diff(central)
        
        fig, axs = plt.subplots(2, 3, figsize=(15, 8))
        fig.suptitle('TreeNodeMass={:.2e}\nCore Tag:{}'.format(core_mass, core_tag))
        axs[0][0].plot(x-x[-1], y-y[-1], '-o', mfc='none', label='Path')
        axs[0][0].plot(x[-1]-x[-1], y[-1]-y[-1], 'o', ms=20, mfc='none', label='Last Pos', color='tab:orange')
        axs[0][0].plot(x[central]-x[-1], y[central]-y[-1], 'o', label='Central', color='tab:blue')

        axs[0][0].legend(framealpha=0.0)
        axs[0][0].axis('equal')
        axs[0][0].set_xlabel('x')
        axs[0][0].set_ylabel('y')
        
        axs[0][1].plot(z-z[-1], y-y[-1], '-o', mfc='none', label='Path')
        axs[0][1].plot(z[-1]-z[-1], y[-1]-y[-1], 'o', ms=20, mfc='none', label='Last Pos')
        axs[0][1].plot(z[central]-z[-1], y[central]-y[-1], 'o', label='Central', color='tab:blue')
        axs[0][1].axis('equal')
        axs[0][1].set_xlabel('z')
        axs[0][1].set_ylabel('y')
        axs[0][1].set_ylim(axs[0][0].get_ylim())

        dx = np.diff(x)
        dy = np.diff(y)
        dz = np.diff(z)
        dr = np.sqrt(dx*dx + dy*dy + dz*dz)

        axs[0][2].plot(step_mid, dr, '-o')
        axs[0][2].fill_between(step_mid, 0, dr, alpha=0.3)
        axs[0][2].set_xlabel('Mid Step')
        axs[0][2].set_ylabel('displace per snapshot [Mpc/h]')

        dv = np.sqrt(vx*vx + vy*vy + vz*vz)[1:]
        # dx = vx[1:]
        # dy = vy[1:]
        # dz = vz[1:]
        theta = np.arccos((vx[1:]*dx + vy[1:]*dy + vz[1:]*dz)/(dv*dr))
        theta = theta*180.0/np.pi
        
        # theta = (dx*dx + dy*dy + dz*dz)/(dr*dr)
        # theta = np.arccos
        axs[1][2].plot(step_mid, theta, '-o')
        axs[1][2].fill_between(step_mid, 0, theta, alpha=0.3)
        axs[1][2].set_xlabel('Mid Step')
        axs[1][2].set_ylabel('Angle between displ. and vel. [deg.]')

        axs[1][0].plot(step, mass, '-o', mfc='none')
        axs[1][0].fill_between(step, np.min(mass), mass, alpha=0.3)
        axs[1][0].plot(step[-1], mass[-1], 'o', ms=20, mfc='none')
        axs[1][0].plot(step[central], mass[central], 'o', color='tab:blue')
        axs[1][0].set_xlabel('Step')
        axs[1][0].set_ylabel('Infall Mass [Msun/h]')
        axs[1][0].set_yscale('log')

        axs[1][1].plot(step, radius*1000.0, '-o', mfc='none')
        axs[1][1].fill_between(step, 0, radius*1000.0, alpha=0.3)
        axs[1][1].plot(step[-1], radius[-1]*1000.0, 'o', ms=20, mfc='none')
        axs[1][1].plot(step[central], radius[central]*1000.0, 'o', color='tab:blue')
        axs[1][1].set_xlabel('Step')
        axs[1][1].set_ylabel('Core Radius [Kpc/h]')
        axs[1][1].set_ylim([0, 200])
        # axs[1][1].set_yscale('log')
        plt.tight_layout(rect=[0, 0.03, 1, 0.95])
        # plt.show()
        dtk.save_figs('figs/'+__file__+'/individual_cores_random_rev4070_v2/')
        plt.close()
Exemplo n.º 24
0
def plot_richness_mass_relation():
    background.set_cosmology("wmap7")
    richness = np.logspace(np.log10(20), np.log10(300), 100)
    m200m_rykoff, r200m_rykoff = background.lambda_to_m200_r200(
        richness, 0.25, richness_mass_author="Rykoff_mean")
    m200m_simet, r200m_simet = background.lambda_to_m200_r200(
        richness, 0.25, richness_mass_author="Simet_mean")
    m200m_baxter, r200m_baxter = background.lambda_to_m200_r200(
        richness, 0.25, richness_mass_author="Baxter_mean")
    m200c_rykoff, r200c_rykoff = background.lambda_to_m200_r200(
        richness, 0.25, richness_mass_author="Rykoff_crit")
    m200c_simet, r200c_simet = background.lambda_to_m200_r200(
        richness, 0.25, richness_mass_author="Simet_crit")
    m200c_baxter, r200c_baxter = background.lambda_to_m200_r200(
        richness, 0.25, richness_mass_author="Baxter_crit")
    plt.figure()
    plt.plot(richness, m200m_rykoff, '-r')
    plt.plot(richness, m200m_simet, '-b')
    plt.plot(richness, m200m_baxter, '-g')
    plt.plot(richness, m200c_rykoff, '--r')
    plt.plot(richness, m200c_simet, '--b')
    plt.plot(richness, m200c_baxter, '--g')
    plt.plot([], [], 'r', label='rykoff')
    plt.plot([], [], 'b', label='simet')
    plt.plot([], [], 'g', label='baxter')
    plt.plot([], [], '-k', label='M200m')
    plt.plot([], [], '--k', label='M200c')
    plt.legend(loc='best', framealpha=0.3)
    plt.yscale('log')
    plt.xscale('log')
    plt.xlabel('Richness')
    plt.ylabel(r'M$_{200}$')
    plt.grid()

    plt.figure()
    plt.plot(richness, r200m_rykoff, '-r')
    plt.plot(richness, r200m_simet, '-b')
    plt.plot(richness, r200m_baxter, '-g')
    plt.plot(richness, r200c_rykoff, '--r')
    plt.plot(richness, r200c_simet, '--b')
    plt.plot(richness, r200c_baxter, '--g')
    plt.plot([], [], 'r', label='rykoff')
    plt.plot([], [], 'b', label='simet')
    plt.plot([], [], 'g', label='baxter')
    plt.plot([], [], '-k', label='R200m')
    plt.plot([], [], '--k', label='R200c')
    plt.legend(loc='best', framealpha=0.3)
    plt.yscale('log')
    plt.xscale('log')
    plt.xlabel('Richness')
    plt.ylabel(r'R$_{200}$')
    plt.grid()

    plt.figure()
    plt.plot(richness, m200c_rykoff / m200m_rykoff, '-r', label='rykoff')
    plt.plot(richness, m200c_simet / m200m_simet, '-b', label='simet')
    plt.plot(richness, m200c_baxter / m200m_baxter, '-g', label='baxter')
    plt.legend(loc='best', framealpha=0.3)
    plt.xscale('log')
    plt.xlabel('Richness')
    plt.ylabel(r'M200c/M200m')
    plt.grid()

    plt.figure()
    plt.plot(richness, r200c_rykoff / r200m_rykoff, '-r', label='rykoff')
    plt.plot(richness, r200c_simet / r200m_simet, '-b', label='simet')
    plt.plot(richness, r200c_baxter / r200m_baxter, '-g', label='baxter')
    plt.legend(loc='best', framealpha=0.3)
    plt.xscale('log')
    plt.xlabel('Richness')
    plt.ylabel(r'R200c/R200m')
    plt.grid()

    plt.figure()
    a = 1.0 / (1.0 + 0.25)
    # plt.plot(m200m_simet, r200m_simet, '-b',  label='my simet mean')
    # plt.plot(m200c_simet, r200c_simet, '--b', label='my simet crit')
    plt.plot(m200m_simet, r200m_simet, '-b', label='my simet mean')
    plt.plot(m200c_simet, r200c_simet, '--b', label='my simet crit')

    nfw_200m = NFWProfile(mdef='200m', redshift=0.25)
    nfw_200c = NFWProfile(mdef='200c', redshift=0.25)
    plt.plot(m200m_simet,
             nfw_200m.halo_mass_to_halo_radius(m200m_simet) * 1000,
             '-r',
             label='ht simet mean')
    plt.plot(m200c_simet,
             nfw_200c.halo_mass_to_halo_radius(m200c_simet) * 1000,
             '--r',
             label='ht simet crit')

    plt.plot(m200m_simet,
             M_to_R(m200m_simet, 0.25, '200m'),
             '-g',
             label='cls simet mean')
    plt.plot(m200c_simet,
             M_to_R(m200c_simet, 0.25, '200c'),
             '--g',
             label='cls simet crit')

    plt.legend(loc='best', framealpha=0.3)
    plt.xscale('log')
    plt.yscale('log')
    plt.xlabel('M200 [Msun]')
    plt.ylabel('R200 [proper kpc]')
    plt.grid()

    plt.show()

    #header list can be found in http://arxiv.org/pdf/1303.3562v2.pdf
    hdulist = pyfits.open("redmapper_dr8_public_v6.3_catalog.fits")
    tdata = hdulist[1].data

    # red_ra = tdata.field('ra')
    # red_dec= tdata.field('dec')
    red_z = tdata.field('z_lambda')
    red_lambda = tdata.field('lambda')
    # red_pcen=tdata.field('p_cen')

    plt.figure()
    h, xbins = np.histogram(red_lambda, bins=256)
    plt.plot(dtk.bins_avg(xbins), h)
    plt.yscale('log')
    plt.xscale('log')
    plt.xlabel('Richness')
    plt.ylabel('count')

    m200m_rykoff = background.lambda_to_m200m_Rykoff(red_lambda, 0.25)
    m200m_simet = background.lambda_to_m200m_Simet(red_lambda, 0.25)
    m200m_baxter = background.lambda_to_m200m_Baxter(red_lambda, 0.25)
    m200c_rykoff = background.lambda_to_m200c_Rykoff(red_lambda, 0.25)
    m200c_simet = background.lambda_to_m200c_Simet(red_lambda, 0.25)
    m200c_baxter = background.lambda_to_m200c_Baxter(red_lambda, 0.25)

    xbins = np.logspace(13.5, 15.5, 100)
    xbins_avg = dtk.bins_avg(xbins)

    plt.figure()
    h, _ = np.histogram(m200m_rykoff, bins=xbins)
    plt.plot(xbins_avg, h, label='rykoff')
    h, _ = np.histogram(m200m_simet, bins=xbins)
    plt.plot(xbins_avg, h, label='simet')
    h, _ = np.histogram(m200m_baxter, bins=xbins)
    plt.plot(xbins_avg, h, label='baxter')
    plt.yscale('log')
    plt.xscale('log')
    plt.ylabel('Counts')
    plt.xlabel('M$_{200m}$ [h$^{-1}$ M$_\odot$]')
    plt.legend(loc='best', framealpha=1.0)
    plt.grid()

    plt.figure()
    h, _ = np.histogram(m200c_rykoff, bins=xbins)
    plt.plot(xbins_avg, h, label='rykoff')
    h, _ = np.histogram(m200c_simet, bins=xbins)
    plt.plot(xbins_avg, h, label='simet')
    h, _ = np.histogram(m200c_baxter, bins=xbins)
    plt.plot(xbins_avg, h, label='baxter')
    plt.yscale('log')
    plt.xscale('log')
    plt.ylabel('Counts')
    plt.xlabel('M$_{200c}$ [h$^{-1}$ M$_\odot$]')
    plt.legend(loc='best', framealpha=1.0)
    plt.grid()

    plt.show()
Exemplo n.º 25
0
plt.xlabel('Log10(Stellar Mass [Msun/h])')
cb.set_label('Freq')
plt.tight_layout()
plt.grid()

plt.figure()
plt.pcolor(x_bins, y_bins, H.T, cmap='PuBu')
cb = plt.colorbar()
plt.ylabel('SDSS r-band abs. Mag.')
plt.xlabel('Log10(Stellar Mass [Msun/h])')
cb.set_label('Freq')
plt.tight_layout()
plt.grid()

H, x_bins = np.histogram(stellar_mass, bins=100)
x_bins_avg = dtk.bins_avg(x_bins)
plt.figure()
plt.plot(x_bins_avg, H)
plt.ylabel('Freq')
plt.xlabel('Log10(Stellar Mass [Msun/h])')
plt.grid()

H, x_bins = np.histogram(mag_r, bins=100)
x_bins_avg = dtk.bins_avg(x_bins)
plt.figure()
plt.plot(x_bins_avg, H)
plt.ylabel('Freq')
plt.xlabel('SDSS r-band abs. Mag.')

plt.grid()
# plt.figure()
Exemplo n.º 26
0
plt.plot(x, gal_zoo_dist(x))
#plt.plot(x,gal_zoo_dist2(x))

inclination = hfile['inclination'].value / 180 * np.pi
size = inclination.size
pos_angle = np.array(rand(size) * np.pi)
q = dtk.clipped_gaussian(0.8, 0.2, size, max_val=1.0, min_val=0.0)

print np.min(q), np.max(q)

spheroid_ellip = (1.0 - q) / (1.0 + q)
spheroid_ellip1 = np.cos(2.0 * pos_angle) * spheroid_ellip
spheroid_ellip2 = np.sin(2.0 * pos_angle) * spheroid_ellip
plt.figure()
h, xbins = np.histogram(q, 100)
plt.plot(dtk.bins_avg(xbins), h, label='axis ratio')
h, xbins = np.histogram(spheroid_ellip, 100)
plt.plot(dtk.bins_avg(xbins), h, label='ellipticity')
plt.legend(loc='best')

plt.figure()
h, xbins = np.histogram(spheroid_ellip1, 100)
plt.plot(dtk.bins_avg(xbins), h, label='ellip1')
h, xbins = np.histogram(spheroid_ellip2, 100)
plt.plot(dtk.bins_avg(xbins), h, label='ellip2')
plt.legend(loc='best')

plt.figure()
H, xbins, ybins = np.histogram2d(spheroid_ellip1,
                                 spheroid_ellip2,
                                 bins=(100, 100))