glass.grf — Gaussian random fields

Gaussian angular power spectra

glass.grf.compute(cl, t1, t2=None)[source]

Compute a band-limited Gaussian angular power spectrum for the target spectrum cl and the transformations t1 and t2. If t2 is not given, it is assumed to be the same as t1.

Parameters:
  • cl (ndarray[tuple[Any, ...], dtype[Any]]) – The angular power spectrum after the transformations.

  • t1 (Transformation) – Transformations applied to the Gaussian random field(s).

  • t2 (Transformation | None) – Transformations applied to the Gaussian random field(s).

Returns:

Gaussian angular power spectrum.

Return type:

ndarray[tuple[Any, ...], dtype[Any]]

Examples

Compute a Gaussian angular power spectrum gl for a lognormal transformation:

t = glass.grf.Lognormal()
gl = glass.grf.compute(cl, t)

See also

glass.grf.solve

Iterative solver for non-band-limited spectra.

glass.grf.solve(cl, t1, t2=None, *, pad=0, initial=None, cltol=1e-05, gltol=1e-05, maxiter=20, monopole=None)[source]

Solve for a Gaussian angular power spectrum.

Given the input angular power spectrum cl and a pair of transformations t1 and t2, computes a Gaussian angular spectrum that reproduces cl after the transformations are applied. This is done using the iterative solver proposed in [Tessore23].

The internal padding of the solver is set by pad, and the initial solution can be passed as initial. The convergence is controlled by the relative errors cltol and gltol, and the maximum number of iterations maxiter.

If monopole is provided, the monopole of the Gaussian angular power spectrum is fixed to that value and ignored by the solver.

Returns a tuple gl, cl, info where gl is the Gaussian angular power spectrum solution, cl is the realised angular power spectrum after transformation, and info indicates success of failure of the solution. Possible info values are

  • 0, solution did not converge in maxiter iterations;

  • 1, solution converged in cl relative error;

  • 2, solution converged in gl relative error;

  • 3, solution converged in both cl and gl relative error.

Parameters:
  • cl (ndarray[tuple[Any, ...], dtype[Any]]) – The angular power spectrum after the transformations.

  • t1 (Transformation) – Transformations applied to the Gaussian random field(s).

  • t2 (Transformation | None) – Transformations applied to the Gaussian random field(s).

  • pad (int) – Internal padding applied to the transforms.

  • initial (ndarray[tuple[Any, ...], dtype[Any]] | None) – Initial solution. If not provided, uses the result of glass.grf.compute().

  • cltol (float) – Relative error for convergence in the desired output.

  • gltol (float) – Relative error for convergence in the solution.

  • maxiter (int) – Maximum number of iterations of the solver.

  • monopole (float | None) – Fix the monopole of the solution to the given value.

Return type:

tuple[ndarray[tuple[Any, ...], dtype[Any]], ndarray[tuple[Any, ...], dtype[Any]], int]

See also

glass.grf.compute

Direct computation for band-limited spectra.

Transforming correlations

These functions can convert between Gaussian and transformed angular correlation functions, and form the basis of glass.grf.compute() and glass.grf.solve().

glass.grf.corr(t1, t2, x, /)[source]

Transform a Gaussian angular correlation function.

Parameters:
  • t1 (Transformation) – Transformations of the Gaussian random field.

  • t2 (Transformation) – Transformations of the Gaussian random field.

  • x (ndarray[tuple[Any, ...], dtype[Any]]) – The Gaussian angular correlation function.

Returns:

The transformed angular correlation function.

Return type:

ndarray[tuple[Any, ...], dtype[Any]]

glass.grf.icorr(t1, t2, x, /)[source]

Inverse-transform an angular correlation function.

Parameters:
  • t1 (Transformation) – Transformations of the Gaussian random field.

  • t2 (Transformation) – Transformations of the Gaussian random field.

  • x (ndarray[tuple[Any, ...], dtype[Any]]) – The transformed angular correlation function.

Returns:

The Gaussian angular correlation function.

Return type:

ndarray[tuple[Any, ...], dtype[Any]]

glass.grf.dcorr(t1, t2, x, /)[source]

Derivative of the angular correlation function transform.

Parameters:
  • t1 (Transformation) – Transformations of the Gaussian random field.

  • t2 (Transformation) – Transformations of the Gaussian random field.

  • x (ndarray[tuple[Any, ...], dtype[Any]]) – The Gaussian angular correlation function.

Returns:

The derivative of the transformed angular correlation function.

Return type:

ndarray[tuple[Any, ...], dtype[Any]]

Transformations

protocol glass.grf.Transformation[source]

Protocol for transformations of Gaussian random fields.

Classes that implement this protocol must have the following methods / attributes:

__call__(x, var, /)[source]

Transform a Gaussian random field x with variance var.

Parameters:
Returns:

The transformed Gaussian random field.

Return type:

ndarray[tuple[Any, ...], dtype[Any]]

class glass.grf.Normal[source]

Transformation for normal fields.

\[t(X) = X\]

This is the identity transformation.

class glass.grf.Lognormal(lamda=1.0)[source]

Transformation for lognormal fields.

\[t(X) = \lambda \bigl[\exp(X - \tfrac{\sigma^2}{2}) - 1\bigr]\]

The “lognormal shift” parameter \(\lambda\) is the scale parameter of the distribution, with determines the smallest possible value \(-\lambda\) of the lognormal field.

Parameters:

lamda (float) – The parameter \(\lambda\).

class glass.grf.SquaredNormal(a, lamda=1.0)[source]

Transformation for squared normal fields as introduced by [Tessore25].

\[t(X) = \lambda \, \bigl[(X - a)^2 - 1\bigr]\]

The transformation is characterised by the shape parameter a, which is related to the variance \(\sigma^2\) of the Gaussian random field, \(a = \sqrt{1 - \sigma^2}\).

The “shift” parameter \(\lambda\) is the scale parameter of the distribution, with determines the smallest possible value \(-\lambda\) of the squared normal field.

Parameters:
  • a (float) – The parameter \(a\).

  • lamda (float) – The parameter \(\lambda\).