Random fields

The following functions provide functionality for simulating random fields on the sphere. This is done in the form of HEALPix maps.

Functions

glass.discretized_cls(cls, *, lmax=None, ncorr=None, nside=None)[source]

Apply discretisation effects to angular power spectra.

Depending on the given arguments, this truncates the angular power spectra to lmax, removes all but ncorr correlations between fields, and applies the HEALPix pixel window function of the given nside. If no arguments are given, no action is performed.

Parameters:
  • cls (Sequence[ndarray[Any, dtype[float64]] | Sequence[float]]) – Angular matter power spectra in GLASS ordering.

  • lmax (int | None) – The maximum mode number to truncate the spectra.

  • ncorr (int | None) – The number of correlated fields to keep.

  • nside (int | None) – The resolution parameter for the HEALPix maps.

Returns:

The discretised angular power spectra.

Raises:

ValueError – If the length of the Cls array is not a triangle number.

Return type:

Sequence[ndarray[Any, dtype[float64]] | Sequence[float]]

glass.lognormal_gls(cls, shift=1.0)[source]

Compute Gaussian Cls for a lognormal random field.

Parameters:
Returns:

The Gaussian angular power spectra for a lognormal random field.

Return type:

Sequence[ndarray[Any, dtype[float64]] | Sequence[float]]

glass.generate_gaussian(gls, nside, *, ncorr=None, rng=None)[source]

Sample Gaussian random fields from Cls iteratively.

A generator that iteratively samples HEALPix maps of Gaussian random fields with the given angular power spectra gls and resolution parameter nside.

The optional argument ncorr can be used to artificially limit now many realised fields are correlated. This saves memory, as only ncorr previous fields need to be kept.

The gls array must contain the auto-correlation of each new field followed by the cross-correlations with all previous fields in reverse order:

gls = [gl_00,
       gl_11, gl_10,
       gl_22, gl_21, gl_20,
       ...]

Missing entries can be set to None.

Parameters:
  • gls (Sequence[ndarray[Any, dtype[float64]] | Sequence[float]]) – The Gaussian angular power spectra for a random field.

  • nside (int) – The resolution parameter for the HEALPix maps.

  • ncorr (int | None) – The number of correlated fields. If not given, all fields are correlated.

  • rng (Generator | None) – Random number generator. If not given, a default RNG is used.

Yields:

fields – The Gaussian random fields.

Raises:

ValueError – If all gls are empty.

Return type:

Generator[ndarray[Any, dtype[float64]]]

glass.generate_lognormal(gls, nside, shift=1.0, *, ncorr=None, rng=None)[source]

Sample lognormal random fields from Gaussian Cls iteratively.

Parameters:
  • gls (Sequence[ndarray[Any, dtype[float64]] | Sequence[float]]) – The Gaussian angular power spectra for a lognormal random field.

  • nside (int) – The resolution parameter for the HEALPix maps.

  • shift (float) – The shift parameter for the lognormal transformation.

  • ncorr (int | None) – The number of correlated fields. If not given, all fields are correlated.

  • rng (Generator | None) – Random number generator. If not given, a default RNG is used.

Yields:

fields – The lognormal random fields.

Return type:

Generator[ndarray[Any, dtype[float64]]]

glass.effective_cls(cls, weights1, weights2=None, *, lmax=None)[source]

Compute effective angular power spectra from weights.

Computes a linear combination of the angular power spectra cls using the factors provided by weights1 and weights2. Additional axes in weights1 and weights2 produce arrays of spectra.

Parameters:
  • cls (Sequence[ndarray[Any, dtype[float64]] | Sequence[float]]) – Angular matter power spectra in GLASS ordering.

  • weights1 (ndarray[Any, dtype[float64]]) – Weight factors for spectra. The first axis must be equal to the number of fields.

  • weights2 (ndarray[Any, dtype[float64]] | None) – Second set of weights. If not given, weights1 is used.

  • lmax (int | None) – Truncate the angular power spectra at this mode number. If not given, the longest input in cls will be used.

Returns:

A dictionary of effective angular power spectra, where keys correspond to the leading axes of weights1 and weights2.

Raises:
  • ValueError – If the length of cls is not a triangle number.

  • ValueError – If the shapes of weights1 and weights2 are incompatible.

Return type:

ndarray[Any, dtype[float64]]

Utility functions

glass.getcl(cls, i, j, lmax=None)[source]

Return a specific angular power spectrum from an array.

Parameters:
  • cls (Sequence[ndarray[Any, dtype[float64]] | Sequence[float]]) – Angular matter power spectra in GLASS ordering.

  • i (int) – Indices to return.

  • j (int) – Indices to return.

  • lmax (int | None) – Truncate the returned spectrum at this mode number.

Returns:

The angular power spectrum for indices i and j from an array in GLASS ordering.

Return type:

ndarray[Any, dtype[float64]] | Sequence[float]