Populate random subvolume of a simulation box and compute the correlation function for the mock with precomputed RR pairs

  • First add a subvolume id column to the halo catalogue

In [3]:
import numpy as np
from halotools.sim_manager import CachedHaloCatalog
from halotools.empirical_models import PrebuiltHodModelFactory


# use the z=0 slice of Multidark
halocat = CachedHaloCatalog(simname='multidark', halo_finder='rockstar', redshift=0.)
  
   
# define function to pass to HOD model to add column to halo table
def mk_id_column(table=None):

    # set up ids from 0 to 124 for the box split into 5 along each edge
    edges = np.linspace(0, 800, 5)
    
    xs = table["halo_x"]
    ys = table["halo_y"]
    zs = table["halo_z"]

    subvol_ids = np.empty(xs.shape)
    for i in xrange(len(xs)):
        xi = np.where(edges < xs[i])[0][-1]
        yi = np.where(edges < ys[i])[0][-1]
        zi = np.where(edges < zs[i])[0][-1]
        subvol_ids[i] = zi * 25 + yi * 5 + xi
    
    return subvol_ids


model = PrebuiltHodModelFactory('zheng07', threshold=-20., redshift=0.)
model.new_haloprop_func_dict = {'sim_subvol': mk_id_column}
  • Now, populate a random subvolume with galaxies

In [4]:
# randomly choose the id of the subvolume to populate
randvol_id = np.random.randint(125)

# define a masking function to find the model halos that are in the selected subvolume
def mask_func(halo_table, subvol_index):
    ids = halo_table["sim_subvol"]
    return np.where(ids == subvol_index)[0]

# create a restricted version of this function which already has the random id passed to it
mocksubvol = lambda x: mask_func(x, randvol_id)

# and now pass this lambda function to the populate_mock method
model.populate_mock(halocat=halocat, masking_function=mocksubvol, enforce_PBC=False)


...Building lookup tables for the NFWPhaseSpace radial profile.
    (This will take about 5 seconds, and only needs to be done once)

In [7]:
# And check that this worked
print randvol_id

print np.min(model.mock.galaxy_table['x'])
print np.max(model.mock.galaxy_table['x'])
print np.min(model.mock.galaxy_table['y'])
print np.max(model.mock.galaxy_table['y'])
print np.min(model.mock.galaxy_table['z'])
print np.max(model.mock.galaxy_table['z'])


70
-0.191926146868
200.191156366
799.149702602
1000.51431675
399.958869767
600.175313312

In [ ]: