# nbodykit.algorithms.fftpower¶

Functions

 project_to_basis(y3d, edges[, los, poles]) Project a 3D statistic on to the specified basis.

Classes

 FFTBase(first, second, Nmesh, BoxSize) Base class provides functions for periodic FFT based Power spectrum code. FFTPower(first, mode[, Nmesh, BoxSize, …]) Algorithm to compute the 1d or 2d power spectrum and/or multipoles in a periodic box, using a Fast Fourier Transform (FFT). ProjectedFFTPower(first[, Nmesh, BoxSize, …]) The power spectrum of a field in a periodic box, projected over certain axes.
class nbodykit.algorithms.fftpower.FFTBase(first, second, Nmesh, BoxSize)[source]

Base class provides functions for periodic FFT based Power spectrum code.

Parameters
• first (CatalogSource) – the first catalog source

• second (CatalogSource, None) – the second source, or None for auto-correlations

• Nmesh (int, 3-vector) – the number of cells per mesh size

• BoxSize (3-vector) – the size of the box

Methods

 load(output[, comm]) Load a saved result. save(self, output) Save the result to disk.
classmethod load(output, comm=None)[source]

Load a saved result. The result has been saved to disk with save().

save(self, output)[source]

Save the result to disk. The format is currently JSON.

class nbodykit.algorithms.fftpower.FFTPower(first, mode, Nmesh=None, BoxSize=None, second=None, los=[0, 0, 1], Nmu=5, dk=None, kmin=0.0, kmax=None, poles=[])[source]

Algorithm to compute the 1d or 2d power spectrum and/or multipoles in a periodic box, using a Fast Fourier Transform (FFT).

This computes the power spectrum as the square of the Fourier modes of the density field, which are computed via a FFT.

Results are computed when the object is inititalized. See the documenation of run() for the attributes storing the results.

Note

A full tutorial on the class is available in the documentation here.

Parameters
• first (CatalogSource, MeshSource) – the source for the first field; if a CatalogSource is provided, it is automatically converted to MeshSource using the default painting parameters (via to_mesh())

• mode ({'1d', '2d'}) – compute either 1d or 2d power spectra

• Nmesh (int, optional) – the number of cells per side in the particle mesh used to paint the source

• BoxSize (int, 3-vector, optional) – the size of the box

• second (CatalogSource, MeshSource, optional) – the second source for cross-correlations

• los (array_like , optional) – the direction to use as the line-of-sight; must be a unit vector

• Nmu (int, optional) – the number of mu bins to use from $$\mu=[0,1]$$; if mode = 1d, then Nmu is set to 1

• dk (float, optional) – the linear spacing of k bins to use; if not provided, the fundamental mode of the box is used; if dk=0 is set, use fine bins such that the modes contributing to the bin has identical modulus.

• kmin (float, optional) – the lower edge of the first k bin to use

• kmin – the upper limit of the last k bin to use (not exact)

• poles (list of int, optional) – a list of multipole numbers ell to compute $$P_\ell(k)$$ from $$P(k,\mu)$$

Methods

 load(output[, comm]) Load a saved result. run(self) Compute the power spectrum in a periodic box, using FFTs. save(self, output) Save the result to disk.
classmethod load(output, comm=None)

Load a saved result. The result has been saved to disk with save().

run(self)[source]

Compute the power spectrum in a periodic box, using FFTs.

Returns

• power (BinnedStatistic) – a BinnedStatistic object that holds the measured $$P(k)$$ or $$P(k,\mu)$$. It stores the following variables:

• k :

the mean value for each k bin

• mumode=2d only

the mean value for each mu bin

• power :

complex array storing the real and imaginary components of the power

• modes :

the number of Fourier modes averaged together in each bin

• poles (BinnedStatistic or None) – a BinnedStatistic object to hold the multipole results $$P_\ell(k)$$; if no multipoles were requested by the user, this is None. It stores the following variables:

• k :

the mean value for each k bin

• power_L :

complex array storing the real and imaginary components for the $$\ell=L$$ multipole

• modes :

the number of Fourier modes averaged together in each bin

• power.attrs, poles.attrs (dict) – dictionary of meta-data; in addition to storing the input parameters, it includes the following fields computed during the algorithm execution:

• shotnoisefloat

the power Poisson shot noise, equal to $$V/N$$, where $$V$$ is the volume of the box and N is the total number of objects; if a cross-correlation is computed, this will be equal to zero

