yaw.correlation.PatchedCounts#

class yaw.correlation.PatchedCounts(binning: Binning, counts: NDArray, *, auto: bool)[source]#

Bases: BinwisePatchwiseArray

Stores the pair counts in spatial patches from catalogs in a correlation measurement.

The pair counts are stored per redshift bin and combination of patches. The total counts per redshift bin, including jackknife samples thereof, can be obtained by calling sample_patch_sum(), which sums over all possible pairs of patches from the first and second catalog.

Implements comparison with the == operator, addition of counts with the +/+= operator and scalar multiplication of the counts with the * operator.

Parameters:
  • binning – Redshift bins used when counting pairs between patches.

  • counts – Array of with pair counts in bins of redshift between combinations of patch pairs from both catalos, numpy array with shape (num_bins, num_patches, num_patches).

Keyword Arguments:

auto – Whether this instance is intended for an autocorrelation measurement.

Methods

__init__(binning, counts, *, auto)

from_file(path)

Restore the class instance from a HDF5 file.

from_hdf(source)

Restore the class instance from a specific HDF5-file group.

get_array()

Represent the internal data as numpy array with shape (num_bins, num_patches, num_patches).

is_compatible(other, *[, require])

Checks if two containers have the same redshift binning and number of spatial patches.

sample_patch_sum()

Compute the sum over all patches and leave-one-out jackknife samples.

set_patch_pair(patch_id1, patch_id2, ...)

Set the correlation pair counts between two patches in each redshift bin.

to_file(path)

Serialise the class instances into a HDF5 file.

to_hdf(dest)

Serialise the class instances into a specific HDF5-file group.

zeros(binning, num_patches, *, auto)

Create a new instance with all pair counts initialised to zero.

Attributes

binning

Accessor for the redshift Binning attribute.

counts

Pair counts between patches of catalog 1 and 2 per redshift bin, array with shape (num_bins, num_patches, num_patches).

auto

Whether the pair counts originate from an autocorrelation measurement.

bins

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

num_bins

The number of redshift bins.

num_patches

The number of spatial patches.

patches

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

auto: bool#

Whether the pair counts originate from an autocorrelation measurement.

binning: Binning#

Accessor for the redshift Binning attribute.

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.

counts: NDArray#

Pair counts between patches of catalog 1 and 2 per redshift bin, array with shape (num_bins, num_patches, num_patches).

classmethod from_file(path: Path | str) Self#

Restore the class instance from a HDF5 file.

Parameters:

path – Path (str or pathlib.Path) to HDF5 file to restore from, see also to_file().

Returns:

Restored class instance.

classmethod from_hdf(source: Group) Self[source]#

Restore the class instance from a specific HDF5-file group.

Parameters:

source – HDF5-file group to restore from, see also to_hdf().

Returns:

Restored class instance.

get_array() NDArray[source]#

Represent the internal data as numpy array with shape (num_bins, num_patches, num_patches).

I.e. the first array element contains the data associated with the first redshift bin and pairing the first patch with itself.

Returns:

Internal data represented as numpy array.

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

Checks if two containers have the same redshift binning and number of spatial patches.

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 number of patches is identical if require=False.

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

  • ValueError – If require=True and binning and the number of patches is not identical.

property num_bins: int#

The number of redshift bins.

property num_patches: int#

The number of spatial patches.

property patches: 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.

sample_patch_sum() SampledData#

Compute the sum over all patches and leave-one-out jackknife samples.

I.e. marginalise over the patch axes and return a 1-dim array with length num_bins.

Returns:

Sum over patches and jackknife samples thereof packed in an instance of SampledData.

set_patch_pair(patch_id1: int, patch_id2: int, counts_binned: NDArray) None[source]#

Set the correlation pair counts between two patches in each redshift bin.

Parameters:
  • patch_id1 – ID/index of the patch from catalog 1.

  • patch_id2 – ID/index of the patch from catalog 2.

  • counts_binned – Array with pair counts per redshift bin between patches with length num_patches.

to_file(path: Path | str) None#

Serialise the class instances into a HDF5 file.

Parameters:

path – Path (str or pathlib.Path) to HDF5 file to serialise into, see also from_file().

to_hdf(dest: Group) None[source]#

Serialise the class instances into a specific HDF5-file group.

Parameters:

dest – HDF5-file group to serialise into, see also from_hdf().

classmethod zeros(binning: Binning, num_patches: int, *, auto: bool) Self[source]#

Create a new instance with all pair counts initialised to zero.

Parameters:
  • binning – Redshift bins used when counting pairs between patches.

  • num_patches – The number of patches in the input catalogs used for the correlation measurement.

Keyword Arguments:

auto – Whether this instance is intended for an autocorrelation measurement.

Returns:

Initialised PatchedCounts instance.