nbodykit includes several methods for generating mock catalogs, with varying
levels of sophistication. These CatalogSource
objects allow users to create catalogs of objects at run time and include:
nbodykit includes two subclasses of
CatalogSource
that
generate particles randomly in a box: RandomCatalog
and UniformCatalog
. While these catalogs do not produce
realistic cosmological distributions of objects, they are especially useful
for generating catalogs quickly and for testing purposes.
RandomCatalog
¶The RandomCatalog
class includes a random number generator
with the functionality of numpy.random.RandomState
that generates
random numbers in parallel and in a manner that is independent of the number
of MPI ranks being used. This property is especially useful for running
reproducible tests where the number of CPUs might vary. The random number
generator is stored as the rng
attribute.
Users can use this random number generator to add columns to the catalog,
using the syntax to add columns.
For example,
In [1]: from nbodykit.lab import RandomCatalog
In [2]: import numpy
# initialize a catalog with only the default columns
In [3]: cat = RandomCatalog(csize=100) # collective size of 100
In [4]: print("columns = ", cat.columns) # only the default columns present
columns = ['Selection', 'Value', 'Weight']
# add mass uniformly distributed in log10
In [5]: cat['Mass'] = 10**(cat.rng.uniform(12, 15, size=cat.size))
# add normally distributed velocity
In [6]: cat['Velocity'] = cat.rng.normal(loc=0, scale=500, size=cat.size)
In [7]: print(cat.columns)
['Mass', 'Selection', 'Value', 'Velocity', 'Weight']
Caveats
rng
attribute, please see the API documentation for MPIRandomState
.size
attribute. Most functions
of the rng
attribute accept the size
keyword to generate an array of the correct size.UniformCatalog
¶The UniformCatalog
is a subclass of
RandomCatalog
that includes Position
and Velocity
columns that are uniformly distributed. The positions of the particles are
uniformly distributed between zero and the size of the box (as specified by
the user), with an input number density. The velocities are also
uniformly distributed but on a scale that is 1% of the size of the box.
For example,
In [8]: from nbodykit.lab import UniformCatalog
In [9]: cat = UniformCatalog(nbar=100, BoxSize=1.0, seed=42)
In [10]: print("columns = ", cat.columns)
columns = ['Position', 'Selection', 'Value', 'Velocity', 'Weight']
# min must be greater than 0
In [11]: print("position minimum = ", cat.compute(cat['Position'].min()))