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 apply the specified function, either in Fourier space or configuration space, based on mode
compute([mode, Nmesh]) Compute / Fetch the mesh object into memory as a RealField or ComplexField object.
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.
paint  
__finalize__(other)

Finalize the creation of a MeshSource object by copying over attributes from a second MeshSource.

Parameters:other (MeshSource) – the second MeshSource to copy over attributes from
__len__()

Length of a mesh source is zero

actions

A list of actions to apply to the density field when interpolating to the mesh.

This stores tuples of (mode, func, kind); see apply() for more details.

apply(func, kind='wavenumber', mode='complex')

Return a view of the mesh, with actions updated to apply the specified function, either in Fourier space or configuration space, based on mode

Parameters:
  • func (callable or a MeshFilter object) – func(x, y) where x is a list of r (k) values that broadcasts into a full array, when mode is ‘real’ (‘complex’); the value of x depends on kind. y is the value of the mesh field on the corresponding locations.
  • kind (string, optional) –

    if a MeshFilter object is given as func, this is ignored. The kind of value in x.

    • When mode is ‘complex’:
      • ’wavenumber’ means wavenumber from [- 2 pi / L * N / 2, 2 pi / L * N / 2).
      • ’circular’ means circular frequency from [- pi, pi).
      • ’index’ means [0, Nmesh )
    • When mode is ‘real’:
      • ’relative’ means distance from [-0.5 Boxsize, 0.5 BoxSize).
      • ’index’ means [0, Nmesh )
  • mode ('complex' or 'real', optional) – if a MeshFilter object is given as func, this is ignored. whether to apply the function to the mesh in configuration space or Fourier space
Returns:

a view of the mesh object with the actions attribute updated to include the new action

Return type:

MeshSource

attrs

A dictionary storing relevant meta-data about the CatalogSource.

compute(mode='real', Nmesh=None)

Compute / Fetch the mesh object into memory as a RealField or ComplexField object.

preview(axes=None, Nmesh=None, root=0)

Gather the mesh into as a numpy array, with (reduced) resolution. The result is broadcast to all ranks, so this uses \(\mathrm{Nmesh}^3\) per rank.

Parameters:
  • Nmesh (int, array_like) – The desired Nmesh of the result. Be aware this function allocates memory to hold a full Nmesh on each rank.
  • axes (int, array_like) – The axes to project the preview onto., e.g. (0, 1)
  • root (int, optional) – the rank number to treat as root when gathering to a single rank
Returns:

out – An numpy array holding the real density field.

Return type:

array_like

save(output, dataset='Field', mode='real')

Save the mesh as a BigFileMesh on disk, either in real or complex space.

Parameters:
  • output (str) – name of the bigfile file
  • dataset (str, optional) – name of the bigfile data set where the field is stored
  • mode (str, optional) – real or complex; the form of the field to store
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_field(mode='real', out=None)

Return the mesh as a pmesh Field object, either in Fourier space or configuration space, based on mode.

This will call to_real_field() or to_complex_field() based on mode.

Parameters:mode ('real' or 'complex') – the return type of the field
Returns:either a RealField of ComplexField, storing the value of the field on the mesh
Return type:RealField, 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
view()

Return a “view” of the MeshSource, in the spirit of numpy’s ndarray view.

This returns a new MeshSource whose memory is owned by self.

Note that for CatalogMesh objects, this is overidden by the CatalogSource.view function.

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 since version 0.2.9: use unitary_amplitude instead

  • 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 apply the specified function, either in Fourier space or configuration space, based on mode
compute([mode, Nmesh]) Compute / Fetch the mesh object into memory as a RealField or ComplexField object.
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.
paint  
__finalize__(other)

Finalize the creation of a MeshSource object by copying over attributes from a second MeshSource.

Parameters:other (MeshSource) – the second MeshSource to copy over attributes from
__len__()

Length of a mesh source is zero

actions

A list of actions to apply to the density field when interpolating to the mesh.

This stores tuples of (mode, func, kind); see apply() for more details.

apply(func, kind='wavenumber', mode='complex')

Return a view of the mesh, with actions updated to apply the specified function, either in Fourier space or configuration space, based on mode

