yaw.redshifts.HistData#
- class yaw.redshifts.HistData(binning: IntervalIndex, data: NDArray, samples: NDArray, method: str, info: str | None = None, density: bool = False)[source]#
Bases:
RedshiftDataContainer for histogram data.
Contains the redshift binning, histogram counts, and resampled counts (e.g. from jackknife or bootstrap). The resampled values are used to compute error estimates and covariance/correlation matrices. Provides some plotting methods for convenience.
- Parameters:
binning (
pandas.IntervalIndex) – The redshift bin edges used for this correlation function.data (
NDArray) – The correlation function values.samples (
NDArray) – The resampled correlation function values.method (
str) – The resampling method used, seeResamplingConfigfor available options.info (
str, optional) – Descriptive text included in the headers of output files produced byCorrData.to_files().density (
bool) – Whether the data is normalised, i.e. a density estimate.
Methods
__init__(binning, data, samples, method[, ...])concatenate_bins(*data)Concatenate pair count data containers with equal patches.
from_corrdata(cross_data[, ref_data, ...])Compute redshift estimate from readily sampled function data.
from_correlation_data(*args, **kwargs)from_correlation_functions(*args, **kwargs)from_corrfuncs(cross_corr[, ref_corr, ...])Sample correlation functions to compute a redshift estimate.
from_files(path_prefix)Create a new instance by loading the data from ASCII files.
Get the underlying, exact redshift bin intervals.
Get value correlation matrix as data frame with its corresponding redshift bin intervals as index and column labels.
Get value covariance matrix as data frame with its corresponding redshift bin intervals as index and column labels.
get_data()Get the data as
pandas.Serieswith the binning as index.Get value error estimate (diagonal of covariance matrix) as series with its corresponding redshift bin intervals as index.
Get the data as
pandas.DataFramewith the binning as index.is_compatible(other[, require])Check whether this instance is compatible with another instance.
mean()Compute the mean redshift.
normalised(*args, **kwargs)Obtain a normalised copy of the data.
plot(*[, color, label, error_bars, ax, ...])Create a plot of the correlation data as a function of redshift.
plot_corr(*[, redshift, cmap, ax])Plot the correlation matrix of the data.
rebin(bins)Recomute the data for a different redshift binning.
shift([dz, amplitude])Shifts the data along the redshift axis.
to_files(path_prefix)Store the data in a set of ASCII files on disk.
Attributes
An
Indexerattribute that supports iteration over the bins or selecting a subset of the bins.Specifies on which side the redshift bin intervals are closed, can be:
left,right,both,neither.Whether the data is normalised, i.e. a density estimate.
Get the width of the redshift bins as array.
Get the edges of the redshift bins as flat array.
The uncertainty (standard error) of the data.
Optional descriptive text for the contained data.
Get the centers of the redshift bins as array.
Get the number of redshift bins.
Number of samples used for error estimate.
The redshift bin intervals.
The data values, one for each redshift bin.
Samples of the data values, shape (# samples, # bins).
The resampling method used.
Covariance matrix automatically computed from the resampled values.
- binning: IntervalIndex#
The redshift bin intervals.
- property bins: Indexer[int | slice | Sequence, _Tdata]#
An
Indexerattribute that supports iteration over the bins or selecting a subset of the bins.The indexer always returns new container instances with the indexed data subset or the current item when iterating.
Warning
Indexing rules for a one-dimensional numpy array apply, however if the resulting binning is not contiguous or contains repeated bins, some operations on the returned container may fail.
- Returns:
yaw.core.containers.Indexer
- property closed: str#
Specifies on which side the redshift bin intervals are closed, can be:
left,right,both,neither.
- concatenate_bins(*data: _Tdata) _Tdata#
Concatenate pair count data containers with equal patches.
The data is merged by appending the data along the redshift binning axis.
Note
Necessary condition for merging is that the patch numbers are identical and that the merged binning is contiguous and non-overlapping. Cannot merge cross- with autocorrelation containers.
- Parameters:
*data – Containers of same type that are appended to the patch dimension of this container.
- Returns:
New instance of this container with combined data.
- covariance: NDArray#
Covariance matrix automatically computed from the resampled values.
- data: NDArray#
The data values, one for each redshift bin.
- density: bool = False#
Whether the data is normalised, i.e. a density estimate.
- property dz: ndarray[Any, dtype[float64]]#
Get the width of the redshift bins as array.
- property edges: ndarray[Any, dtype[float64]]#
Get the edges of the redshift bins as flat array.
- property error: NDArray#
The uncertainty (standard error) of the data.
- Returns:
NDArray
- classmethod from_corrdata(cross_data: CorrData, ref_data: CorrData | None = None, unk_data: CorrData | None = None, info: str | None = None) RedshiftData#
Compute redshift estimate from readily sampled function data.
The required argument is a crosscorrelation measurement, additional parameters can specify sample autocorrelation measurements that are used to mitigate the evolving galaxy bias.
- Parameters:
cross_corr (
CorrData) – Data from the sampled cross-correlation function.ref_corr (
CorrData, optional) – Data from the sampled reference sample autocorrelation function. Used to mitigate reference bias evolution.unk_corr (
CorrData, optional) – Data from the sampled unknown sample autocorrelation function. Used to mitigate unknown bias evolution.
- Returns:
- classmethod from_correlation_data(*args, **kwargs)#
Deprecated since version 2.3.2: Renamed to
from_corrdata().
- classmethod from_correlation_functions(*args, **kwargs)#
Deprecated since version 2.3.2: Renamed to
from_corrfuncs().
- classmethod from_corrfuncs(cross_corr: CorrFunc, ref_corr: CorrFunc | None = None, unk_corr: CorrFunc | None = None, *, cross_est: str | None = None, ref_est: str | None = None, unk_est: str | None = None, config: ResamplingConfig | None = None, info: str | None = None) RedshiftData#
Sample correlation functions to compute a redshift estimate.
The required argument is a crosscorrelation measurement, additional parameters can specify sample autocorrelation measurements that are used to mitigate the evolving galaxy bias.
- Parameters:
cross_corr (
CorrFunc) – The measured cross-correlation function.ref_corr (
CorrFunc, optional) – The measured reference sample autocorrelation function. Used to mitigate reference bias evolution.unk_corr (
CorrFunc, optional) – The measured unknown sample autocorrelation function. Used to mitigate unknown bias evolution.
- Returns:
- classmethod from_files(path_prefix: Path | str) HistData[source]#
Create a new instance by loading the data from ASCII files.
The data is restored from a set of three input files produced by
to_files().Note
These file have the same names but different file extension, therefore only provide the base name without any extension to specifiy the input files.
- Parameters:
path_prefix (
str) – The base name of the input files without any file extension.- Returns:
CorrData
- get_binning() IntervalIndex#
Get the underlying, exact redshift bin intervals.
- Returns:
pandas.IntervalIndex
- get_correlation() DataFrame#
Get value correlation matrix as data frame with its corresponding redshift bin intervals as index and column labels.
- Returns:
pandas.DataFrame
- get_covariance() DataFrame#
Get value covariance matrix as data frame with its corresponding redshift bin intervals as index and column labels.
- Returns:
pandas.DataFrame
- get_data() Series#
Get the data as
pandas.Serieswith the binning as index.
- get_error() Series#
Get value error estimate (diagonal of covariance matrix) as series with its corresponding redshift bin intervals as index.
- Returns:
pandas.Series
- get_samples() DataFrame#
Get the data as
pandas.DataFramewith the binning as index. The columns are labelled numerically and each represent one of the samples.
- info: str | None = None#
Optional descriptive text for the contained data.
- is_compatible(other: SampledData, require: bool = False) bool#
Check whether this instance is compatible with another instance.
Ensures that both objects are instances of the same class, that the redshift binning is identical, that the number of samples agree, and that the resampling method is identical.
- Parameters:
other (
BinnedQuantity) – Object instance to compare to.require (
bool, optional) – Raise a ValueError if any of the checks fail.
- Returns:
bool
- mean() SampledValue[source]#
Compute the mean redshift.
- Returns:
Mean redshift for the redshift data and its samples in a data container.
- Return type:
- method: str#
The resampling method used.
- property mids: ndarray[Any, dtype[float64]]#
Get the centers of the redshift bins as array.
- property n_bins: int#
Get the number of redshift bins.
- property n_samples: int#
Number of samples used for error estimate.
- normalised(*args, **kwargs) HistData[source]#
Obtain a normalised copy of the data.
Normalises the data by integration along the redshift axis. This sets the containers
densityflag toTrue.- Returns:
- plot(*, color: str | NDArray | None = None, label: str | None = None, error_bars: bool = True, ax: Axis | None = None, xoffset: float = 0.0, plot_kwargs: dict[str, Any] | None = None, zero_line: bool = False, scale_by_dz: bool = False) Axis#
Create a plot of the correlation data as a function of redshift.
Create a new axis or plot to an existing one, add x-axis offsets, if plotting multiple instances, or specify if the values should be represented as points with errorbars (default) or as line plot with shaded area to represent uncertainties.
- Parameters:
color – Valid
matplotlibcolor used for the error bars or the line and the shaded uncertainty area.label (
str, optional) – Plot label for the legend.error_bars (
bool, optional) – Whether to plot error bars (the default) or a line plot with shaded area.ax (plot axis, optional) – Optional
matplotlibaxis to plot into.xoffset (
int, optional) – Shift to apply to the x-axis (redshift) values.plot_kwargs (
dict, optional) – Parameters passed to theerrobar()orplot()plotting functions.zero_lilne (
bool, optional) – Wether to draw a thin black line that indicatesy=0.scale_by_dz (
bool, optional) – Whether to multiply the y-values by the redshift bin widthdz.
- plot_corr(*, redshift: bool = False, cmap: str = 'RdBu_r', ax: Axis | None = None) Axis#
Plot the correlation matrix of the data.
Create a new axis or plot to an existing one.
- Parameters:
redshift (
bool, optional) – Whether to map the matrix onto redshifts or as regular matrix plot (the default).cmap (
str, optional) – Name of amatplotlibcolormap to use.ax (plot axis, optional) – Optional
matplotlibaxis to plot into.
- rebin(bins: NDArray) HistData[source]#
Recomute the data for a different redshift binning.
Warning
The result may be inaccurate since the result is interpolated step-wise.
- Parameters:
bins (
NDArray) – Edges of the new redshift bins. May exceed or cover just a fraction of the original redshift range.- Return type:
- samples: NDArray#
Samples of the data values, shape (# samples, # bins).
- shift(dz: float | SampledValue = 0.0, *, amplitude: float | SampledValue = 1.0) HistData[source]#
Shifts the data along the redshift axis.
The shifting is performed by recomputing the histogram with its original redshift bins which are shifted by some amount.
Warning
The result may be inaccurate since the result is interpolated step-wise.
- Parameters:
dz (
SampledValueorfloat) – The amplitude of the shift along the redshift axis. If the input provides samples of the shift, each redshift estimate sample is shifted individually to obtain a more accurate error estimate.amplitude (
SampledValueorfloat) – An optional ampltude factor applied to the redshift estimate. Same rules as for thedzparameter.
- Return type:
- to_files(path_prefix: Path | str) None#
Store the data in a set of ASCII files on disk.
These files can be loaded with the
from_files()method. There are three files with the same name but different file extension.Files
[path_prefix].dat: Contains the redshift bin edges, the data values and their standard error. Additionally there is information about the error estimate and theinfoattribute.[path_prefix].smp: Contains one row for each redshift bin. The first two columns list the lower and upper edge of the redshift bin, the remaining columns list the values of the samples, i.e. there areN+2columns. Additionally contains theinfoattribute.[path_prefix].cov: Contains the covariance matrix and additionally theinfoattribute.- Parameters:
path_prefix (
str) – The base name of the output files without any file extension.