def compare_abundance_line(param_fname1, param_fname2):
    param1 = dtk.Param(param_fname1)
    param2 = dtk.Param(param_fname2)
    m_infall1, radius1 = load_abundance_line(get_fname(param1))
    m_infall2, radius2 = load_abundance_line(get_fname(param2))
    f, ax = plt.subplots(1)
    ax.loglog(m_infall1, radius1, label='arg1')
    ax.loglog(m_infall2, radius2, label='arg2')
    plt.show()
示例#2
0
def make_zoom_param(input_param_fname):
    base_param = dtk.Param(input_param_fname)
    mi_bins_info = base_param.get_float_list("mi_bins_info")
    rd_bins_info = base_param.get_float_list("rd_bins_info")
    rm_bins_info = base_param.get_float_list("rm_bins_info")
    spacing = {}
    spacing["mi"] = get_spacing(mi_bins_info)
    spacing["rd"] = get_spacing(rd_bins_info)
    spacing["rm"] = get_spacing(rm_bins_info)
    model_fit_param = dtk.Param("figs/"+input_param_fname+"/calc_likelihood_bounds.py/grid_fit_param.txt")
    model_params = ['mi', 'rd', 'rm']
    for mp in model_params:
        if mp in model_fit_param:
            rd_factor = 1.0
            if mp == "rd":
                rd_factor = 1000.0

            old_values = base_param.get_float_list(mp+"_bins_info")
            center = model_fit_param.get_float(mp)
            lower, upper = model_fit_param.get_float_list(mp+"_limits")
            print("\n\nparam:", mp)
            old_range = (old_values[1]-old_values[0])*rd_factor
            print(" old range: {:.3f}->{:.3f}".format(old_values[0]*rd_factor, old_values[1]*rd_factor))
            print("\trange: {:.3f}".format((old_values[1]-old_values[0])*rd_factor))
            print(" fit: {:.3f} +{:.3f} -{:.3f}".format(center, upper-center, center-lower))
            print("\trange: {:3f}".format(upper-lower))

            err = np.max([center-lower, upper-center, spacing[mp]])

            # print(center-lower, upper-center)
            print(" target err: {:.3f}".format(err))
            # if err< 0.002:
            #     err = 0.002
            new_lower_limit = lower - err*3
            new_upper_limit = upper + err*3
            if new_lower_limit < 0:
                new_lower_limit = 0
            print(" New limits: {:.3f} -> {:.3f}".format(new_lower_limit, new_upper_limit))
            new_range = new_upper_limit - new_lower_limit
            print("\trange: {:.3f}".format(new_range))
            print("\tchange: {:.3f}".format(new_range/old_range))
            if mp != 'rd':
                base_param.set_var(mp+"_bins_info", "{} {} {}".format(new_lower_limit, new_upper_limit, old_values[2]))
            else:
                base_param.set_var(mp+"_bins_info", "{} {} {}".format(new_lower_limit/1000, new_upper_limit/1000, old_values[2]))

    with open(input_param_fname.replace(".param", "_zoom.param"), 'w') as f:
        f.write(str(base_param))
示例#3
0
def plot_abundance_line(ax, param_fname):
    param = dtk.Param(param_fname)
    core_loc = param.get_string('core_loc')
    expected_abundance = param.get_string('expected_abundance')
    fname = "tmp_hdf5/{}/abundance={}.hdf5".format(core_loc,
                                                   expected_abundance)
    print(fname)
示例#4
0
def plot_1pt_distributions(param_file):
    param = dtk.Param(param_file)
    cluster_hfname = param.get_string("cluster_loc")
    zmr_hfname = param.get_string("zmrh5_loc")

    core_hfile = h5py.File(cluster_hfname, 'r')
    zmr_hfile = h5py.File(zmr_hfname, 'r')
    plot_cluster_mass(
        core_hfile,
        '/data/a/cpac/dkorytov/data/Ngal_sdss/data/normal_wmap7/query_results/query_results.hdf5'
    )
    plot_cluster_redshift(
        0.24,
        '/data/a/cpac/dkorytov/data/Ngal_sdss/data/normal_wmap7/query_results/query_results.hdf5'
    )
    plot_cluster_cores2(core_hfile, [
        10,
        10.5,
        11,
        11.5,
        12,
        12.5,
        13.0,
        13.5,
    ])
    dtk.save_figs("figs/" + param_file + "/" + __file__ + "/")
    plt.show()
示例#5
0
 def load_from_param(self,file_loc):
     param = dtk.Param(file_loc)
     self.z_bins = np.array(param.get_float_list("z_bins"))
     self.m_bins = np.array(param.get_float_list("m_bins"))
     self.r_bins = np.array(param.get_float_list("r_bins"))
     self.zmr_gal_density = np.array(param.get_float_list("zmr_gal_density"))
     self.zmr_gal_density_err = np.array(param.get_float_list("zmr_gal_density_err"))
def plot_mstar_background(param_fname):
    param = dtk.Param(param_fname)
    background_folder = param.get_string('background_folder')
    galaxy_type = param.get_int('galaxy_type')
    galaxy_weight = param.get_int('galaxy_weight')
    background.set_gal_type_weight(galaxy_type, galaxy_weight)
    background.set_gal_clr_type(param.get_int('galaxy_color_type'),
                                param.get_int_list('galaxy_mag_lim1'))
    background.set_gal_mag_type(param.get_int('galaxy_mag_type'),
                                param.get_int_list('galaxy_mag_lim1'))
    plt.figure()
    labels = {
        -1: '$>2.50 $L$_\star$',
        -0.5: '$>1.58 $L$_\star$',
        0: '$> 1.00 $L$_\star$',
        0.5: '$> 0.63 $L$_\star$',
        1: '$> 0.40 $L$_\star$',
    }
    for mstar_cut in [-1, -0.5, 0, 0.5, 1.0][::-1]:
        background.set_mstar_cut(mstar_cut)
        a, b = background.get_background_estimate_sqdeg(
            background_folder, galaxy_type, galaxy_weight)
        z_range = np.linspace(0.1, 0.35, 100)
        plt.plot(z_range, a(z_range), label=labels[mstar_cut])
        plt.yscale('log')
        plt.xlabel('redshift')
        plt.ylabel('background galaxy density [deg$^{-2}$]')
        plt.legend(framealpha=0.0, labelspacing=0.0)
        plt.tight_layout()