Parameters:
  • func (callable or a MeshFilter object) – func(x, y) where x is a list of r (k) values that broadcasts into a full array, when mode is ‘real’ (‘complex’); the value of x depends on kind. y is the value of the mesh field on the corresponding locations.
  • kind (string, optional) –

    if a MeshFilter object is given as func, this is ignored. The kind of value in x.

    • When mode is ‘complex’:
      • ’wavenumber’ means wavenumber from [- 2 pi / L * N / 2, 2 pi / L * N / 2).
      • ’circular’ means circular frequency from [- pi, pi).
      • ’index’ means [0, Nmesh )
    • When mode is ‘real’:
      • ’relative’ means distance from [-0.5 Boxsize, 0.5 BoxSize).
      • ’index’ means [0, Nmesh )
  • mode ('complex' or 'real', optional) – if a MeshFilter object is given as func, this is ignored. whether to apply the function to the mesh in configuration space or Fourier space
Returns:

a view of the mesh object with the actions attribute updated to include the new action

Return type:

MeshSource

attrs

A dictionary storing relevant meta-data about the CatalogSource.

compute(mode='real', Nmesh=None)

Compute / Fetch the mesh object into memory as a RealField or ComplexField object.

preview(axes=None, Nmesh=None, root=0)

Gather the mesh into as a numpy array, with (reduced) resolution. The result is broadcast to all ranks, so this uses \(\mathrm{Nmesh}^3\) per rank.

Parameters:
  • Nmesh (int, array_like) – The desired Nmesh of the result. Be aware this function allocates memory to hold a full Nmesh on each rank.
  • axes (int, array_like) – The axes to project the preview onto., e.g. (0, 1)
  • root (int, optional) – the rank number to treat as root when gathering to a single rank
Returns:

out – An numpy array holding the real density field.

Return type:

array_like

save(output, dataset='Field', mode='real')

Save the mesh as a BigFileMesh on disk, either in real or complex space.

Parameters:
  • output (str) – name of the bigfile file
  • dataset (str, optional) – name of the bigfile data set where the field is stored
  • mode (str, optional) – real or complex; the form of the field to store
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
to_field(mode='real', out=None)

Return the mesh as a pmesh Field object, either in Fourier space or configuration space, based on mode.

This will call to_real_field() or to_complex_field() based on mode.

Parameters:mode ('real' or 'complex') – the return type of the field
Returns:either a RealField of ComplexField, storing the value of the field on the mesh
Return type:RealField, ComplexField
to_real_field(out=None, normalize=True)

Convert the mesh source to the configuration-space field, returning a pmesh.pm.RealField object.

Not implemented in the base class, unless object is a view.

view()

Return a “view” of the MeshSource, in the spirit of numpy’s ndarray view.

This returns a new MeshSource whose memory is owned by self.

Note that for CatalogMesh objects, this is overidden by the CatalogSource.view function.

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 apply the specified function, either in Fourier space or configuration space, based on mode
compute([mode, Nmesh]) Compute / Fetch the mesh object into memory as a RealField or ComplexField object.
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.
paint  
__finalize__(other)

Finalize the creation of a MeshSource object by copying over attributes from a second MeshSource.

Parameters:other (MeshSource) – the second MeshSource to copy over attributes from
__len__()

Length of a mesh source is zero

actions

A list of actions to apply to the density field when interpolating to the mesh.

This stores tuples of (mode, func, kind); see apply() for more details.

apply(func, kind='wavenumber', mode='complex')

Return a view of the mesh, with actions updated to apply the specified function, either in Fourier space or configuration space, based on mode

Parameters:
  • func (callable or a MeshFilter object) – func(x, y) where x is a list of r (k) values that broadcasts into a full array, when mode is ‘real’ (‘complex’); the value of x depends on kind. y is the value of the mesh field on the corresponding locations.
  • kind (string, optional) –

    if a MeshFilter object is given as func, this is ignored. The kind of value in x.

    • When mode is ‘complex’:
      • ’wavenumber’ means wavenumber from [- 2 pi / L * N / 2, 2 pi / L * N / 2).
      • ’circular’ means circular frequency from [- pi, pi).
      • ’index’ means [0, Nmesh )
    • When mode is ‘real’:
      • ’relative’ means distance from [-0.5 Boxsize, 0.5 BoxSize).
      • ’index’ means [0, Nmesh )
  • mode ('complex' or 'real', optional) – if a MeshFilter object is given as func, this is ignored. whether to apply the function to the mesh in configuration space or Fourier space
Returns:

a view of the mesh object with the actions attribute updated to include the new action

Return type:

MeshSource

attrs

A dictionary storing relevant meta-data about the CatalogSource.

compute(mode='real', Nmesh=None)

