nbodykit.mockmaker

Functions

gaussian_complex_fields(pm, linear_power, seed)

Make a Gaussian realization of a overdensity field, \(\delta(x)\).

gaussian_real_fields(pm, linear_power, seed)

Make a Gaussian realization of a overdensity field in real-space \(\delta(x)\).

lognormal_transform(density[, bias])

Apply a (biased) lognormal transformation of the density field by computing:

poisson_sample_to_points(delta, …[, bias, …])

Poisson sample the linear delta and displacement fields to points.

nbodykit.mockmaker.gaussian_complex_fields(pm, linear_power, seed, unitary_amplitude=False, inverted_phase=False, compute_displacement=False, logger=None)[source]

Make a Gaussian realization of a overdensity field, \(\delta(x)\).

If specified, also compute the corresponding 1st order Lagrangian displacement field (Zel’dovich approximation) \(\psi(x)\), which is related to the linear velocity field via:

\[v(x) = f a H \psi(x)\]

Notes

This computes the overdensity field using the following steps:

  1. Generate complex variates with unity variance

  2. Scale the Fourier field by \((P(k) / V)^{1/2}\)

After step 2, the complex field has unity variance. This is equivalent to generating real-space normal variates with mean and unity variance, calling r2c() and dividing by \(N^3\) since the variance of the complex FFT (with no additional normalization) is \(N^3 \times \sigma^2_\mathrm{real}\).

Furthermore, the power spectrum is defined as V * variance. So a normalization factor of 1 / V shows up in step 2, cancels this factor such that the power spectrum is P(k).

The linear displacement field is computed as:

\[\psi_i(k) = i \frac{k_i}{k^2} \delta(k)\]

Note

To recover the linear velocity in proper units, i.e., km/s, from the linear displacement, an additional factor of \(f \times a \times H(a)\) is required

Parameters
  • pm (pmesh.pm.ParticleMesh) – the mesh object

  • linear_power (callable) – a function taking wavenumber as its only argument, which returns the linear power spectrum

  • seed (int) – the random seed used to generate the random field

  • compute_displacement (bool, optional) – if True, also return the linear Zel’dovich displacement field; default is False

  • unitary_amplitude (bool, optional) – if True, the seed gaussian has unitary_amplitude.

  • inverted_phase (bool, optional) – if True, the phase of the seed gaussian is inverted

Returns

  • delta_k (ComplexField) – the real-space Gaussian overdensity field

  • disp_k (ComplexField or None) – if requested, the Gaussian displacement field

nbodykit.mockmaker.gaussian_real_fields(pm, linear_power, seed, unitary_amplitude=False, inverted_phase=False, compute_displacement=False, logger=None)[source]

Make a Gaussian realization of a overdensity field in real-space \(\delta(x)\).

If specified, also compute the corresponding linear Zel’dovich displacement field \(\psi(x)\), which is related to the linear velocity field via:

Notes

See the docstring for gaussian_complex_fields() for the steps involved in generating the fields.

Parameters
  • pm (pmesh.pm.ParticleMesh) – the mesh object

  • linear_power (callable) – a function taking wavenumber as its only argument, which returns the linear power spectrum

  • seed (int) – the random seed used to generate the random field

  • compute_displacement (bool, optional) – if True, also return the linear Zel’dovich displacement field; default is False

  • unitary_amplitude (bool, optional) – if True, the seed gaussian has unitary_amplitude.

  • inverted_phase (bool, optional) – if True, the phase of the seed gaussian is inverted

Returns

  • delta (RealField) – the real-space Gaussian overdensity field

  • disp (RealField or None) – if requested, the Gaussian displacement field

nbodykit.mockmaker.lognormal_transform(density, bias=1.0)[source]

Apply a (biased) lognormal transformation of the density field by computing:

\[F(\delta) = \frac{1}{N} e^{b*\delta}\]

where \(\delta\) is the initial overdensity field and the normalization \(N\) is chosen such that \(\langle F(\delta) \rangle = 1\)

Parameters
  • density (array_like) – the input density field to apply the transformation to

  • bias (float, optional) – optionally apply a linear bias to the density field; default is unbiased (1.0)

Returns

toret – the real field holding the transformed density field

Return type

RealField

nbodykit.mockmaker.poisson_sample_to_points(delta, displacement, pm, nbar, bias=1.0, seed=None, logger=None)[source]

Poisson sample the linear delta and displacement fields to points.

The steps in this function:

  1. Apply a biased, lognormal transformation to the input delta field

  2. Poisson sample the overdensity field to discrete points

  3. Disribute the positions of particles uniformly within the mesh cells, and assign the displacement field at each cell to the particles

Parameters
  • delta (RealField) – the linear overdensity field to sample

  • displacement (list of RealField (3,)) – the linear displacement fields which is used to move the particles

  • nbar (float) – the desired number density of the output catalog of objects

  • bias (float, optional) – apply a linear bias to the overdensity field (default is 1.)

  • seed (int, optional) – the random seed used to Poisson sample the field to points

Returns

  • pos (array_like, (N, 3)) – the Cartesian positions of each of the generated particles

  • displ (array_like, (N, 3)) – the displacement field sampled for each of the generated particles in the same units as the pos array