yaw.CorrData#

class yaw.CorrData(binning: Binning, data: ArrayLike, samples: ArrayLike)[source]#

Bases: AsciiSerializable, SampledData, Broadcastable

Container for a correlation functino measured in bins of redshift.

Implements convenience methods to estimate the standard error, covariance and correlation matrix, and plotting methods. Additionally implements len(), comparison with the == operator and addition with +/-.

Parameters:
  • binning – The redshift :~yaw.Binning` applied to the data.

  • data – Array containing the values in each of the redshift bin.

  • samples – 2-dim array containing M jackknife samples of the data, expected to have shape (num_samples, num_bins).

Methods

__init__(binning, data, samples)

from_files(path_prefix)

Restore the class instance from a set of ASCII files.

is_compatible(other, *[, require])

Checks if two containers have compatible binning and number of jackknife samples.

plot(*[, color, label, style, ax, xoffset, ...])

Plot the data with its uncertainty against the redshift bin centers.

plot_corr(*[, redshift, cmap, ax])

Plot the correlation matrix of the data.

to_files(path_prefix)

Serialise the class instance into a set of ASCII files.

Attributes

binning

Accessor for the redshift Binning attribute.

data

Array containing the values in each of the N redshift bin.

samples

2-dim array containing M jackknife samples of the data, expected to have shape (M, N).

bins

Indexing helper to create a new instance from a subset of patches.

correlation

Correlation matrix computed from the Gaussian covariance matrix with shape (N, N).

covariance

Gaussian covariance matrix estimated from the jackknife samples with shape (N, N).

error

Standard error estimated from the jackknife samples.

num_bins

The number of redshift bins.

num_samples

The number of jackknife samples.

binning: Binning#

Accessor for the redshift Binning attribute.

property bins: Indexer[TypeSliceIndex, TypeBinwiseData]#

Indexing helper to create a new instance from a subset of patches.

The indexer supports indexing, slicing, and iteration over individual patches.

Caution

Indixing a non-contiguous subset of bins will result in expanding the previous bin to encompass all omitted bins, e.g. selecting the first and third bin of (0, 1], (1, 2], (2, 3] will result in a binning with edges (0, 2], (2, 3].

Slicing is unaffected since it always results in a contiguous subset of bins.

property correlation: NDArray#

Correlation matrix computed from the Gaussian covariance matrix with shape (N, N).

property covariance: NDArray#

Gaussian covariance matrix estimated from the jackknife samples with shape (N, N).

data: NDArray#

Array containing the values in each of the N redshift bin.

property error: NDArray#

Standard error estimated from the jackknife samples.

classmethod from_files(path_prefix: Path | str) TypeCorrData[source]#

Restore the class instance from a set of ASCII files.

Parameters:

path_prefix – A path (str or pathlib.Path) prefix used as [path_prefix].{dat,smp,cov}, pointing to the ASCII files to restore from, see also to_files().

is_compatible(other: Any, *, require: bool = False) bool#

Checks if two containers have compatible binning and number of jackknife samples.

Parameters:

other – Another instance of this class to compare to, returns False if instance types do not match.

Keyword Arguments:

require – Whether to raise exceptions if any of the checks fail.

Returns:

Whether the containers have identical binning and number of jackknife samples if require=False.

Raises:
  • TypeError – If require=True and type of other does match this class.

  • ValueError – If require=True the binning or number of samples is not identical.

property num_bins: int#

The number of redshift bins.

property num_samples: int#

The number of jackknife samples.

plot(*, color: str | NDArray | None = None, label: str | None = None, style: PlotStyle | str | None = None, ax: Axis | None = None, xoffset: float = 0.0, plot_kwargs: dict[str, Any] | None = None, indicate_zero: bool = False, scale_dz: bool = False) Axis#

Plot the data with its uncertainty against the redshift bin centers.

Keyword Arguments:
  • color – Matplotlib color to use for the line or error bars.

  • label – Matplotlib-compatible label for plot.

  • style

    Plotting style, must be either of
    • point: point with error bar,

    • line: line with transparent shade marking the errors, or

    • step: same as line, but using a step-plot to emulate a histgram-style visualisation.

  • ax – Matplotlib axis to plot onto.

  • xoffset – Offset to apply to the redshift bin centers.

  • plot_kwargs – Keyword arguments passed on to the primary matplotlib plotting function (plot, errorbar, stairs).

  • indicate_zero – Whether to draw a thin black line at y=0.

  • scale_dz – Whether to scale the data and uncertainty by the inverse of the redshift bin width.

plot_corr(*, redshift: bool = False, cmap: str = 'RdBu_r', ax: Axis | None = None) Axis#

Plot the correlation matrix of the data.

Keyword Arguments:
  • redshift – Whether to plot the correlation on a axes scales by redshift instead of bin indices.

  • cmap – Name or other matplotlib-compatible color map for the matrix elements.

  • ax – Matplotlib axis to plot onto.

samples: NDArray#

2-dim array containing M jackknife samples of the data, expected to have shape (M, N).

to_files(path_prefix: Path | str) None[source]#

Serialise the class instance into a set of ASCII files.

This method creates three files, which are all readable with numpy.loadtxt:

  • [path_prefix].dat: File with header and four columns, the left and right redshift bin edges, data, and errors.

  • [path_prefix].smp: File containing the jackknife samples. The first two columns are the left and right redshift bin edges, the remaining columns each represent one jackknife sample.

  • [path_prefix].cov: File storing the covariance matrix.

Parameters:

path_prefix – A path (str or pathlib.Path) prefix [path_prefix].{dat,smp,cov} pointing to the ASCII files to serialise into, see also from_files().