Compute / Fetch the mesh object into memory as a RealField or ComplexField object.

preview(axes=None, Nmesh=None, root=0)

Gather the mesh into as a numpy array, with (reduced) resolution. The result is broadcast to all ranks, so this uses \(\mathrm{Nmesh}^3\) per rank.

Parameters:
  • Nmesh (int, array_like) – The desired Nmesh of the result. Be aware this function allocates memory to hold a full Nmesh on each rank.
  • axes (int, array_like) – The axes to project the preview onto., e.g. (0, 1)
  • root (int, optional) – the rank number to treat as root when gathering to a single rank
Returns:

out – An numpy array holding the real density field.

Return type:

array_like

save(output, dataset='Field', mode='real')

Save the mesh as a BigFileMesh on disk, either in real or complex space.

Parameters:
  • output (str) – name of the bigfile file
  • dataset (str, optional) – name of the bigfile data set where the field is stored
  • mode (str, optional) – real or complex; the form of the field to store
to_complex_field()[source]

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

to_field(mode='real', out=None)

Return the mesh as a pmesh Field object, either in Fourier space or configuration space, based on mode.

This will call to_real_field() or to_complex_field() based on mode.

Parameters:mode ('real' or 'complex') – the return type of the field
Returns:either a RealField of ComplexField, storing the value of the field on the mesh
Return type:RealField, ComplexField
to_real_field()[source]

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.

This returns a new MeshSource whose memory is owned by self.

Note that for CatalogMesh objects, this is overidden by the CatalogSource.view function.

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 apply the specified function, either in Fourier space or configuration space, based on mode
compute([mode, Nmesh]) Compute / Fetch the mesh object into memory as a RealField or ComplexField object.
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() 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.
paint  
__finalize__(other)

Finalize the creation of a MeshSource object by copying over attributes from a second MeshSource.

Parameters:other (MeshSource) – the second MeshSource to copy over attributes from
__len__()

Length of a mesh source is zero

actions

A list of actions to apply to the density field when interpolating to the mesh.

This stores tuples of (mode, func, kind); see apply() for more details.

apply(func, kind='wavenumber', mode='complex')

Return a view of the mesh, with actions updated to apply the specified function, either in Fourier space or configuration space, based on mode

Parameters:
  • func (callable or a MeshFilter object) – func(x, y) where x is a list of r (k) values that broadcasts into a full array, when mode is ‘real’ (‘complex’); the value of x depends on kind. y is the value of the mesh field on the corresponding locations.
  • kind (string, optional) –

    if a MeshFilter object is given as func, this is ignored. The kind of value in x.

    • When mode is ‘complex’:
      • ’wavenumber’ means wavenumber from [- 2 pi / L * N / 2, 2 pi / L * N / 2).
      • ’circular’ means circular frequency from [- pi, pi).
      • ’index’ means [0, Nmesh )
    • When mode is ‘real’:
      • ’relative’ means distance from [-0.5 Boxsize, 0.5 BoxSize).
      • ’index’ means [0, Nmesh )
  • mode ('complex' or 'real', optional) – if a MeshFilter object is given as func, this is ignored. whether to apply the function to the mesh in configuration space or Fourier space
Returns:

a view of the mesh object with the actions attribute updated to include the new action

Return type:

MeshSource

attrs

A dictionary storing relevant meta-data about the CatalogSource.

compute(mode='real', Nmesh=None)

Compute / Fetch the mesh object into memory as a RealField or ComplexField object.

preview(axes=None, Nmesh=None, root=0)

Gather the mesh into as a numpy array, with (reduced) resolution. The result is broadcast to all ranks, so this uses \(\mathrm{Nmesh}^3\) per rank.

Parameters:
  • Nmesh (int, array_like) – The desired Nmesh of the result. Be aware this function allocates memory to hold a full Nmesh on each rank.
  • axes (int, array_like) – The axes to project the preview onto., e.g. (0, 1)
  • root (int, optional) – the rank number to treat as root when gathering to a single rank
Returns:

out – An numpy array holding the real density field.

Return type:

array_like

save(output, dataset='Field', mode='real')

Save the mesh as a BigFileMesh on disk, either in real or complex space.

Parameters:
  • output (str) – name of the bigfile file
  • dataset (str, optional) – name of the bigfile data set where the field is stored
  • mode (str, optional) – real or complex; the form of the field to store
to_complex_field(out=None)

Convert the mesh source to the Fourier-space field, returning a pmesh.pm.ComplexField object.