示例#7
0
def calc_abundance_line(param_fname, plot=False):
    param = dtk.Param(param_fname)
    core_loc = param.get_string('core_loc')
    rL = param.get_float('rL')
    expected_comov_abundance = param.get_float('expected_comov_abundance')
    step = param.get_int('step')
    core_loc = core_loc.replace("${step}", str(step))
    if "qcontinuum" in param:
        qcontinuum = param.get_bool("qcontinuum")
    else:
        qcontinuum = False
    cat = load_core_cat(core_loc.replace('${step}', str(step)))
    expected_num = int(rL * rL * rL * expected_comov_abundance)
    x = np.logspace(11, 12.6, 50)
    y = np.zeros_like(x)
    print("calculating radius")
    cat = sort_cat(cat, 'radius')
    for i in range(0, len(x)):
        print("\t", i)
        y[i] = calc_abundance_radius(cat, x[i], expected_num, presort=True)
    if plot:
        print('num/vol: ', expected_comov_abundance)
        print('vol: ', rL * rL * rL)
        print('expected_num:', expected_num)

        print(x)
        print(y)
        plt.figure()
        plt.plot(x, y, '-x')
        plt.yscale('log')
        plt.xscale('log')
    y1 = np.logspace(-3, -.2, 25)
    x1 = np.zeros_like(y1)
    print("calculating infall")
    cat = sort_cat(cat, 'infall_mass')
    for i in range(0, len(x1)):
        print("\t", i)
        x1[i] = calc_abundance_infall_mass(cat,
                                           y1[i],
                                           expected_num,
                                           presort=True)
    if plot:
        plt.plot(x1, y1, '-x')
        print(x1)
        print(y1)

    abund_infall_mass = np.concatenate((x, x1))
    abund_radius = np.concatenate((y, y1))
    srt = np.argsort(abund_infall_mass)
    slct = np.isfinite(abund_infall_mass[srt]) & np.isfinite(abund_radius[srt])
    out_fname = 'tmp_hdf5/{}/abundance={}.hdf5'.format(
        core_loc, expected_comov_abundance)
    dtk.ensure_dir(out_fname)
    print(out_fname)
    hfile = h5py.File(out_fname, 'w')
    hfile['abund_infall_mass'] = abund_infall_mass[srt][slct]
    hfile['abund_radius'] = abund_radius[srt][slct]
    hfile.close()
    plt.show()
def get_cores(param_filename):
    cat = {}
    param = dtk.Param(param_filename)
    cluster_loc = param.get_string("cluster_loc")
    hfile = h5py.File(cluster_loc, 'r')
    cat['radius'] = hfile['cores/core_r'].value
    cat['mass']   = hfile['cores/core_m'].value
    return cat
示例#9
0
def load_zmr(param_fname):
    param = dtk.Param(param_fname)
    result_folder = param.get_string("result_folder")

    fname = result_folder + "type1_weight1_mag1_clr1_result.hdf5"
    print(fname)
    zmr = h5py.File(fname, 'r')
    return zmr
def get_survival_rate(param_fname, fit, mass_bins):
    param = dtk.Param(param_fname)
    cluster_loc = param.get_string('cluster_loc')
    cluster_load_num = param.get_int('cluster_load_num')
    cluster_data = load_clusters(cluster_loc)
    # getting the Ngal with and without disruption
    model_fit_fname = "figs/"+param_fname+"/calc_likelihood_bounds.py/grid_fit_param.txt"
    model_fit = load_fit_limits(model_fit_fname)
    return get_survival_rate_cluster(cluster_data,  cluster_load_num, mass_bins, model_fit, )
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()
示例#12
0
def get_clusters(param_fname, core_host_mass=False):
    param = dtk.Param(param_fname)
    cluster_loc = param.get_string('cluster_loc')
    central = param.get_bool('force_central_as_galaxy')
    if central:
        print("It's compact central")
    clusters = ClusterData()
    clusters.load_file(cluster_loc,
                       treat_centrals=central,
                       step=401,
                       core_host_mass=core_host_mass)
    return clusters, central
示例#13
0
def miscenter_clusters(param_fname):
    param = dtk.Param(param_fname)
    sod_input = param.get_string('sod_input')
    sod_output = param.get_string('sod_output')
    step = param.get_int('step')
    # re-scale from kpc to mpc
    miscenter_mean = param.get_float('miscenter_mean')/1000
    miscenter_width = param.get_float('miscenter_width')/1000
    sod_input = sod_input.replace('${step}', str(step))
    sod_output = sod_output.replace('${step}', str(step))
    assert sod_input != sod_output, 'Output file cannot be the same as the input file'
    cat = load_clusters(sod_input)
    apply_miscentering_to_cluster(cat, miscenter_mean, miscenter_width)
    save_clusters(sod_output, cat)
示例#14
0
    def load_param(self, file_loc):
        print(file_loc)
        if ".param" in file_loc:
            param = dtk.Param(file_loc)
            self.z_bins = np.array(param.get_float_list("z_bins"))
            self.m_bins = np.array(param.get_float_list("m_bins"))
            self.r_bins = np.array(param.get_float_list("r_bins"))
            self.z_size = self.z_bins.size -1
            self.m_size = self.m_bins.size -1
            self.r_size = self.r_bins.size -1
            zm_shape = (self.z_size,self.m_size)
            zmr_shape = (self.z_size,self.m_size,self.r_size)
            self.zm_Ngal = np.array(param.get_float_list("zm_Ngal")).reshape(zm_shape)
            self.zm_Ngal_err = np.array(param.get_float_list("zm_Ngal_err")).reshape(zm_shape)
            self.zm_Ngal_var = np.array(param.get_float_list("zm_Ngal_var")).reshape(zm_shape)
            self.zmr_gal_counts = np.array(param.get_float_list("zmr_gal_counts")).reshape(zmr_shape)
            self.zmr_gal_density = np.array(param.get_float_list("zmr_gal_density")).reshape(zmr_shape)
            self.zmr_gal_density_err = np.array(param.get_float_list("zmr_gal_density_err")).reshape(zmr_shape)
            self.zmr_gal_density_var = np.array(param.get_float_list("zmr_gal_density_var")).reshape(zmr_shape)
            self.zmr_dgal_dr = np.array(param.get_float_list("zmr_dgal_dr")).reshape(zmr_shape)
            self.zmr_dgal_dr_err = np.array(param.get_float_list("zmr_dgal_dr_err")).reshape(zmr_shape)
            self.zmr_dgal_dr_var = np.array(param.get_float_list("zmr_dgal_dr_var")).reshape(zmr_shape)
            self.zmr_gal_accum = np.array(param.get_float_list("zmr_gal_accum")).reshape(zmr_shape)
            self.zmr_gal_accum_err = np.array(param.get_float_list("zmr_gal_accum_err")).reshape(zmr_shape)
            self.zmr_gal_accum_var = np.array(param.get_float_list("zmr_gal_accum_var")).reshape(zmr_shape)

            self.zm_counts = np.array(param.get_float_list("zm_counts")).reshape(zm_shape)
            self.zmr_counts = np.array(param.get_float_list("zmr_counts")).reshape(zmr_shape) 
        elif ".hdf5" in file_loc:
            hfile = h5py.File(file_loc, 'r')
            print(hfile.keys())
            self.z_bins = hfile['z_bins'].value
            self.m_bins = hfile['m_bins'].value
            self.r_bins = hfile['r_bins'].value
            self.z_size = self.z_bins.size -1
            self.m_size = self.m_bins.size -1
            self.r_size = self.r_bins.size -1
            self.zm_Ngal = hfile['zm_Ngal']
            self.zm_Ngal_err = hfile['zm_Ngal_err']
            self.zm_Ngal_var = hfile['zm_Ngal_var']
            
            self.zmr_gal_density = hfile['zmr_gal_density']
            self.zmr_gal_density_var = hfile['zmr_gal_density_var']
            self.zmr_gal_density_err = hfile['zmr_gal_density_err']
            self.zm_counts = hfile['zm_counts']
            self.zmr_counts = hfile['zmr_counts']
        else:
            raise ValueError("{} doesn't have .param or .hdf5".format(file_loc))
def load_fit_limits(fname):
    if fname in load_fit_limits.cache:
        return load_fit_limits.cache[fname]
    pfile = dtk.Param(fname)
    result = {}
    for p in ['mi', 'rd', 'rm']:
        if p in pfile:
            result[p] = pfile.get_float(p)
            result[p + '_limits'] = np.array(
                pfile.get_float_list(p + '_limits'))
            result[p + '_lower_err'] = result[p] - result[p + '_limits'][0]
            result[p + '_upper_err'] = result[p + '_limits'][1] - result[p]
    if 'X_red' in pfile:
        result['x2'] = pfile.get_float('X_red')
        print(result['x2'])
    else:
        result['x2'] = np.nan
    return result
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]
示例#17
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()
def plot_saved_clusters(param_filename):
    global n2merger
    param = dtk.Param(param_filename)
    cluster_loc = param.get_string("cluster_loc")
    cluster_data = ClusterData()
    # n2lib_loc = "lib/libn2merg.so"
    # n2merger = N2Merger(n2lib_loc)
    # core_loc = param.get_string('core_loc').replace("${step}", str(401)).replace("_500L", "")
    fit_mi, fit_rd = get_fit_param(param_filename)
    # fit_mi, fit_rd = 1e12, 1e3
    print("Infall mass: {:.2e}\nR disrupt: {:.4f}".format(fit_mi, fit_rd))
    # test_core_catalog(core_loc, 1)

    cluster_data.load_file(cluster_loc)
    for i in range(int(cluster_data.num)):
        if cluster_data.mass[i] > 1e14:
            # cluster_data.plot_fit_cluster(i, 12.2, 0.02)
            # cluster_data.plot_cluster(i)
            cluster_data.plot_fit_cluster(i, fit_mi, fit_rd)
            dtk.save_figs("figs/" + __file__ + "/" + param_filename + "/",
                          extension=".png")
            plt.show()
            plt.close('all')
def test_saved_clusters(param_filename):
    param = dtk.Param(param_filename)
    cluster_loc = param.get_string('cluster_loc')
    sod_loc = param.get_string("sod_loc")
    sod_hdf5 = param.get_string("sod_hdf5")

    sod_data_raw = SODData()

    sod_data_saved = SODData()
    sod_data_saved.load_sod(
        '/media/luna1/dkorytov/data/OuterRim/sod_200m/sod_m200m.401.test1.hdf5',
        True)

    saved_cluster = ClusterData()
    saved_cluster.load_file('tmp_hdf5/clusters_OR_M200m.test1.hdf5')
    # sod_data_raw.load_sod('/media/luna1/dkorytov/data/OuterRim/sod/m000.401.sodproperties', False)
    plt.figure()
    bins = np.logspace(12, 16, 32)
    plt.title("Mass")
    # plot_hist(sod_data_raw.mass, bins, label='sod_raw')
    plot_hist(sod_data_saved.mass, bins, label='sod saved')
    plot_hist(saved_cluster.mass, bins, label='saved cluster')
    plt.yscale('log')
    plt.xscale('log')
    plt.xlabel('m200')
    plt.legend(loc='best')

    plt.figure()
    bins = np.linspace(0, 5, 64)
    plt.title("radius")
    # plot_hist(sod_data_raw.rad, bins, label='sod_raw')
    plot_hist(sod_data_saved.rad, bins, label='sod saved')
    plot_hist(saved_cluster.rad, bins, label='saved cluster')
    plt.yscale('log')
    plt.xlabel('r200')
    plt.legend(loc='best')
    plt.show()
示例#20
0
#!/usr/bin/env python2.7
import matplotlib
#matplotlib.use('Agg')
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as clrs
import sys
import dtk

param = dtk.Param(sys.argv[1])

fof_loc = param.get_string("fof_loc")
sod_loc = param.get_string("sod_loc")
core_loc = param.get_string("core_loc")
gal_loc = param.get_string("gal_loc")
hp_loc = param.get_string("hp_loc")
mt_loc = param.get_string("mt_loc")
steps = param.get_int_list("steps")
core_intacted_radius = param.get_float("core_intact_radius")

fof_cat = dtk.Catalog(fof_loc)
sod_cat = dtk.Catalog(sod_loc)
core_cat = dtk.Catalog(core_loc)
hp_cat = dtk.Catalog(hp_loc)
gal_cat = dtk.Catalog(gal_loc)
mt_cat = dtk.Catalog(mt_loc)
gal_mt_cat = dtk.Catalog()
step = steps[0]

fof_cat.add_steps(steps)
sod_cat.add_steps(steps)
示例#21
0
def calc_likelihood_bounds(param_file_name):
    param = dtk.Param(param_file_name)
    expected_comov_abundance = param.get_float('expected_comov_abundance')
    core_loc = param.get_string('core_loc')
    step = param.get_int('step')
    core_loc = core_loc.replace("${step}", str(step))
    lgrid_param = dtk.Param("output/" + param_file_name + "/lgrid.param")
    has_rm = param.get_bool("fit_r_merger")
    has_rd = param.get_float_list("rd_bins_info")[2] > 2

    result = np.array(lgrid_param.get_double_list("result"))
    hfile_fit = h5py.File("output/" + param_file_name +
                          "/fit_core_params.hdf5")

    nan_slct = np.isnan(result)
    result[nan_slct] = np.ones(np.sum(nan_slct)) * 1000000
    mi_bins = np.array(lgrid_param.get_float_list("mi_bins"))
    rd_bins = np.array(lgrid_param.get_float_list("rd_bins")) * 1000
    rm_bins = np.array(lgrid_param.get_float_list("rm_bins"))

    result2 = result.reshape((mi_bins.size, rd_bins.size, rm_bins.size))

    #print(np.min(result2), np.max(result2))
    lkhd = np.exp(-(result2 - np.min(result2)))
    lkhd_mi = np.sum(lkhd, axis=(1, 2))
    lkhd_rd = np.sum(lkhd, axis=(0, 2))
    lkhd_rm = np.sum(lkhd, axis=(0, 1))
    # print(np.shape(lkhd_mi))
    # lkhd_mi = renormalize(lkhd_mi, np.log10(mi_bins))
    # lkhd_mi = renormalize(lkhd_rd, rd_bins)
    # lkhd_mi = renormalize(lkhd_rm, rm_bins)
    lkhd_mi_rd = np.sum(lkhd, axis=2)
    lkhd_mi_rm = np.sum(lkhd, axis=1)
    #print(np.shape(lkhd_mi))
    max_lkhd = np.unravel_index(np.argmax(lkhd, axis=None), lkhd.shape)
    fit_mi = hfile_fit['m_infall'][()][0]
    fit_mi_bds_lwr, fit_mi_bds_upr, fit_lkhd_mi, fit_mi_bins = get_bounds_limits(
        lkhd_mi,
        np.log10(mi_bins),
        np.log10(fit_mi),
        fine_grain=5000,
        fit_index=max_lkhd[0])
    if has_rd:
        fit_rd = hfile_fit['r_disrupt'][()][0]
        fit_rd_bds_lwr, fit_rd_bds_upr, _, fit_rd_bins = get_bounds_limits(
            lkhd_rd, rd_bins, fit_rd, fine_grain=5000, fit_index=max_lkhd[1])
    if has_rm:
        fit_rm = hfile_fit['r_merger'][()][0]
        fit_rm_bds_lwr, fit_rm_bds_upr, _, fit_rm_bins = get_bounds_limits(
            lkhd_rm, rm_bins, fit_rm, fine_grain=5000, fit_index=max_lkhd[2])
    if has_rd and not has_rm:
        corner_plot(
            [
                r'log$_{10}$M$_{\mathrm{infall}}$/h$^{-1}$M$_\odot$',
                'R$_{\mathrm{disrupt}}$ [h$^{-1}$kpc]'
            ],
            grid_dic={
                'bins': [np.log10(mi_bins), rd_bins],
                'lkhd': np.sum(lkhd, axis=2),
                'cost': None
            },
            expected_comov_abundance=expected_comov_abundance,
            core_loc=core_loc)
        corner_plot(
            [
                r'log$_{10}$M$_{\mathrm{infall}}$/h$^{-1}$M$_\odot$',
                'R$_{\mathrm{disrupt}}$ [h$^{-1}$kpc]'
            ],
            grid_dic={
                'bins': [np.log10(mi_bins), rd_bins],
                'lkhd': np.sum(lkhd, axis=2),
                'cost': np.sum(result2, axis=2)
            },
            expected_comov_abundance=expected_comov_abundance,
            core_loc=core_loc)
        # corner_plot([r'M$_{\mathrm{infall}}$', 'R$_{\mathrm{disrupt}}$'], mcmc_dic = {'mcmc_loc': "output/{}/mcmc.gio".format(param_file_name)})
        # corner_plot([r'M$_{\mathrm{infall}}$', 'R$_{\mathrm{disrupt}}$'], grid_dic = {'bins': [np.log10(mi_bins), rd_bins], 'lkhd': np.sum(lkhd, axis=2), 'cost': None}, mcmc_dic = {'mcmc_loc': "output/{}/mcmc.gio".format(param_file_name)})
    if has_rm and not has_rd:
        corner_plot(
            [
                r'log$_{10}$M$_{\mathrm{infall}}$/h$^{-1}$M$_\odot$',
                'R$_{\mathrm{merger}}$ [h$^{-1}$Mpc]'
            ],
            grid_dic={
                'bins': [np.log10(mi_bins), rm_bins],
                'lkhd': np.sum(lkhd, axis=1),
                'cost': None
            },
            expected_comov_abundance=expected_comov_abundance,
            core_loc=core_loc)
        corner_plot(
            [
                r'log$_{10}$M$_{\mathrm{infall}}$/h$^{-1}$M$_\odot$',
                'R$_{\mathrm{merger}}$ [h$^{-1}$Mpc]'
            ],
            grid_dic={
                'bins': [np.log10(mi_bins), rm_bins],
                'lkhd': np.sum(lkhd, axis=1),
                'cost': np.sum(result2, axis=1)
            },
            expected_comov_abundance=expected_comov_abundance,
            core_loc=core_loc)
    if has_rm and has_rd:

        corner_plot(
            [
                r'log$_{10}$M$_{\mathrm{infall}}$/h$^{-1}$M$_\odot$',
                'R$_{\mathrm{disrupt}}$ [h$^{-1}$kpc]',
                'R$_{\mathrm{merge}}$ [h$^{-1}$Mpc]',
            ],
            grid_dic={
                'bins': [np.log10(mi_bins), rd_bins, rm_bins],
                'lkhd': lkhd,
                'cost': None
            },
            expected_comov_abundance=expected_comov_abundance)
        corner_plot(
            [
                r'log$_{10}$M$_{\mathrm{infall}}$/h$^{-1}$M$_\odot$',
                'R$_{\mathrm{disrupt}}$ [h$^{-1}$kpc]',
                'R$_{\mathrm{merge}}$ [h$^{-1}$Mpc]',
            ],
            grid_dic={
                'bins': [np.log10(mi_bins), rd_bins, rm_bins],
                'lkhd': lkhd,
                'cost': result2
            },
            expected_comov_abundance=expected_comov_abundance)
        #corner_plot([r'M$_{\mathrm{infall}}$', 'R$_{\mathrm{disrupt}}$', 'R$_{\mathrm{merge}}$', ], [np.log10(mi_bins), rd_bins, rm_bins], lkhd, cost = result2)
    if not has_rm and not has_rd:
        # plot_1d_likelihood("M$_{infall}$", mi_bins, lkhd_mi, fit_mi, mi_bds, log=True);
        plot_1d_likelihood("M$_{infall}$  [h$^{-1}$M$_\odot$]",
                           fit_mi_bins,
                           fit_lkhd_mi,
                           fit_mi, [fit_mi_bds_lwr, fit_mi_bds_upr],
                           log=False)
        # corner_plot([r'M$_{\mathrm{infall}}$'], grid_dic = {'bins':[np.log10(mi_bins)]]
    grid_fit_fname = "figs/" + param_file_name + "/" + __file__ + "/grid_fit_param.txt"
    dtk.ensure_dir(grid_fit_fname)
    txt_file = open(grid_fit_fname, 'w')
    txt_file.write("mi\t{}\n".format(np.log10(mi_bins[np.argmax(lkhd_mi)])))
    txt_file.write("mi_limits\t{}\t{}\n".format(fit_mi_bins[fit_mi_bds_lwr],
                                                fit_mi_bins[fit_mi_bds_upr]))
    param_num = 1
    if has_rd:
        txt_file.write("rd\t{}\n".format(rd_bins[np.argmax(lkhd_rd)]))
        txt_file.write("rd_limits\t{}\t{}\n".format(
            fit_rd_bins[fit_rd_bds_lwr], fit_rd_bins[fit_rd_bds_upr]))
        param_num += 1
    if has_rm:
        txt_file.write("rm\t{}\n".format(rm_bins[np.argmax(lkhd_rm)]))
        # txt_file.write("rm\t{}\n".format(fit_rm))#rm_bins[np.argmax(lkhd_rm)]))
        txt_file.write("rm_limits\t{}\t{}\n".format(
            fit_rm_bins[fit_rm_bds_lwr], fit_rm_bins[fit_rm_bds_upr]))
        param_num += 1
    txt_file.write("cost\t{}\n".format(np.min(result2)))
    dof = (
        5 *
        15) - param_num  #Five mass bins w/ halos. Each halo has 15 radial bins
    txt_file.write("X_red\t{}\n".format(np.min(result2) / dof))
