4.7.16 pde.tools.spectral module

Functions making use of spectral decompositions.

make_colored_noise

Return a function creating an array of random values that obey.

make_correlated_noise

Return a function creating random values with specified spatial correlations.

make_colored_noise(shape, dx=1.0, exponent=0, scale=1, rng=None)[source]

Return a function creating an array of random values that obey.

\[\langle c(\boldsymbol k) c(\boldsymbol k’) \rangle = \Gamma^2 |\boldsymbol k|^\nu \delta(\boldsymbol k-\boldsymbol k’)\]

in spectral space on a Cartesian grid. The special case \(\nu = 0\) corresponds to white noise. 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.

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

  • exponent (float) – Exponent \(\nu\) of the power spectrum

  • scale (float) – Scaling factor \(\Gamma\) determining noise strength

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

Returns:

a function returning a random realization

Return type:

callable

make_correlated_noise(shape, correlation, *, discretization=1.0, dtype=<class 'float'>, rng=None, **kwargs)[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

Return type:

Callable[[], NumericArray]

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

Parameters:
  • shape (tuple[int, ...])

  • correlation (CorrelationType)

  • discretization (NumberOrArray)

  • dtype (np.typing.DTypeLike)

  • rng (np.random.Generator | None)