In [1]:
# this cell is hidden via the metadata
from nbodykit import style
import matplotlib.pyplot as plt
plt.style.use(style.notebook)

In [2]:
from nbodykit.lab import UniformCatalog

cat = UniformCatalog(nbar=100, BoxSize=1.0, seed=42)

mesh = cat.to_mesh(Nmesh=16)

print("mesh = ", mesh)


/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
mesh =  (UniformCatalog(size=96, seed=42) as CatalogMesh)

In [3]:
from nbodykit.lab import LinearMesh, cosmology
from matplotlib import pyplot as plt

cosmo = cosmology.Planck15
Plin = cosmology.LinearPower(cosmo, redshift=0, transfer='EisensteinHu')

# initialize the mesh
mesh = LinearMesh(Plin, Nmesh=128, BoxSize=1380, seed=42)

# preview the density field
plt.imshow(mesh.preview(axes=[0,1]))


Out[3]:
<matplotlib.image.AxesImage at 0x7f0b1af1b6d8>

In [4]:
from nbodykit.lab import FieldMesh
from pmesh.pm import RealField, ComplexField, ParticleMesh

# a 8^3 mesh
pm = ParticleMesh(Nmesh=[8,8,8])

# initialize a RealField
rfield = RealField(pm)

# set entire mesh to unity
rfield[...] = 1.0

# initialize from the RealField
real_mesh = FieldMesh(rfield)

# can also initialize from a ComplexField
cfield = rfield.r2c()
complex_mesh = FieldMesh(cfield)

In [5]:
from nbodykit.lab import ArrayMesh
import numpy

# generate random data on a 128^3 mesh
data = numpy.random.random(size=(128,128,128))

# inititalize the mesh
mesh = ArrayMesh(data, BoxSize=1.0)

# preview the density mesh
plt.imshow(mesh.preview(axes=[0,1]))


Out[5]:
<matplotlib.image.AxesImage at 0x7f0b1aebf0b8>