示例#22
0
def query(param_fname):
    param = dtk.Param(param_fname)
    query_data_folder = param.get_string("query_data_folder")
    cluster_size_max  = param.get_bool("cluster_size_max")
    cluster_size      = param.get_int("cluster_size")
    cluster_start     = param.get_int("cluster_start")
    random_size_max   = param.get_bool("random_size_max")
    random_size       = param.get_int("random_size")
    random_start      = param.get_int("random_start")
    query_galaxy_only = param.get_bool("query_galaxy_only")
    r200_factor       = param.get_float("r200_factor") 
    cosmology_name    = param.get_string("cosmology_name")

    if "richness_mass_author" in param:
        richness_mass_author = param.get_string("richness_mass_author")
    else:
        richness_mass_author = "Rykoff_crit"
    if "mass_type" in param:
        mass_type = param.get_string("mass_type")
        assert (mass_type in ['critical', 'crit', 'mean']), "Mass type ("+mass_type+") not understood"
    else:
        mass_type = "critical"

    if "cluster_use_random_positions" in param:
        cluster_use_random_positions = param.get_bool("cluster_use_random_positions")
    else:
        cluster_use_random_positions = False

    if "query_random" in param:
        query_random = param.get_bool("query_random")
    else:
        query_random = True

    if "query_cluster" in param:
        query_cluster = param.get_bool("query_cluster")
    else:
        query_cluster = True

    if "spider_clusters" in param:
        spider_clusters = param.get_bool("spider_clusters")
    else:
        spider_clusters = False
    if "spider_mean" in param:
        spider_mean = param.get_bool("spider_mean")
    else:
        spider_mean = False
    if "spider_bcg_center" in param:
        spider_bcg_center = param.get_bool("spider_bcg_center")
    else:
        spider_bcg_center = False
    if "spider_mass_from_richness" in param:
        spider_mass_from_richness = param.get_bool("spider_mass_from_richness")
    else:
        spider_mass_from_richness = False

    cosmo = background.set_cosmology(cosmology_name)
    dtk.ensure_dir(query_data_folder)


    if query_random:
        print("Querying random fields...")
        rand_cat = load_redmapper_randoms_fits("redmapper_dr8_public_v6.3_randoms.fits")
        if(random_size_max):
            random_size = cat['ra'].size
        query_sdss_culster(query_data_folder, rand_cat['ra'],
                           rand_cat['dec'], rand_cat['z'],
                           rand_cat['lambda'], "rnd", random_size,
                           start=random_start, plot=False,
                           query_galaxy_only=query_galaxy_only,
                           r200_factor=r200_factor,
                           richness_mass_author=richness_mass_author)
    else:
        print ("Not quering random fields...")
    
    if query_cluster:
        print( "Querying redmapper clusters...")
        print(spider_clusters)
        if not spider_clusters:
            cluster_cat = load_redmapper_cluster_fits("redmapper_dr8_public_v6.3_catalog.fits")
            spider_rad = None
        else:
            cluster_cat = load_spider_fits("/media/luna1/dkorytov/data/spider_xray/catCluster-SPIDERS_RASS_CLUS-v2.0.fits")
            if spider_bcg_center:
                spider_bcg_center = load_spiders_bcg_fits("./SpidersXclusterBCGs-v2.0.fits")
                cluster_cat = combine_spiders_bcg(cluster_cat, spider_bcg_center)
                cluster_cat['ra'] = cluster_cat['ra_bcg']
                cluster_cat['dec'] = cluster_cat['dec_bcg']
            if spider_mass_from_richness:
                spider_rad = None # use the default richness -> mass conversion. 
                print("spider mass from richness")
            else:
                spider_rad = cluster_cat['r200c_deg']
        if(cluster_size_max):
            cluster_size = cluster_cat['ra'].size
        if(cluster_use_random_positions ):
            raise
            cluster_cat['ra'][:cluster_size]  = rand_cat['ra'][:cluster_size]
            cluster_cat['dec'][:cluster_size] = rand_cat['dec'][:cluster_size]
        # query_cat(cat, 
        query_sdss_culster(query_data_folder, cluster_cat['ra'],
                           cluster_cat['dec'], cluster_cat['z'],
                           cluster_cat['lambda'], "gal", cluster_size,
                           start=cluster_start, plot=False,
                           spider_rad=spider_rad,
                           spider_mean=spider_mean,
                           r200_factor=r200_factor,
                           richness_mass_author=richness_mass_author,
        )
    else:
        print("Not querying redmapper clusters...")
