nbodykit.source.mesh

class nbodykit.source.mesh.BigFileMesh(path, dataset, comm=None, **kwargs)[source]

A MeshSource object that reads a mesh from disk using bigfile.

This can read meshes that have been stored with the save() function of MeshSource objects.

Parameters:
  • path (str) – the name of the file to load
  • dataset (str) – the name of the dataset in the Bigfile holding the grid
  • comm (MPI.Communicator) – the MPI communicator
  • **kwargs – extra meta-data to be stored in the attrs dict

Attributes

actions A list of actions to apply to the density field when interpolating to the mesh.
attrs A dictionary storing relevant meta-data about the CatalogSource.

Methods

apply(func[, kind, mode]) Return a view of the mesh, with actions updated to
paint([mode, Nmesh]) Paint the density on the mesh and apply any transformation functions specified in actions.
preview([axes, Nmesh, root]) Gather the mesh into as a numpy array, with (reduced) resolution.
save(output[, dataset, mode]) Save the mesh as a BigFileMesh on disk, either in real or complex space.
to_complex_field() Return the ComplexField stored on disk.
to_field([mode, out]) Return the mesh as a pmesh Field object, either in Fourier space or configuration space, based on mode.
to_real_field() Return the RealField stored on disk.
view() Return a “view” of the MeshSource, in the spirit of numpy’s ndarray view.
to_complex_field()[source]

Return the ComplexField stored on disk.

Note

The mesh stored on disk must be stored with mode=complex

Returns:real – an array-like object holding the mesh loaded from disk in Fourier space
Return type:pmesh.pm.ComplexField
to_real_field()[source]

Return the RealField stored on disk.

Note

The mesh stored on disk must be stored with mode=real

Returns:real – an array-like object holding the mesh loaded from disk in configuration space
Return type:pmesh.pm.RealField
class nbodykit.source.mesh.LinearMesh(Plin, BoxSize, Nmesh, seed=None, unitary_amplitude=False, inverted_phase=False, remove_variance=None, comm=None)[source]

A MeshSource object that generates a RealField density mesh from a linear power spectrum function \(P(k)\).

Parameters:
  • Plin (callable) – the callable linear power spectrum function, which takes the wavenumber as its single argument
  • BoxSize (float, 3-vector of floats) – the size of the box to generate the grid on
  • Nmesh (int, 3-vector of int) – the number of the mesh cells per side
  • seed (int, optional) – the global random seed, used to set the seeds across all ranks
  • remove_variance (bool, optional) – :deprecated:`use unitary_amplitude instead` True to remove variance from the complex field by fixing the amplitude to \(P(k)\) and only the phase is random.
  • unitary_amplitude (bool, optional) – True to remove variance from the complex field by fixing the amplitude to \(P(k)\) and only the phase is random.
  • inverted_phase (bool, optional) – True to invert phase of the complex field by fixing the amplitude to \(P(k)\) and only the phase is random.
  • comm (MPI communicator) – the MPI communicator

Attributes

actions A list of actions to apply to the density field when interpolating to the mesh.
attrs A dictionary storing relevant meta-data about the CatalogSource.

Methods

apply(func[, kind, mode]) Return a view of the mesh, with actions updated to
paint([mode, Nmesh]) Paint the density on the mesh and apply any transformation functions specified in actions.
preview([axes, Nmesh, root]) Gather the mesh into as a numpy array, with (reduced) resolution.
save(output[, dataset, mode]) Save the mesh as a BigFileMesh on disk, either in real or complex space.
to_complex_field() Return a ComplexField, generating from the linear power spectrum.
to_field([mode, out]) Return the mesh as a pmesh Field object, either in Fourier space or configuration space, based on mode.
to_real_field([out, normalize]) Convert the mesh source to the configuration-space field, returning a pmesh.pm.RealField object.
view() Return a “view” of the MeshSource, in the spirit of numpy’s ndarray view.
to_complex_field()[source]

Return a ComplexField, generating from the linear power spectrum.

Note

The density field is normalized to \(1+\delta\) such that the mean of the return field in real space is unity.

Returns:an array-like object holding the generated linear density field in Fourier space
Return type:pmesh.pm.ComplexField
class nbodykit.source.mesh.FieldMesh(field)[source]

A MeshSource initialized from an in-memory Field object, either a pmesh.pm.RealField or pmesh.pm.ComplexField.

Note

The original field object is never modified by this source.

Parameters:
  • field (RealField, ComplexField) – the pmesh Field object, either of real or complex type
  • Nmesh (int, 3-vector of int, optional) – the desired number of cells per size on the mesh. If this is different than the Nmesh of the input Field, the Field will be re-sampled

Attributes

actions A list of actions to apply to the density field when interpolating to the mesh.
attrs A dictionary storing relevant meta-data about the CatalogSource.

Methods

apply(func[, kind, mode]) Return a view of the mesh, with actions updated to
paint([mode, Nmesh]) Paint the density on the mesh and apply any transformation functions specified in actions.
preview([axes, Nmesh, root]) Gather the mesh into as a numpy array, with (reduced) resolution.
save(output[, dataset, mode]) Save the mesh as a BigFileMesh on disk, either in real or complex space.
to_complex_field() Return a copy of the (possibly re-sampled) input ComplexField
to_field([mode, out]) Return the mesh as a pmesh Field object, either in Fourier space or configuration space, based on mode.
to_real_field() Return a copy of the (possibly re-sampled) input RealField
view() Return a “view” of the MeshSource, in the spirit of numpy’s ndarray view.
to_complex_field()[source]

Return a copy of the (possibly re-sampled) input ComplexField

to_real_field()[source]

Return a copy of the (possibly re-sampled) input RealField

class nbodykit.source.mesh.ArrayMesh(array, BoxSize, comm=None, root=0, **kwargs)[source]

A MeshSource initalized from an in-memory numpy array.

Note

The in-memory array must be fully hosted by the root rank.

Parameters:
  • array (numpy.ndarray) – the numpy array holding the field data; this must be fully hosted by the rank specified by root
  • BoxSize (float, 3-vector) – the size of the box
  • root (int, optional) – the root rank holding the array data
  • **kwargs – additional meta-data to store

Attributes

actions A list of actions to apply to the density field when interpolating to the mesh.
attrs A dictionary storing relevant meta-data about the CatalogSource.

Methods

apply(func[, kind, mode]) Return a view of the mesh, with actions updated to
paint([mode, Nmesh]) Paint the density on the mesh and apply any transformation functions specified in actions.
preview([axes, Nmesh, root]) Gather the mesh into as a numpy array, with (reduced) resolution.
save(output[, dataset, mode]) Save the mesh as a BigFileMesh on disk, either in real or complex space.
to_complex_field([out]) Convert the mesh source to the Fourier-space field, returning a pmesh.pm.ComplexField object.
to_field([mode, out]) Return the mesh as a pmesh Field object, either in Fourier space or configuration space, based on mode.
to_real_field()
view() Return a “view” of the MeshSource, in the spirit of numpy’s ndarray view.