4.7.16 pde.tools.spectral module

Functions making use of spectral decompositions.

make_correlated_noise

Return a function creating random values with specified spatial correlations.

make_correlated_noise(shape: tuple[int, ...], correlation: CorrelationType, *, discretization: NumberOrArray = 1.0, dtype: np.DTypeLike = <class 'float'>, rng: np.random.Generator | None = None, **kwargs) → Callable[[], NumericArray][source]

Return a function creating random values with specified spatial correlations.

The returned field \(f\) generally obeys a selected correlation function \(C(k)\). In Fourier space, we thus have

\[\langle f(\boldsymbol k) f(\boldsymbol k’) \rangle = C(|\boldsymbol k|) \delta(\boldsymbol k-\boldsymbol k’)\]

For simplicity, the correlations respect periodic boundary conditions.

Parameters:
  • shape (tuple of ints) – Number of supports points in each spatial dimension. The number of the list defines the spatial dimension.

  • correlation (str) – Selects the correlation function used to make the correlated noise. Many of the options (described below) support additional parameters that can be supplied as keyword arguments.

  • discretization (float or list of floats) – Discretization along each dimension. A uniform discretization in each direction can be indicated by a single number.

  • dtype (numpy.dtype) – Data type of the returned noise array. If a complex dtype is provided, the function returns complex-valued arrays; otherwise the real part is taken and returned as the specified real dtype.

  • rng (Generator) – Random number generator (default: default_rng())

  • **kwargs – Additional parameters can affect details of the correlation function. Examples include length_scale, exponent, and sharpness, which are described in the table below.

Supported correlation functions

Identifier

Correlation function

none

No correlation, \(C(k) = \delta(k)\)

gaussian

\(C(k) = \exp(-\frac12 k^2 \lambda^2)\) with the length scale \(\lambda\) set by argument length_scale.

power law

\(C(k) = k^{\nu/2}\) with exponent \(\nu\) set by argument exponent.

cosine

\(C(k) = \exp\bigl(-s^2(\lambda k - 1)^2\bigr)\) with the length scale \(\lambda\) set by argument length_scale, whereas the sharpness parameter \(s\) is set by sharpness and defaults to 10.

Note

The returned field only has unit variance for correlation functions that decrease monotonously. In other cases (i.e., for cosine correlation), the variance depends on details, like the resolution of the grid.

Returns:

a function returning a random realization

Return type:

callable