示例#23
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')
示例#24
0
#!/usr/bin/env python2.7

import numpy as np
import matplotlib.pyplot as plt
import dtk
import sys
import myutil
import h5py

param1 = dtk.Param(sys.argv[1])
param2 = dtk.Param(sys.argv[2])

output1 = param1.get_string('output')
output_mod1 = output1.replace(".hdf5", "_mod.hdf5")
hfile1 = h5py.File(output_mod1, 'r')

output2 = myutil.get_output_loc(param2)
output_mod2 = output2.replace(".hdf5", "_mod.hdf5")
hfile2 = h5py.File(output_mod2, 'r')

match_list = []
mismatch_list = []
mismatch_val = []
only_1_list = []
only_2_list = []


def check_group(hgroup1, hgroup2):
    hobjects1 = []
    hobjects2 = []
    hgroup1.visit(hobjects1.append)
示例#25
0
    for ch_id in ids:
        slct = chain_id == ch_id
        ssq.append(np.var(data[slct]))
        chain_avg = np.mean(data[slct])
        B += (chain_avg - global_avg)**2
    W = np.mean(ssq)
    B = n / (m - 1.0) * B
    var = (n - 1.0) / n * W + 1.0 / n * B
    R = np.sqrt(var / W)
    return R


if (__name__ == '__main__'):
    print "Gelman Ruben Test"
    param_file_name = sys.argv[1]
    param = dtk.Param(param_file_name)
    file_loc = "output/" + param_file_name + "/mcmc.gio"
    print "loading data"
    mcmc_id = dtk.gio_read(file_loc, "mcmc_walker_id")
    mcmc_step = dtk.gio_read(file_loc, "mcmc_walker_step")
    mcmc_mi = dtk.gio_read(file_loc, "mcmc_mass_infall")
    mcmc_rd = dtk.gio_read(file_loc, "mcmc_r_disrupt")

    print "data loaded"
    slct_half = mcmc_step > np.max(mcmc_step) / 2.0
    print "M_infall: ", gelman_ruben_test(mcmc_mi[slct_half],
                                          mcmc_id[slct_half])
    print "R_dispupt: ", gelman_ruben_test(mcmc_rd[slct_half],
                                           mcmc_id[slct_half])
    if (param.get_bool("fit_r_merger")):
        mcmc_rm = dtk.gio_read(file_loc, "mcmc_r_merger")
示例#26
0
#!/usr/bin/env python2.7

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as clrs
import dtk

params = dtk.Param("mcmc/test.param")

m_i = np.array(params.get_float_list("m_i"))
r_d = np.array(params.get_float_list("r_d"))
r_f = np.array(params.get_float_list("r_f"))
r_m = np.array(params.get_float_list("r_m"))
print min(m_i), max(m_i)
print min(r_d), max(r_d)

plt.figure()
plt.plot(m_i, r_d, '.', alpha=.3)
plt.yscale('log')
plt.xscale('log')
plt.xlabel('m_infall')
plt.ylabel('r_disrupt')
plt.grid()

plt.figure()
H, x_bins, y_bins = np.histogram2d(m_i,
                                   r_d,
                                   bins=(np.logspace(10, 12, 100),
                                         np.logspace(-2, -1, 100)))
print H
plt.pcolor(x_bins, y_bins, H.T, cmap='PuBu', norm=clrs.LogNorm())
示例#27
0
def query_mask(param_fname):
    global num_pass
    global num_fail

    param = dtk.Param(param_fname)
    query_data_folder = param.get_string("query_data_folder")
    cosmology_name = param.get_string("cosmology_name")
    cluster_size_max = param.get_bool("cluster_size_max")
    cluster_size = param.get_int("cluster_size")
    cluster_start = param.get_int("cluster_start")
    random_size_max = param.get_bool("random_size_max")
    random_size = param.get_int("random_size")
    random_start = param.get_int("random_start")

    query_galaxy_only = param.get_bool("query_galaxy_only")
    r200_factor = param.get_float("r200_factor")

    if "richness_mass_author" in param:
        richness_mass_author = param.get_string("richness_mass_author")
    else:
        richness_mass_author = "Rykoff"
    print "Richness mass author: ", richness_mass_author

    if "clusters_query" in param:
        clusters_query = param.get_bool("clusters_query")
    else:
        clusters_query = True

    if "randoms_query" in param:
        randoms_query = param.get_bool("randoms_query")
    else:
        randoms_query = True
    if "spider_clusters" in param:
        spider_clusters = param.get_bool("spider_clusters")
    else:
        spider_clusters = False
    if "spider_mean" in param:
        spider_mean = param.get_bool("spider_mean")
    else:
        spider_mean = False
    if "spider_bcg_center" in param:
        spider_bcg_center = param.get_bool("spider_bcg_center")
    else:
        spider_bcg_center = False
    if "spider_mass_from_richness" in param:
        spider_mass_from_richness = param.get_bool("spider_mass_from_richness")
    else:
        spider_mass_from_richness = False

    dtk.ensure_dir(query_data_folder)
    background.set_cosmology(cosmology_name)

    num_pass = 0
    num_fail = 0

    if clusters_query:
        print "Querying redmapper clusters..."
        if not spider_clusters:
            cluster_cat = load_redmapper_cluster_fits(
                "redmapper_dr8_public_v6.3_catalog.fits")
            spider_rad = None
        else:
            cluster_cat = load_spider_fits(
                "/media/luna1/dkorytov/data/spider_xray/catCluster-SPIDERS_RASS_CLUS-v2.0.fits"
            )
            if spider_bcg_center:
                print "spider bcg center"
                spider_bcg_center = load_spiders_bcg_fits(
                    "./SpidersXclusterBCGs-v2.0.fits")
                cluster_cat = combine_spiders_bcg(cluster_cat,
                                                  spider_bcg_center)
                cluster_cat['ra'] = cluster_cat['ra_bcg']
                cluster_cat['dec'] = cluster_cat['dec_bcg']

            if spider_mass_from_richness:
                spider_rad = None  # use the default richness -> mass conversion.
                print "spider mass from richness"
            else:
                spider_rad = cluster_cat['r200c_deg']

        if (cluster_size_max):
            cluster_size = cluster_cat['ra'].size
        query_sdss_mask(query_data_folder,
                        cluster_cat['ra'],
                        cluster_cat['dec'],
                        cluster_cat['z'],
                        cluster_cat['lambda'],
                        "gal",
                        cluster_size,
                        r200_factor=r200_factor,
                        start=cluster_start,
                        plot=False,
                        save_data=True,
                        spider_rad=spider_rad,
                        richness_mass_author=richness_mass_author)

    if randoms_query:
        print "Querying random fields..."
        rand_cat = load_redmapper_randoms_fits(
            "redmapper_dr8_public_v6.3_randoms.fits")
        if (random_size_max):
            random_size = rand_cat['ra'].size
        query_sdss_mask(query_data_folder,
                        rand_cat['ra'],
                        rand_cat['dec'],
                        rand_cat['z'],
                        rand_cat['lambda'],
                        "rnd",
                        random_size,
                        r200_factor=r200_factor,
                        start=random_start,
                        plot=False,
                        save_data=True,
                        richness_mass_author=richness_mass_author)
示例#28
0
#!/usr/bin/env python2.7

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as clr
import sys
import dtk

param_file_name = sys.argv[1]
i = 0
dtk.set_fig_path("figs/" + param_file_name + "/" + __file__ + "/")
while (True):

    param = dtk.Param("output/" + param_file_name + "/" + __file__ +
                      "/lgrid.param")
    # if(sys.argv[1] == 'cpp'):
    #     param = dtk.Param("tmp/clstr%d.param"%i)
    # elif(sys.argv[1] == 'py'):
    #     param = dtk.Param("tmp/clstr%d_py.param"%i)
    # else:
    #     print "no \"cpp\"/\"py\" argument afterwards. Quitting"
    halo_x = param.get_float("halo_x")
    halo_y = param.get_float("halo_y")
    halo_m = param.get_float("halo_mass")
    halo_r = param.get_float("halo_radius")

    core_x = np.array(param.get_float_list("core_x"))
    core_y = np.array(param.get_float_list("core_y"))
    core_r = np.array(param.get_float_list("core_r"))
    core_m = np.array(param.get_float_list("core_m"))
    print np.min(core_r), "->", np.max(core_r)
示例#29
0
#!/usr/bin/env python2.7

import numpy as np
import matplotlib.pyplot as plt
import dtk

param = dtk.Param("tmp/fof_test.param")
x = np.array(param.get_float_list("x"))
y = np.array(param.get_float_list("y"))
z = np.array(param.get_float_list("z"))
c = np.array(param.get_int_list("c"))
clrs = np.unique(c)
print clrs.size, '/', c.size