• N1int

the total number of objects in the first source

• N2int

the total number of objects in the second source

save(self, output)

Save the result to disk. The format is currently JSON.

class nbodykit.algorithms.fftpower.ProjectedFFTPower(first, Nmesh=None, BoxSize=None, second=None, axes=(0, 1), dk=None, kmin=0.0)[source]

The power spectrum of a field in a periodic box, projected over certain axes.

This is not really always physically meaningful, but convenient for making sense of Lyman-Alpha forest or lensing maps.

This is usually called the 1d power spectrum or 2d power spectrum.

Results are computed when the object is inititalized. See the documenation of run() for the attributes storing the results.

Parameters
• first (CatalogSource, MeshSource) – the source for the first field; if a CatalogSource is provided, it is automatically converted to MeshSource using the default painting parameters (via to_mesh())

• Nmesh (int, optional) – the number of cells per side in the particle mesh used to paint the source

• BoxSize (int, 3-vector, optional) – the size of the box

• second (CatalogSource, MeshSource, optional) – the second source for cross-correlations

• axes (tuple) – axes to measure the power on. The axes not in the list will be averaged out. For example: - (0, 1) : project to x,y and measure power - (0) : project to x and measure power.

• dk (float, optional) – the linear spacing of k bins to use; if not provided, the fundamental mode of the box is used

• kmin (float, optional) – the lower edge of the first k bin to use

Methods

 load(output[, comm]) Load a saved result. run(self) Run the algorithm. save(self, output) Save the result to disk.
classmethod load(output, comm=None)

Load a saved result. The result has been saved to disk with save().

run(self)[source]

Run the algorithm. This attaches the following attributes to the class:

edges

the edges of the wavenumber bins

Type

array_like

power

a BinnedStatistic object that holds the projected power. It stores the following variables:

• k :

the mean value for each k bin

• power :

complex array holding the real and imaginary components of the projected power

• modes :

the number of Fourier modes averaged together in each bin

Type

BinnedStatistic

save(self, output)

Save the result to disk. The format is currently JSON.

nbodykit.algorithms.fftpower.project_to_basis(y3d, edges, los=[0, 0, 1], poles=[])[source]

Project a 3D statistic on to the specified basis. The basis will be one of:

• 2D (x, mu) bins: mu is the cosine of the angle to the line-of-sight

• 2D (x, ell) bins: ell is the multipole number, which specifies the Legendre polynomial when weighting different mu bins

Note

The 2D (x, mu) bins will be computed only if poles is specified. See return types for further details.

Notes

• the mu range extends from 0.0 to 1.0

• the mu bins are half-inclusive half-exclusive, except the last bin is inclusive on both ends (to include mu = 1.0)

Parameters
• y3d (RealField or ComplexField) – the 3D array holding the statistic to be projected to the specified basis

• edges (list of arrays, (2,)) – list of arrays specifying the edges of the desired x bins and mu bins

• los (array_like,) – the line-of-sight direction to use, which mu is defined with respect to; default is [0, 0, 1] for z.

• poles (list of int, optional) – if provided, a list of integers specifying multipole numbers to project the 2d (x, mu) bins on to

• hermitian_symmetric (bool, optional) – Whether the input array y3d is Hermitian-symmetric, i.e., the negative frequency terms are just the complex conjugates of the corresponding positive-frequency terms; if True, the positive frequency terms will be explicitly double-counted to account for this symmetry

Returns

• result (tuple) – the 2D binned results; a tuple of (xmean_2d, mumean_2d, y2d, N_2d), where:

• xmean_2darray_like, (Nx, Nmu)

the mean x value in each 2D bin

• mumean_2darray_like, (Nx, Nmu)

the mean mu value in each 2D bin

• y2darray_like, (Nx, Nmu)

the mean y3d value in each 2D bin

• N_2darray_like, (Nx, Nmu)

the number of values averaged in each 2D bin

• pole_result (tuple or None) – the multipole results; if poles supplied it is a tuple of (xmean_1d, poles, N_1d), where:

• xmean_1darray_like, (Nx,)

the mean x value in each 1D multipole bin

• polesarray_like, (Nell, Nx)

the mean multipoles value in each 1D bin

• N_1darray_like, (Nx,)

the number of values averaged in each 1D bin