Not implemented in the base class, unless object is a view.

to_field(mode='real', out=None)

Return the mesh as a pmesh Field object, either in Fourier space or configuration space, based on mode.

This will call to_real_field() or to_complex_field() based on mode.

Parameters:mode ('real' or 'complex') – the return type of the field
Returns:either a RealField of ComplexField, storing the value of the field on the mesh
Return type:RealField, ComplexField
to_real_field()[source]

Convert the mesh source to the configuration-space field, returning a pmesh.pm.RealField object.

Not implemented in the base class, unless object is a view.

view()

Return a “view” of the MeshSource, in the spirit of numpy’s ndarray view.

This returns a new MeshSource whose memory is owned by self.

Note that for CatalogMesh objects, this is overidden by the CatalogSource.view function.

class nbodykit.source.mesh.CatalogMesh(source, Nmesh, BoxSize, Position, dtype='f4', resampler='cic', compensated=False, interlaced=False, Value=None, Selection=None, Weight=None, **kwargs)[source]

A mesh generated by resampling a Catalog with the given parameters.

The original CatalogSource object is stored as the base attribute.

Parameters:
  • source (CatalogSource) – the input catalog that we are viewing as a mesh
  • BoxSize – the size of the box
  • Nmesh (int, 3-vector) – the number of cells per mesh side
  • dtype (str) – the data type of the values stored on mesh
  • Weight (array_like, Column, None) – column that specifies the weight value for each particle in the source to use when gridding
  • Value (array_like, Column, None) – column that specifies the field value for each particle; the mesh stores a weighted average of this column
  • Selection (array_like, Column, None) – column that selects the subset of particles to grid to the mesh
  • Position (array_like, Column, None) – column in source specifying the position coordinates; default is Position
  • interlaced (bool, optional) – use the interlacing technique of Sefusatti et al. 2015 to reduce the effects of aliasing on Fourier space quantities computed from the mesh
  • compensated (bool, optional) – whether to correct for the window introduced by the grid interpolation scheme
  • window (str, optional) – the string specifying which window interpolation scheme to use; see pmesh.window.methods

‘Weight’, ‘Value’, ‘Selection’, ‘Position’ are items of the collection that can be reassigned after the creation of the object.

Attributes:
actions

The actions to apply to the interpolated density field, optionally included the compensation correction.

attrs

A dictionary storing relevant meta-data about the CatalogSource.

compensated

Boolean flag to indicate whether to correct for the windowing kernel introduced when interpolating the discrete particles to a continuous field.

interlaced

Whether to use interlacing when interpolating the density field.

resampler

String specifying the name of the interpolation kernel when gridding the density field.

window

Methods

apply(func[, kind, mode]) Return a view of the mesh, with actions updated to apply the specified function, either in Fourier space or configuration space, based on mode
compute([mode, Nmesh]) Compute / Fetch the mesh object into memory as a RealField or ComplexField object.
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([out, normalize]) Paint the density field, by interpolating the position column on to the mesh.
view() Return a “view” of the MeshSource, in the spirit of numpy’s ndarray view.
paint  
__finalize__(other)

Finalize the creation of a MeshSource object by copying over attributes from a second MeshSource.

Parameters:other (MeshSource) – the second MeshSource to copy over attributes from
__len__()

Length of a mesh source is zero

actions

The actions to apply to the interpolated density field, optionally included the compensation correction.

apply(func, kind='wavenumber', mode='complex')

Return a view of the mesh, with actions updated to apply the specified function, either in Fourier space or configuration space, based on mode

Parameters:
  • func (callable or a MeshFilter object) – func(x, y) where x is a list of r (k) values that broadcasts into a full array, when mode is ‘real’ (‘complex’); the value of x depends on kind. y is the value of the mesh field on the corresponding locations.
  • kind (string, optional) –

    if a MeshFilter object is given as func, this is ignored. The kind of value in x.

    • When mode is ‘complex’:
      • ’wavenumber’ means wavenumber from [- 2 pi / L * N / 2, 2 pi / L * N / 2).
      • ’circular’ means circular frequency from [- pi, pi).
      • ’index’ means [0, Nmesh )
    • When mode is ‘real’:
      • ’relative’ means distance from [-0.5 Boxsize, 0.5 BoxSize).
      • ’index’ means [0, Nmesh )
  • mode ('complex' or 'real', optional) – if a MeshFilter object is given as func, this is ignored. whether to apply the function to the mesh in configuration space or Fourier space
