In [1]:
from nbodykit.lab import RandomCatalog
import numpy

# initialize a catalog with only the default columns
cat = RandomCatalog(csize=100) # collective size of 100
print("columns = ", cat.columns) # only the default columns present

# add mass uniformly distributed in log10
cat['Mass'] = 10**(cat.rng.uniform(12, 15))

# add normally distributed velocity
cat['Velocity'] = cat.rng.normal(loc=0, scale=500)

print(cat.columns)


columns =  ['Selection', 'Value', 'Weight']
['Mass', 'Selection', 'Value', 'Velocity', 'Weight']
/home/yfeng1/anaconda3/install/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters

In [2]:
from nbodykit.lab import UniformCatalog

cat = UniformCatalog(nbar=100, BoxSize=1.0, seed=42)
print("columns = ", cat.columns)

# min must be greater than 0
print("position minimum = ", cat.compute(cat['Position'].min()))

# max must be less than 1.0
print("position maximum = ", cat.compute(cat['Position'].max()))

# min must be greater than 0
print("velocity minimum = ", cat.compute(cat['Velocity'].min()))

# max must be less than 0.01
print("velocity maximum = ", cat.compute(cat['Velocity'].max()))


columns =  ['Position', 'Selection', 'Value', 'Velocity', 'Weight']
position minimum =  0.00015684966390538957
position maximum =  0.9992508603400948
velocity minimum =  2.4238347118806793e-05
velocity maximum =  0.00999869916263692

In [3]:
from nbodykit.lab import HaloCatalog, cosmology

# uniform objects in a box
cat = UniformCatalog(nbar=100, BoxSize=1.0, seed=42)

# add a Mass column to the objects
cat['Mass'] = 10**(cat.rng.uniform(12, 15))

# initialize the halos
halos = HaloCatalog(cat, cosmo=cosmology.Planck15, redshift=0., mdef='vir', position='Position', velocity='Velocity', mass='Mass')

print(halos.columns)


['Concentration', 'Mass', 'Position', 'Radius', 'Selection', 'Value', 'Velocity', 'VelocityOffset', 'Weight']

In [4]:
halocat = halos.to_halotools()

print(halocat)

print(halocat.halo_table[:10])


<halotools.sim_manager.user_supplied_halo_catalog.UserSuppliedHaloCatalog object at 0x7f78f96c0198>
       halo_x              halo_y       ... halo_upid halo_local_id
------------------- ------------------- ... --------- -------------
0.45470105222137214  0.8326320323149597 ...      -1.0             0
0.31944725103976734 0.48518719297596336 ...      -1.0             1
0.21242627399222258 0.16674683796980805 ...      -1.0             2
 0.3185452432219371  0.3490676632113582 ...      -1.0             3
 0.5066846142238558 0.23705948996927073 ...      -1.0             4
0.47273713613639634  0.8569679300356892 ...      -1.0             5
0.45934116150501314  0.9523800798479475 ...      -1.0             6
 0.9244771851038425  0.8843779857073643 ...      -1.0             7
 0.4553655200041342  0.8086086697963959 ...      -1.0             8
 0.5231105620516908 0.10008694708748456 ...      -1.0             9

In [5]:
from nbodykit.hod import Zheng07Model
hod = halos.populate(Zheng07Model, alpha=0.5, sigma_logM=0.40, seed=42)

print("total number of HOD galaxies = ", hod.csize)
print(hod.columns)

print("number of centrals = ", hod.compute((hod['gal_type']==0).sum()))
print("number of satellites = ", hod.compute((hod['gal_type']==1).sum()))


total number of HOD galaxies =  291
['Position', 'Selection', 'Value', 'Velocity', 'VelocityOffset', 'Weight', 'conc_NFWmodel', 'gal_type', 'halo_hostid', 'halo_id', 'halo_mvir', 'halo_num_centrals', 'halo_num_satellites', 'halo_rvir', 'halo_upid', 'halo_vx', 'halo_vy', 'halo_vz', 'halo_x', 'halo_y', 'halo_z', 'host_centric_distance', 'vx', 'vy', 'vz', 'x', 'y', 'z']
number of centrals =  94
number of satellites =  197

In [6]:
# repopulate, just changing the random seed
hod.repopulate(seed=84)
print("total number of HOD galaxies = ", hod.csize)

print("number of centrals = ", hod.compute((hod['gal_type']==0).sum()))
print("number of satellites = ", hod.compute((hod['gal_type']==1).sum()))

# re-populate with new parameters
hod.repopulate(logM0=13.2, logM1=14.5)
print("total number of HOD galaxies = ", hod.csize)

print("number of centrals = ", hod.compute((hod['gal_type']==0).sum()))
print("number of satellites = ", hod.compute((hod['gal_type']==1).sum()))


total number of HOD galaxies =  282
number of centrals =  95
number of satellites =  187
total number of HOD galaxies =  141
number of centrals =  93
number of satellites =  48

In [7]: