Example #1
0
def load_sim_data(cfg):
    """Load the UniverseMachine data."""

    #read in halocat
    halocat = CachedHaloCatalog(
        simname=cfg['sim_name'],
        halo_finder=cfg['sim_halo_finder'],
        version_name=cfg['sim_version_name'],
        redshift=cfg['sim_z'],
        ptcl_version_name=cfg['sim_ptcl_version_name'])  # doctest: +SKIP

    #read in particle table
    ptcl_table = Table.read(os.path.join(cfg['data_location'], cfg['sim_dir'],
                                         cfg['sim_particle_file']),
                            path='data')
    px = ptcl_table['x']
    py = ptcl_table['y']
    pz = ptcl_table['z']
    particles = np.vstack((px, py, pz)).T
    ptcl_table = 0

    #downsample
    num_ptcls_to_use = int(1e4)
    particles = randomly_downsample_data(particles, num_ptcls_to_use)
    particle_masses = np.zeros(num_ptcls_to_use) + halocat.particle_mass
    downsampling_factor = (cfg['sim_particles_per_dimension']**3) / float(
        len(particles))

    # other parameters
    cfg['sim_cosmo'] = FlatLambdaCDM(H0=cfg['sim_h0'] * 100.0,
                                     Om0=cfg['sim_omega_m'])

    cfg['sim_volume'] = np.power(cfg['sim_lbox'] / cfg['sim_h0'], 3)
    #     if verbose:
    #         print("# The volume of the UniverseMachine mock is %15.2f Mpc^3" %
    #               cfg['um_volume'])

    return {
        'halocat': halocat,
        'particles': particles,
        'particle_masses': particle_masses,
        'downsampling_factor': downsampling_factor
    }, cfg
Example #2
0
N_parts_down = N_parts // 40  #used to be 4
down_parts_fname = "../pos_parts_down_" + str(N_parts_down) + ".npy"

test = False
if os.path.isfile(down_parts_fname):
    pos_parts = np.load(down_parts_fname)
else:
    if test:
        Npts = int(1e5)
        x = np.random.uniform(0, Lbox, Npts)
        y = np.random.uniform(0, Lbox, Npts)
        z = np.random.uniform(0, Lbox, Npts)
        pos_parts = np.vstack((x, y, z)).T
    else:
        pos_parts = np.load(dir_part + part_fn) / 1000.  # in Mpc/h
    pos_parts = randomly_downsample_data(pos_parts, N_parts_down)
    print(pos_parts.shape[0])
    np.save(down_parts_fname, pos_parts)

if test:
    Npts = int(1.2e4)
    x = np.random.uniform(0, Lbox, Npts)
    y = np.random.uniform(0, Lbox, Npts)
    z = np.random.uniform(0, Lbox, Npts)
    pos_gals = np.vstack((x, y, z)).T
else:
    pos_gals = np.load("../" + ext1 + "/true_gals.npy")

if test:
    Npts = int(1.2e4)
    x = np.random.uniform(0, Lbox, Npts)
Example #3
0
num_ptcls_to_use = int(1e6)
particle_masses = np.zeros(
    num_ptcls_to_use) + halocat.particle_mass / particle_portion
total_num_ptcls_in_snapshot = len(halocat.ptcl_table)
downsampling_factor = total_num_ptcls_in_snapshot / float(num_ptcls_to_use)
##ggl

pi_max = 60
r_wp = np.logspace(-1, np.log10(Lbox) - 1, 20)
##wp

pos_part = return_xyz_formatted_array(*(halocat.ptcl_table[ax]
                                        for ax in 'xyz'),
                                      period=Lbox)

pos_part = randomly_downsample_data(pos_part, num_ptcls_to_use)

#########################################################


def calc_all_observables(param):

    model.param_dict.update(dict(
        zip(param_names,
            param)))  ##update model.param_dict with pairs (param_names:params)
    c = Ngal_estimate(halocat, param)
    n_est = c.ngal_estimate()
    if n_est < 1e5 and n_est > 7.8e4:
        try:
            model.mock.populate()
        except:
Example #4
0
    pos_g = pos_g_opt.copy()

N_m = pos_m.shape[0]
down = 5000
N_m_down = N_m // down
print("Number of pcles = ", N_m_down)
print("Downsampling...")
try:
    pos_m = np.load("../pos_m_down_" + str(down) + ".npy")
except:
    #x_m = pos_m[::down,0]
    #y_m = pos_m[::down,1]
    #z_m = pos_m[::down,2]
    #pos_m = np.vstack((x_m,y_m,z_m)).T

    pos_m = randomly_downsample_data(pos_m, N_m_down)

    print(pos_m.shape[0])
    np.save("../pos_m_down_" + str(down) + ".npy", pos_m)
    plt.scatter(pos_m[:, 0], pos_m[:, 1], s=0.01)
    plt.show()
print("Downsampled O.o!")

down_fac = N_m / N_m_down
pcle_mass *= down_fac

N_g = pos_g.shape[0]
N_g_opt = pos_g.shape[0]
print("Number of gals = ", N_g)

pos_m = pos_m.astype(np.float32)