plt.figure()
plt.scatter(x, y, c=c, edgecolor='none')
plt.xlim((0, 5))
plt.ylim((0, 5))
plt.grid()
plt.show()
def plot_saved_clusters(param_fname):
    param = dtk.Param(param_fname)
    query_data_file = param.get_string(
        'query_data_folder') + 'query_results.hdf5'
    mstar_offset = param.get_int('mstar_cut_offset')

    query_results = param.get_string("query_data_folder")
    query_cluster_all = param.get_bool('query_cluster_all')
    query_cluster_num = param.get_int('query_cluster_num')
    query_type = param.get_string('query_type')

    cosmology_name = param.get_string("cosmology_name")
    galaxy_type = param.get_int("galaxy_type")
    galaxy_weight = param.get_int("galaxy_weight")
    galaxy_color_type = param.get_int("galaxy_color_type")
    galaxy_mag_type = param.get_int("galaxy_mag_type")
    galaxy_color_lim = param.get_float_list("galaxy_color_lim%d" %
                                            galaxy_color_type)
    galaxy_mag_lim = param.get_float_list("galaxy_mag_lim%d" % galaxy_mag_type)

    background_folder = param.get_string("background_folder")
    background_force = param.get_bool("background_force")
    background_all = param.get_bool("background_all")
    background_num = param.get_int("background_num")
    # z bins for background estimate
    background_z_start = param.get_float('background_z_start')
    background_z_end = param.get_float('background_z_end')
    background_z_num = param.get_float('background_z_num')

    # external data such as spt
    spt_plot = param.get_bool("spt_plot")
    spt_file = param.get_string("spt_file")

    #params for the final cluster bining
    z_bins_num = param.get_int("z_bins")
    z_bins_start = param.get_float("z_bins_start")
    z_bins_end = param.get_float("z_bins_end")

    mass_bins_num = param.get_int("mass_bins")
    mass_bins_start = param.get_float("mass_bins_start")
    mass_bins_end = param.get_float("mass_bins_end")

    radial_r200_rescale = param.get_bool('radial_r200_rescale')
    radial_bin_num = param.get_int('radial_bin_num')
    radial_bin_kpc_min = param.get_float('radial_bin_kpc_min')
    radial_bin_kpc_max = param.get_float('radial_bin_kpc_max')
    radial_bin_r200_min = param.get_float('radial_bin_r200_min')
    radial_bin_r200_max = param.get_float('radial_bin_r200_max')

    RS_line_plot = param.get_bool('RS_line_plot')

    #params for saving the resulting profiles

    result_folder = param.get_string("result_folder")

    if ('mstar_cut_offset' in param.data.keys()):
        mstar_cut_offset = param.get_float('mstar_cut_offset')
    else:
        mstar_cut_offset = 1.0

    if 'background_r200_factor' in param:
        background_r200_factor = param.get_float('background_r200_factor')
    else:
        background_r200_factor = 1.0

    if 'richness_mass_author' in param:
        richness_mass_author = param.get_string("richness_mass_author")
    else:
        richness_mass_author = None

    if 'convert_m200m_to_m200c' in param:
        convert_m200m_to_m200c = param.get_bool('convert_m200m_to_m200c')
    else:
        convert_m200m_to_m200c = False
    if 'convert_m200c_to_m200m' in param:
        convert_m200c_to_m200m = param.get_bool('convert_m200c_to_m200m')
    else:
        convert_m200c_to_m200m = False
    #######################
    ## Processing Params ##
    #######################

    background_z_bins = np.linspace(background_z_start, background_z_end,
                                    int(background_z_num))

    if (galaxy_type == 1):
        galaxy_type_name = "all"
    elif (galaxy_type == 2):
        galaxy_type_name = "red"
    elif (galaxy_type == 3):
        galaxy_type_name = "non-red"
    else:
        print("unknwon galaxy type")
        raise
    if (galaxy_weight == 1):
        galaxy_weight_name = "normal"
    elif (galaxy_weight == 2):
        galaxy_weight_name = "red squence"
    elif (galaxy_weight == 3):
        galaxy_weight_name = 'red squence rykoff'
    else:
        print("unknown galaxy weight")
        raise

    if (galaxy_color_type == 1):
        galaxy_color_name = 'g-r'
    elif (galaxy_color_type == 2):
        galaxy_color_name = 'g-r - RS(z)'
    if (galaxy_mag_type == 1):
        galaxy_mag_name = 'i'
    elif (galaxy_mag_type == 2):
        galaxy_mag_name = 'i-m*(z)'

    background.set_gal_clr_type(galaxy_color_type, galaxy_color_lim)
    background.set_gal_mag_type(galaxy_mag_type, galaxy_mag_lim)
    background.set_gal_type_weight(galaxy_type, galaxy_weight)
    background.set_cosmology(cosmology_name)
    background.set_mstar_cut(mstar_cut_offset)

    background.set_mstar_cut(param.get_float('mstar_cut_offset'))
    [dataclstr, datagal, data_pass_mask, clstr_num] = background.get_clstr(
        query_type,
        query_results,
        100,
        till_end=False,

        # query_cluster_num,
        # till_end=query_cluster_all,
        richness_mass_author=richness_mass_author,
        convert_m200c_to_m200m=convert_m200c_to_m200m,
        convert_m200m_to_m200c=convert_m200m_to_m200c)

    for i in range(0, 400):
        print(list(dataclstr[i].keys()))
        print(list(datagal[i].keys()))
        gal_prop = dataclstr[i]
        gal = datagal[i]
        rad = float(gal_prop['r200_arcmin']) / 60
        dec = float(gal_prop['dec'])
        ra = float(gal_prop['ra'])
        mass = float(gal_prop['m200'])
        z = float(gal_prop['z'])
        if dec > 10 or mass < 2e14 or z > 0.35:
            continue
        plt.figure()
        print(ra, dec, rad)
        # c1 = plt.Circle((ra, dec), rad, fill=True, color='r', lw=2)
        e_r200 = matplotlib.patches.Ellipse((ra, dec),
                                            rad / np.cos(dec / 360) * 2.0,
                                            rad * 2.0,
                                            fill=False,
                                            color='k',
                                            lw=2)
        plt.gca().add_artist(e_r200)
        # plotting radial bins
        for j in range(0, 16):
            rad_bin = float(j) / 16 * rad
            e_bin = matplotlib.patches.Ellipse(
                (ra, dec),
                rad_bin / np.cos(dec / 360) * 2.0,
                rad_bin * 2.0,
                fill=False,
                color='k',
                lw=1,
                ls='--')
            plt.gca().add_artist(e_bin)

        plt.ylabel('Dec [deg]')
        plt.xlabel('Ra [deg]')
        plt.plot([], [], 'k', lw=2, label='$R_{200c}$')
        plt.plot([], [], 'k', ls='--', label='radial bins')

        ## Galaxies
        #          bright               saturated             satur_center         nopetro             deblended_as_moving
        cut_flgs = 0x0000000000000002 | 0x0000000000040000 | 0x0000080000000000 | 0x0000000000000100 | 0x0000000100000000
        flgs = gal['flags_i'] | gal['flags_r'] | gal['flags_g']
        slct1 = gal['type'] != 31
        slct2 = np.logical_not(flgs & cut_flgs)
        slct3 = gal['m_i'] < background.m_cut(z)
        slct = slct1 & slct2 & slct3

        plt.plot(gal['ra'][slct],
                 gal['dec'][slct],
                 '.',
                 alpha=0.6,
                 label='galaxies')
        plt.text(
            0.05,
            0.05,
            'M$_{{200c}}$=\n{:2.2e}[$h^{{-1}}$M$_{{\odot}}$]'.format(mass),
            transform=plt.gca().transAxes,
            verticalalignment='bottom',
            horizontalalignment='left')
        plt.text(0.95,
                 0.05,
                 'z={:.2f}'.format(z),
                 transform=plt.gca().transAxes,
                 verticalalignment='bottom',
                 horizontalalignment='right')

        plt.legend(framealpha=0.0, labelspacing=0)
        plt.axis('equal')
        pyplot_zoom_out(top=0.2, right=-0.5, left=0.3)
        plt.tight_layout()
        dtk.save_figs('figs/' + __file__ + '/', '.pdf')
        plt.close('all')