LogNormalPowerBox¶
-
class
powerbox.powerbox.
LogNormalPowerBox
(*args, **kwargs)[source]¶ Bases:
powerbox.powerbox.PowerBox
Calculate Log-Normal density fields with given power spectra.
See the documentation of
PowerBox
for a detailed explanation of the arguments, as this class has exactly the same arguments.This class calculates an (over-)density field of arbitrary dimension given an input isotropic power spectrum. In this case, the field has a log-normal distribution of over-densities, always yielding a physically valid field.
Examples
To create a log-normal over-density field:
>>> from powerbox import LogNormalPowerBox >>> lnpb = LogNormalPowerBox(100,lambda k : k**-7./5.,dim=2, boxlength=1.0) >>> overdensities = lnpb.delta_x >>> grid = lnpb.x >>> radii = lnpb.r
To plot the overdensities:
>>> import matplotlib.pyplot as plt >>> plt.imshow(pb.delta_x)
Compare the fields from a Gaussian and Lognormal realisation with the same power:
>>> lnpb = LogNormalPowerBox(300,lambda k : k**-7./5.,dim=2, boxlength=1.0) >>> pb = PowerBox(300,lambda k : k**-7./5.,dim=2, boxlength=1.0) >>> fig,ax = plt.subplots(2,1,sharex=True,sharey=True,figsize=(12,5)) >>> ax[0].imshow(lnpb.delta_x,aspect="equal",vmin=-1,vmax=lnpb.delta_x.max()) >>> ax[1].imshow(pb.delta_x,aspect="equal",vmin=-1,vmax = lnpb.delta_x.max())
To create and plot a discrete version of the field:
>>> positions = lnpb.create_discrete_sample(nbar=1000.0, # Number density in terms of boxlength units >>> randomise_in_cell=True) >>> plt.scatter(positions[:,0],positions[:,1],s=2,alpha=0.5,lw=0)
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
correlation_array
()The correlation function from the input power, on the grid 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 real-space over-density field, from the input power spectrum gauss_hermitian
()A random array which has Gaussian magnitudes and Hermitian symmetry gaussian_correlation_array
()The correlation function required for a Gaussian field to produce the input power on a lognormal field gaussian_power_array
()The power spectrum required for a Gaussian field to produce the input power on a lognormal field 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)¶ 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.
-
delta_k
()[source]¶ A realisation of the delta_k, i.e. the gaussianised square root of the unitless power spectrum (i.e. the Fourier co-efficients)
-
gauss_hermitian
()¶ A random array which has Gaussian magnitudes and Hermitian symmetry
-
gaussian_correlation_array
()[source]¶ The correlation function required for a Gaussian field to produce the input power on a lognormal field
-
gaussian_power_array
()[source]¶ The power spectrum required for a Gaussian field to produce the input power on a lognormal field
-
k
()¶ The entire grid of wavenumber magitudes
-
power_array
()¶ The Power Spectrum (volume normalised) at self.k
-