Returns:

a view of the mesh object with the actions attribute updated to include the new action

Return type:

MeshSource

attrs

A dictionary storing relevant meta-data about the CatalogSource.

compensated

Boolean flag to indicate whether to correct for the windowing kernel introduced when interpolating the discrete particles to a continuous field.

See the documentation for further details.

compute(mode='real', Nmesh=None)

Compute / Fetch the mesh object into memory as a RealField or ComplexField object.

interlaced

Whether to use interlacing when interpolating the density field. See the documentation for further details.

See also: Section 3.1 of Sefusatti et al. 2015

preview(axes=None, Nmesh=None, root=0)

Gather the mesh into as a numpy array, with (reduced) resolution. The result is broadcast to all ranks, so this uses \(\mathrm{Nmesh}^3\) per rank.

Parameters:
  • Nmesh (int, array_like) – The desired Nmesh of the result. Be aware this function allocates memory to hold a full Nmesh on each rank.
  • axes (int, array_like) – The axes to project the preview onto., e.g. (0, 1)
  • root (int, optional) – the rank number to treat as root when gathering to a single rank
Returns:

out – An numpy array holding the real density field.

Return type:

array_like

resampler

String specifying the name of the interpolation kernel when gridding the density field.

See the documentation for further details.

Note

Valid values must be in pmesh.resampler.methods

save(output, dataset='Field', mode='real')

Save the mesh as a BigFileMesh on disk, either in real or complex space.

Parameters:
  • output (str) – name of the bigfile file
  • dataset (str, optional) – name of the bigfile data set where the field is stored
  • mode (str, optional) – real or complex; the form of the field to store
to_complex_field(out=None)

Convert the mesh source to the Fourier-space field, returning a pmesh.pm.ComplexField object.

Not implemented in the base class, unless object is a view.

to_field(mode='real', out=None)

Return the mesh as a pmesh Field object, either in Fourier space or configuration space, based on mode.

This will call to_real_field() or to_complex_field() based on mode.

Parameters:mode ('real' or 'complex') – the return type of the field
Returns:either a RealField of ComplexField, storing the value of the field on the mesh
Return type:RealField, ComplexField
to_real_field(out=None, normalize=True)[source]

Paint the density field, by interpolating the position column on to the mesh.

This computes the following meta-data attributes in the process of painting, returned in the attrs attributes of the returned RealField object:

  • N : int
    the (unweighted) total number of objects painted to the mesh
  • W : float
    the weighted number of total objects, equal to the collective sum of the ‘weight’ column
  • shotnoise : float
    the Poisson shot noise, equal to the volume divided by N
  • num_per_cell : float
    the mean number of weighted objects per cell

Note

The density field on the mesh is normalized as \(1+\delta\), such that the collective mean of the field is unity.

See the documentation on painting for more details on painting catalogs to a mesh.

Returns:real – the painted real field; this has a attrs dict storing meta-data
Return type:pmesh.pm.RealField
view()

Return a “view” of the MeshSource, in the spirit of numpy’s ndarray view.

This returns a new MeshSource whose memory is owned by self.

Note that for CatalogMesh objects, this is overidden by the CatalogSource.view function.

class nbodykit.source.mesh.MultipleSpeciesCatalogMesh(source, Nmesh, BoxSize, dtype, selection, position, weight, value, interlaced, compensated, resampler)[source]

A subclass of CatalogMesh designed to paint the density field from a sum of multiple types of particles.

The compute() function paints the density field summed over all particle species.

Parameters:
  • source (CatalogSource) – the input catalog that we wish to interpolate to a mesh
  • BoxSize – the size of the box
  • Nmesh (int, 3-vector) – the number of cells per mesh side
  • dtype (str) – the data type of the values stored on mesh
  • weight (str) – column in source that specifies the weight value for each particle in the source to use when gridding
  • value (str) – column in source that specifies the field value for each particle; the mesh stores a weighted average of this column
  • selection (str) – column in source that selects the subset of particles to grid
  • position (str, optional) – column in source specifying the position coordinates; default is Position
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 apply the specified function, either in Fourier space or configuration space, based on mode
compute([mode, Nmesh]) Compute / Fetch the mesh object into memory as a RealField or ComplexField object.
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([normalize]) Paint the density field holding the sum of all particle species, returning a RealField object.
view() Return a “view” of the MeshSource, in the spirit of numpy’s ndarray view.
paint  
__finalize__(other)

