PowerBox¶
-
class
powerbox.powerbox.
PowerBox
(N, pk, dim=2, boxlength=1.0, ensure_physical=False, a=1.0, b=1.0, vol_normalised_power=True, seed=None)[source]¶ Bases:
object
Calculate real- and fourier-space Gaussian fields generated with a given power spectrum.
Parameters: - N : int
Number of grid-points on a side for the resulting box (equivalently, number of wavenumbers to use).
- pk : callable
A callable of a single (vector) variable k, which is the isotropic power spectrum. The relationship of the k of which this is a function to the real-space co-ordinates, x, is determined by the parameters
a,b
.- dim : int, default 2
Number of dimensions of resulting box.
- boxlength : float, default 1.0
Length of the final signal on a side. This may have arbitrary units, so long as pk is a function of a variable which has the inverse units.
- ensure_physical : bool, optional
Interpreting the power spectrum as a spectrum of density fluctuations, the minimum physical value of the real-space field,
delta_x()
, is -1. Withensure_physical
set toTrue
,delta_x()
is clipped to return values >-1. If this is happening a lot, consider usingLogNormalPowerBox
.- a,b : float, optional
These define the Fourier convention used. See
powerbox.dft
for details. The defaults define the standard usage in cosmology (for example, as defined in Cosmological Physics, Peacock, 1999, pg. 496.). Standard numerical usage (eg. numpy) is (a,b) = (0,2pi).- vol_normalised_power : bool, optional
Whether the input power spectrum,
pk
, is volume-weighted. Default True because of standard cosmological usage.- seed: int, optional
A random seed to define the initial conditions. If not set, it will remain random, and each call to eg.
delta_x()
will produce a different realisation.
Notes
A number of conventions need to be listed.
The conventions of using x for “real-space” and k for “fourier space” arise from cosmology, but this does not affect anything – x could just as well stand for “time domain” and k for “frequency domain”.
The important convention is the relationship between x and k, or in other words, whether k is interpreted as an angular frequency or ordinary frequency. By default, because of cosmological conventions, k is an angular frequency, so that the fourier transform integrand is delta_k*exp(-ikx). The conventions can be changed arbitrarily by setting the
a,b
parameters (seepowerbox.dft
for details).The primary quantity of interest is
delta_x()
, which is a zero-mean Gaussian field with a power spectrum equivalent to that which was input. Being zero-mean enables its direct interpretation as an overdensity field, and this interpretation is enforced in themake_discrete_sample()
method.Note
None of the n-dimensional arrays that are created within the class are stored, due to the inefficiency in memory consumption that this would imply. Thus, each large array is created and returned by their respective method, to be stored/discarded by the user.
Warning
Due to the above note, repeated calls to eg.
delta_x()
will produce different realisations of the real-space field, unless the seed parameter is set in the constructor.Examples
To create a 3-dimensional box of gaussian over-densities, gridded into 100 bins, with cosmological conventions, and a power-law power spectrum, simply use
>>> pb = PowerBox(100,lambda k : 0.1*k**-3., dim=3, boxlength=100.0) >>> overdensities = pb.delta_x() >>> grid = pb.x >>> radii = pb.r
To create a 2D turbulence structure, with arbitrary units, once can use
>>> import matplotlib.pyplot as plt >>> pb = PowerBox(1000, lambda k : k**-7./5.) >>> plt.imshow(pb.delta_x())
Attributes Summary
kvec
The vector of wavenumbers along a side r
The radial position of every point in the grid x
The co-ordinates of the grid along a side Methods Summary
create_discrete_sample
(nbar[, …])Assuming that the real-space signal represents an over-density with respect to some mean, create a sample of tracers of the underlying density distribution. delta_k
()A realisation of the delta_k, i.e. delta_x
()The realised field in real-space from the input power spectrum gauss_hermitian
()A random array which has Gaussian magnitudes and Hermitian symmetry k
()The entire grid of wavenumber magitudes power_array
()The Power Spectrum (volume normalised) at self.k Attributes Documentation
-
kvec
¶ The vector of wavenumbers along a side
-
r
¶ The radial position of every point in the grid
-
x
¶ The co-ordinates of the grid along a side
Methods Documentation
-
create_discrete_sample
(nbar, randomise_in_cell=True, min_at_zero=False, store_pos=False)[source]¶ Assuming that the real-space signal represents an over-density with respect to some mean, create a sample of tracers of the underlying density distribution.
Parameters: - nbar : float
Mean tracer density within the box.
- randomise_in_cell : bool, optional
Whether to randomise the positions of the tracers within the cells, or put them at the grid-points (more efficient).
- min_at_zero : bool, optional
Whether to make the lower corner of the box at the origin, otherwise the centre of the box is at the origin.
- store_pos : bool, optional
Whether to store the sample of tracers as an instance variable tracer_positions.
Returns: - tracer_positions : float, array_like
(n, d)
-array, withn
the number of tracers andd
the number of dimensions. Each row represents a single tracer’s co-ordinates.