yaw.RedshiftData#
- class yaw.RedshiftData(binning: Binning, data: ArrayLike, samples: ArrayLike)[source]#
Bases:
CorrDataContainer for a clustering redshift estimate.
Implements conveniences methods to estimate the standard error, covariance and correlation matrix, normalisation, and plotting methods. Additionally implements
len(), comparison with the==operator and addition with+/-.- Parameters:
binning – The redshift
Binningapplied to the data.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 (
num_samples,num_bins).
Methods
__init__(binning, data, samples)from_corrdata(cross_data[, ref_data, unk_data])Compute a redshift estimate from a set of cross- and autocorrelation functions.
from_corrfuncs(cross_corr[, ref_corr, unk_corr])Compute a redshift estimate from a set of cross- and autocorrelation pair counts.
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.
normalised([target])Attempts to normalise the redshift estimate to a probability density.
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
Accessor for the redshift
Binningattribute.Array containing the values in each of the N redshift bins.
2-dim array containing M jackknife samples of the data, expected to have shape (M, N).
Indexing helper to create a new instance from a subset of patches.
Correlation matrix computed from the Gaussian covariance matrix with shape (N, N).
Gaussian covariance matrix estimated from the jackknife samples with shape (N, N).
Standard error estimated from the jackknife samples.
The number of redshift bins.
The number of jackknife samples.
- property bins: Indexer[TypeSliceIndex, Self]#
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 bins.
- property error: NDArray#
Standard error estimated from the jackknife samples.
- classmethod from_corrdata(cross_data: CorrData, ref_data: CorrData | None = None, unk_data: CorrData | None = None) Self[source]#
Compute a redshift estimate from a set of cross- and autocorrelation functions.
Computes the clustering redshift estimate with optional correction for galaxy sample biases:
\[n(z) = \frac{w_{sp}(z)}{\sqrt{\Delta z^2 \, w_{ss}(z) \, w_{pp}(z)}}\]- Parameters:
cross_data – The cross-correlation function amplitude (\(w_{sp}\)), must be a
CorrDatainstance.- Keyword Arguments:
- Returns:
The redshift estimate as
RedshiftData.
- classmethod from_corrfuncs(cross_corr: CorrFunc, ref_corr: CorrFunc | None = None, unk_corr: CorrFunc | None = None) Self[source]#
Compute a redshift estimate from a set of cross- and autocorrelation pair counts.
Computes the correlation functions from the input pair counts and calls
from_corrdata().- Parameters:
cross_corr – The cross-correlation function pair counts (\(w_{sp}\)), must be a
CorrFuncinstance.- Keyword Arguments:
- Returns:
The redshift estimate as
RedshiftData.
- classmethod from_files(path_prefix: Path | str) Self#
Restore the class instance from a set of ASCII files.
- Parameters:
path_prefix – A path (
strorpathlib.Path) prefix used as[path_prefix].{dat,smp,cov}, pointing to the ASCII files to restore from, see alsoto_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
Falseif 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=Trueand type ofotherdoes match this class.ValueError – If
require=Truethe binning or number of samples is not identical.
- normalised(target: TypeCorrData | None = None) Self[source]#
Attempts to normalise the redshift estimate to a probability density.
By default rescales data and jackknife samples by computing a normalisation factor obtained from integrating the data over the redshift range of the binning. Alternatively, the normalisation may be optained by fitting to another data container to achieve a relative normalisation.
Warning
Both approaches are inaccuarte due to noise fluctions (in particular negative correlation amplitudes).
- Keyword Arguments:
target – Optional, when provided used as reference to fit the normalisation factor, must be a subclass of
CorrData.- Returns:
A new instance with a normalisation factor applied to the data and jackknife samples.
- 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, orstep: same asline, 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#
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 (
strorpathlib.Path) prefix[path_prefix].{dat,smp,cov}pointing to the ASCII files to serialise into, see alsofrom_files().