FFTPower
)¶The FFTPower
class computes the 1d power spectrum \(P(k)\), 2d
power spectrum \(P(k,\mu)\), and/or multipoles \(P_\ell(k)\) for data
in a simulation box, using a Fast Fourier Transform (FFT). Here, we provide
a brief overview of the algorithm itself as well as the key things to know for
the user to get up and running quickly.
Note
To jump right into the FFTPower
algorithm, see this
cookbook recipe for a detailed
walk-through of the FFTPower
algorithm.
The steps involved in computing the power spectrum via FFTPower
are as follows:
Generate data on a mesh
Data must be painted on to a discrete mesh to compute the power spectrum.
There are several ways to generate data on a mesh (see Creating a Mesh),
but the most common is painting a discrete catalog of objects
on to a mesh (see Converting a CatalogSource to a Mesh and Painting Catalogs to a Mesh).
The FFTPower
class accepts
input data in either the form of a MeshSource
or a CatalogSource
. In the latter case,
the catalog is automatically converted to a mesh using the default parameters
of the to_mesh()
function.
When converting from a catalog to a mesh, users can customize the painting
procedure via the options of the
to_mesh()
function.
These options have important effects on the resulting power spectrum of
the field in Fourier space. See Converting a CatalogSource to a Mesh for more details.
FFT the mesh to Fourier space
Once the density field is painted to the mesh, the Fourier transform
of the field \(\delta(\vx)\) is performed in parallel to obtain the complex
modes of the overdensity field, \(\delta(\vk)\). The field is stored
using the ComplexField
object.
Generate the 3D power spectrum on the mesh
The 3D power spectrum field is computed on the mesh, using
where \(\delta^\star (\mathbf{k})\) is the complex conjugate of \(\delta(\mathbf{k})\).
Perform the binning in the specified basis
Finally, the 3D power defined on the mesh \(P(\mathbf{k})\) is binned using the basis specified by the user. The available options for binning are:
Users can compute various quantities using the FFTPower
. We’ll discuss
the available functionality briefly in the sub-sections below.
Both auto and cross spectra are supported. Users can compute cross power spectra
by passing a second mesh object to the FFTPower
class using
the second
keyword. The first mesh object should always be specified as
the first
argument.
The 1D power spectrum \(P(k)\) can be computed by specifying the
mode
argument as “1d”. The wavenumber binning will be linear, and can be
customized by specifying the dk
and kmin
attributes. By default,
the edge of the last wavenumber bin is the
Nyquist frequency, given
by \(k_\mathrm{Nyq} = \pi N_\mathrm{mesh} / L_\mathrm{box}\). If dk
is not specified, then the fundamental mode of the box is used:
\(2\pi/L_\mathrm{box}\).
The 2D power spectrum \(P(k,\mu)\) can be computed by specifying the
mode
argument as “2d”. The number of \(\mu\) bins is specified via
the Nmu
keyword. The bins range from \(\mu=0\) to \(\mu=1\).
The FFTPower
class can also compute the multipoles of the 2D power
spectrum, defined as
where \(\mathcal{L}_\ell\) is the Legendre polynomial of order
\(\ell\). Users can specify which multipoles they wish to compute
by passing a list of the desired \(\ell\) values as the poles
keyword to the FFTPower
class.
For example, we can compute both \(P(k,\mu)\) and \(P_\ell(k)\) for a uniform catalog of objects using:
In [1]: from nbodykit.lab import UniformCatalog, FFTPower
In [2]: cat = UniformCatalog(nbar=100, BoxSize=1.0, seed=42)
In [3]: r = FFTPower(cat, mode='2d', Nmesh=32, Nmu=5, poles=[0,2,4])
The power spectrum results are stored in two attributes of the
initialized FFTPower
object:
power
and poles
. These attributes are
BinnedStatistic
objects, which
behave like structured numpy arrays and store
the measured results on a coordinate grid defined by the bins.
See Analyzing your Results for a full tutorial on using
the BinnedStatistic
class.
The power
attribute stores the following variables:
the mean value for each k
bin
mode=2d
the mean value for each mu
bin
complex array storing the real and imaginary components of the power
the number of Fourier modes averaged together in each bin
The poles
attribute stores the following variables:
k
binNote that measured power results for bins where modes
is zero (no data points
to average over) are set to NaN
.
In our example, the power
and poles
attributes are:
# the 2D power spectrum results
In [4]: print(r.power)
<BinnedStatistic: dims: (k: 16, mu: 5), variables: ('k', 'mu', 'power', 'modes')>
In [5]: print("variables = ", r.power.variables)