Finalize the creation of a MeshSource object by copying over attributes from a second MeshSource.

Parameters:other (MeshSource) – the second MeshSource to copy over attributes from
__getitem__(key)[source]

If indexed by a species name, return a CatalogMesh object holding only the data columns for that species with the same parameters as the current object.

If not a species name, this has the same behavior as CatalogSource.__getitem__().

__len__()

Length of a mesh source is zero

actions

A list of actions to apply to the density field when interpolating to the mesh.

This stores tuples of (mode, func, kind); see apply() for more details.

apply(func, kind='wavenumber', mode='complex')

Return a view of the mesh, with actions updated to apply the specified function, either in Fourier space or configuration space, based on mode

Parameters:
  • func (callable or a MeshFilter object) – func(x, y) where x is a list of r (k) values that broadcasts into a full array, when mode is ‘real’ (‘complex’); the value of x depends on kind. y is the value of the mesh field on the corresponding locations.
  • kind (string, optional) –

    if a MeshFilter object is given as func, this is ignored. The kind of value in x.

    • When mode is ‘complex’:
      • ’wavenumber’ means wavenumber from [- 2 pi / L * N / 2, 2 pi / L * N / 2).
      • ’circular’ means circular frequency from [- pi, pi).
      • ’index’ means [0, Nmesh )
    • When mode is ‘real’:
      • ’relative’ means distance from [-0.5 Boxsize, 0.5 BoxSize).
      • ’index’ means [0, Nmesh )
  • mode ('complex' or 'real', optional) – if a MeshFilter object is given as func, this is ignored. whether to apply the function to the mesh in configuration space or Fourier space
Returns:

a view of the mesh object with the actions attribute updated to include the new action

Return type:

MeshSource

attrs

A dictionary storing relevant meta-data about the CatalogSource.

compute(mode='real', Nmesh=None)

Compute / Fetch the mesh object into memory as a RealField or ComplexField object.

preview(axes=None, Nmesh=None, root=0)

Gather the mesh into as a numpy array, with (reduced) resolution. The result is broadcast to all ranks, so this uses \(\mathrm{Nmesh}^3\) per rank.

Parameters:
  • Nmesh (int, array_like) – The desired Nmesh of the result. Be aware this function allocates memory to hold a full Nmesh on each rank.
  • axes (int, array_like) – The axes to project the preview onto., e.g. (0, 1)
  • root (int, optional) – the rank number to treat as root when gathering to a single rank
Returns:

out – An numpy array holding the real density field.

Return type:

array_like

save(output, dataset='Field', mode='real')

Save the mesh as a BigFileMesh on disk, either in real or complex space.

Parameters:
  • output (str) – name of the bigfile file
  • dataset (str, optional) – name of the bigfile data set where the field is stored
  • mode (str, optional) – real or complex; the form of the field to store
to_complex_field(out=None)

Convert the mesh source to the Fourier-space field, returning a pmesh.pm.ComplexField object.

Not implemented in the base class, unless object is a view.

to_field(mode='real', out=None)

Return the mesh as a pmesh Field object, either in Fourier space or configuration space, based on mode.

This will call to_real_field() or to_complex_field() based on mode.

Parameters:mode ('real' or 'complex') – the return type of the field
Returns:either a RealField of ComplexField, storing the value of the field on the mesh
Return type:RealField, ComplexField
to_real_field(normalize=True)[source]

Paint the density field holding the sum of all particle species, returning a RealField object.

Meta-data computed for each particle is stored in the attrs attribute of the returned RealField, with keys that are prefixed by the species name. In particular, the total shot noise for the mesh is defined as:

\[P_\mathrm{shot} = \sum_i (W_i/W_\mathrm{tot})^2 P_{\mathrm{shot},i},\]

where the sum is over all species in the catalog, W_i is the sum of the Weight column for the \(i^\mathrm{th}\) species, and \(W_\mathrm{tot}\) is the sum of \(W_i\) across all species.

Parameters:normalize (bool, optional) – if True, normalize the density field as \(1+\delta\), dividing by the total mean number of objects per cell, as given by the num_per_cell meta-data value in attrs
Returns:the RealField holding the painted density field, with a attrs dictionary attribute holding the meta-data
Return type:RealField
view()

Return a “view” of the MeshSource, in the spirit of numpy’s ndarray view.

This returns a new MeshSource whose memory is owned by self.

Note that for CatalogMesh objects, this is overidden by the CatalogSource.view function.