Shells (glass.shells)

The glass.shells module provides functions for the definition of matter shells, i.e. the radial discretisation of the light cone.

Window functions

class glass.shells.RadialWindow(za, wa, zeff)

A radial window, defined by a window function.

The radial window is defined by a window function in redshift, which is given by a pair of arrays za, wa.

The radial window also has an effective redshift, stored in the zeff attribute, which should be a representative redshift for the window function.

To prevent accidental inconsistencies, instances of this type are immutable (however, the array entries may not be immutable; do not change them in place):

>>> from glass.shells import RadialWindow
>>> w1 = RadialWindow(..., ..., zeff=0.1)
>>> w1.zeff = 0.15
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't set attribute

To create a new instance with a changed attribute value, use the ._replace method:

>>> w1 = w1._replace(zeff=0.15)
>>> w1
RadialWindow(za=..., wa=..., zeff=0.15)
Attributes:
za(N,) array_like

Redshift array; the abscissae of the window function.

wa(N,) array_like

Weight array; the values (ordinates) of the window function.

zefffloat

Effective redshift of the window.

Methods

_replace(**kwds)

Return a new RadialWindow object replacing specified fields with new values

glass.shells.tophat_windows(zbins, dz=0.001, weight=None)

Tophat window functions from the given redshift bin edges.

Uses the N+1 given redshifts as bin edges to construct N tophat window functions. The redshifts of the windows have linear spacing approximately equal to dz.

An optional weight function \(w(z)\) can be given using weight; it is applied to the tophat windows.

The resulting windows functions are RadialWindow instances. Their effective redshifts are the mean redshifts of the (weighted) tophat bins.

Parameters:
zbins(N+1,) array_like

Redshift bin edges for the tophat window functions.

dzfloat, optional

Approximate spacing of the redshift grid.

weightcallable, optional

If given, a weight function to be applied to the window functions.

Returns:
ws(N,) list of RadialWindow

List of window functions.

See also

Window functions
glass.shells.linear_windows(zgrid, dz=0.001, weight=None)

Linear interpolation window functions.

Uses the N+2 given redshifts as nodes to construct N triangular window functions between the first and last node. These correspond to linear interpolation of radial functions. The redshift spacing of the windows is approximately equal to dz.

An optional weight function \(w(z)\) can be given using weight; it is applied to the triangular windows.

The resulting windows functions are RadialWindow instances. Their effective redshifts correspond to the given nodes.

Parameters:
zgrid(N+2,) array_like

Redshift grid for the triangular window functions.

dzfloat, optional

Approximate spacing of the redshift grid.

weightcallable, optional

If given, a weight function to be applied to the window functions.

Returns:
ws(N,) list of RadialWindow

List of window functions.

See also

Window functions
glass.shells.cubic_windows(zgrid, dz=0.001, weight=None)

Cubic interpolation window functions.

Uses the N+2 given redshifts as nodes to construct N cubic Hermite spline window functions between the first and last node. These correspond to cubic spline interpolation of radial functions. The redshift spacing of the windows is approximately equal to dz.

An optional weight function \(w(z)\) can be given using weight; it is applied to the cubic spline windows.

The resulting windows functions are RadialWindow instances. Their effective redshifts correspond to the given nodes.

Parameters:
zgrid(N+2,) array_like

Redshift grid for the cubic spline window functions.

dzfloat, optional

Approximate spacing of the redshift grid.

weightcallable, optional

If given, a weight function to be applied to the window functions.

Returns:
ws(N,) list of RadialWindow

List of window functions.

See also

Window functions

Window function tools

glass.shells.restrict(z, f, w)

Restrict a function to a redshift window.

Multiply the function \(f(z)\) by a window function \(w(z)\) to produce \(w(z) f(z)\) over the support of \(w\).

The function \(f(z)\) is given by redshifts z of shape (N,) and function values f of shape (…, N), with any number of leading axes allowed.

The window function \(w(z)\) is given by w, which must be a RadialWindow instance or compatible with it.

The restriction has redshifts that are the union of the redshifts of the function and window over the support of the window. Intermediate function values are found by linear interpolation

Parameters:
z, farray_like

The function to be restricted.

wRadialWindow

The window function for the restriction.

Returns:
zr, frarray

The restricted function.

glass.shells.partition(z, fz, shells, *, method='nnls')

Partition a function by a sequence of windows.

Returns a vector of weights \(x_1, x_2, \ldots\) such that the weighted sum of normalised radial window functions \(x_1 \, w_1(z) + x_2 \, w_2(z) + \ldots\) approximates the given function \(f(z)\).

The function \(f(z)\) is given by redshifts z of shape (N,) and function values fz of shape (…, N), with any number of leading axes allowed.

The window functions are given by the sequence shells of RadialWindow or compatible entries.

Parameters:
z, fzarray_like

The function to be partitioned. If f is multi-dimensional, its last axis must agree with z.

shellssequence of RadialWindow

Ordered sequence of window functions for the partition.

method{“lstsq”, “nnls”, “restrict”}

Method for the partition. See notes for description.

Returns:
xarray_like

Weights of the partition, where the leading axis corresponds to shells.

Notes

Formally, if \(w_i\) are the normalised window functions, \(f\) is the target function, and \(z_i\) is a redshift grid with intervals \(\Delta z_i\), the partition problem seeks an approximate solution of

\[\begin{pmatrix} w_1(z_1) \Delta z_1 & w_2(z_1) \, \Delta z_1 & \cdots \\ w_1(z_2) \Delta z_2 & w_2(z_2) \, \Delta z_2 & \cdots \\ \vdots & \vdots & \ddots \end{pmatrix} \, \begin{pmatrix} x_1 \\ x_2 \\ \vdots \end{pmatrix} = \begin{pmatrix} f(z_1) \, \Delta z_1 \\ f(z_2) \, \Delta z_2 \\ \vdots \end{pmatrix} \;. \]

The redshift grid is the union of the given array z and the redshift arrays of all window functions. Intermediate function values are found by linear interpolation.

When partitioning a density function, it is usually desirable to keep the normalisation fixed. In that case, the problem can be enhanced with the further constraint that the sum of the solution equals the integral of the target function,

\[\begin{pmatrix} w_1(z_1) \Delta z_1 & w_2(z_1) \, \Delta z_1 & \cdots \\ w_1(z_2) \Delta z_2 & w_2(z_2) \, \Delta z_2 & \cdots \\ \vdots & \vdots & \ddots \\ \hline \lambda & \lambda & \cdots \end{pmatrix} \, \begin{pmatrix} x_1 \\ x_2 \\ \vdots \end{pmatrix} = \begin{pmatrix} f(z_1) \, \Delta z_1 \\ f(z_2) \, \Delta z_2 \\ \vdots \\ \hline \lambda \int \! f(z) \, dz \end{pmatrix} \;, \]

where \(\lambda\) is a multiplier to enforce the integral contraints.

The partition() function implements a number of methods to obtain a solution:

If method="nnls" (the default), obtain a partition from a non-negative least-squares solution. This will usually match the shape of the input function closely. The contribution from each shell is a positive number, which is required to partition e.g. density functions.

If method="lstsq", obtain a partition from an unconstrained least-squares solution. This will more closely match the shape of the input function, but might lead to shells with negative contributions.

If method="restrict", obtain a partition by integrating the restriction (using restrict()) of the function \(f\) to each window. For overlapping shells, this method might produce results which are far from the input function.

glass.shells.combine(z, weights, shells)

Evaluate a linear combination of window functions.

Takes a vector of weights \(x_1, x_2, \ldots\) and computes the weighted sum of normalised radial window functions \(f(z) = x_1 \, w_1(z) + x_2 \, w_2(z) + \ldots\) in the given redshifts \(z\).

The window functions are given by the sequence shells of RadialWindow or compatible entries.

Parameters:
zarray_like

Redshifts z in which to evaluate the combined function.

weightsarray_like

Weights of the linear combination, where the leading axis corresponds to shells.

shellssequence of RadialWindow

Ordered sequence of window functions to be combined.

Returns:
fzarray_like

Linear combination of window functions, evaluated in z.

See also

partition

Find weights for a given function.

Redshift grids

glass.shells.redshift_grid(zmin, zmax, *, dz=None, num=None)

Redshift grid with uniform spacing in redshift.

glass.shells.distance_grid(cosmo, zmin, zmax, *, dx=None, num=None)

Redshift grid with uniform spacing in comoving distance.

Weight functions

glass.shells.distance_weight(z, cosmo)

Uniform weight in comoving distance.

glass.shells.volume_weight(z, cosmo)

Uniform weight in comoving volume.

glass.shells.density_weight(z, cosmo)

Uniform weight in matter density.