binny.analysis.comparison module#

Compare tomographic redshift distributions.

binny.analysis.comparison.between_bin_overlap(z_a: Any, bins_a: Mapping[int, Any], z_b: Any, bins_b: Mapping[int, Any], *, method: str = 'min', unit: Literal['fraction', 'percent'] = 'fraction', normalize: bool = False, rtol: float = 0.001, atol: float = 1e-06, decimal_places: int | None = 2) → dict[int, dict[int, float]]#

Compare bins from two tomographic samples.

Parameters:
  • z_a – Redshift grid of the first sample.

  • bins_a – Distributions of the first sample.

  • z_b – Redshift grid of the second sample.

  • bins_b – Distributions of the second sample.

  • method – Comparison metric: min, cosine, js, hellinger, or tv.

  • unit – Fraction or percent.

  • normalize – Whether to normalize the distributions.

  • rtol – Relative normalization tolerance.

  • atol – Absolute normalization tolerance.

  • decimal_places – Number of decimal places, or None.

Returns:

Matrix comparing bins from the first and second samples.

Raises:

ValueError – If the metric or input distributions are invalid.

binny.analysis.comparison.between_interval_mass_matrix(z: Any, bins: Mapping[int, Any], target_edges: Mapping[int, tuple[float, float]] | Sequence[float] | ndarray, *, unit: Literal['fraction', 'percent'] = 'fraction', decimal_places: int | None = 2) → dict[int, dict[int, float]]#

Measure how much of each bin lies within target intervals.

Parameters:
  • z – Redshift grid.

  • bins – Input redshift distributions.

  • target_edges – Redshift intervals to compare against.

  • unit – Fraction or percent.

  • decimal_places – Number of decimal places, or None.

Returns:

Matrix where entry (i, j) gives the fraction of input bin i within target interval j.

Raises:

ValueError – If the intervals, units, or bin masses are invalid.

binny.analysis.comparison.between_overlap_pairs(z_a: Any, bins_a: Mapping[int, Any], z_b: Any, bins_b: Mapping[int, Any], *, threshold: float = 10.0, unit: Literal['fraction', 'percent'] = 'percent', method: str = 'min', direction: Literal['high', 'low'] = 'high', normalize: bool = False, rtol: float = 0.001, atol: float = 1e-06, decimal_places: int | None = 2) → list[tuple[int, int, float]]#

Find bin pairs from two samples that pass a threshold.

Parameters:
  • z_a – Redshift grid of the first sample.

  • bins_a – Distributions of the first sample.

  • z_b – Redshift grid of the second sample.

  • bins_b – Distributions of the second sample.

  • threshold – Minimum or maximum accepted value.

  • unit – Fraction or percent, including the threshold.

  • method – Comparison metric: min, cosine, js, hellinger, or tv.

  • direction – Select values above or below the threshold.

  • normalize – Whether to normalize the distributions.

  • rtol – Relative normalization tolerance.

  • atol – Absolute normalization tolerance.

  • decimal_places – Number of decimal places, or None.

Returns:

Sorted list of matching cross-sample bin pairs.

Raises:

ValueError – If the direction, metric, or inputs are invalid.

binny.analysis.comparison.between_pearson_matrix(z_a: Any, bins_a: Mapping[int, Any], z_b: Any, bins_b: Mapping[int, Any], *, normalize: bool = False, rtol: float = 0.001, atol: float = 1e-06, decimal_places: int | None = 2) → dict[int, dict[int, float]]#

Calculate Pearson correlations between bins from two samples.

Parameters:
  • z_a – Redshift grid of the first sample.

  • bins_a – Distributions of the first sample.

  • z_b – Redshift grid of the second sample.

  • bins_b – Distributions of the second sample.

  • normalize – Whether to normalize the distributions.

  • rtol – Relative normalization tolerance.

  • atol – Absolute normalization tolerance.

  • decimal_places – Number of decimal places, or None.

Returns:

Matrix of cross-sample Pearson correlation coefficients.

Raises:

ValueError – If the input distributions are invalid.

binny.analysis.comparison.bin_overlap(z: Any, bins: Mapping[int, Any], *, method: str = 'min', unit: Literal['fraction', 'percent'] = 'fraction', normalize: bool = False, rtol: float = 0.001, atol: float = 1e-06, decimal_places: int | None = 2) → dict[int, dict[int, float]]#

Compare all pairs of bins within one tomographic sample.

Parameters:
  • z – Redshift grid.

  • bins – Redshift distributions indexed by bin.

  • method – Comparison metric: min, cosine, js, hellinger, or tv.

  • unit – Fraction or percent.

  • normalize – Whether to normalize the distributions.

  • rtol – Relative normalization tolerance.

  • atol – Absolute normalization tolerance.

  • decimal_places – Number of decimal places, or None.

Returns:

Symmetric matrix of pairwise comparison values.

Raises:

ValueError – If the metric or input distributions are invalid.

binny.analysis.comparison.leakage_matrix(z: Any, bins: Mapping[int, Any], bin_edges: Mapping[int, tuple[float, float]] | Sequence[float] | ndarray, *, unit: Literal['fraction', 'percent'] = 'fraction', decimal_places: int | None = 2) → dict[int, dict[int, float]]#

Measure how much of each bin lies within each nominal bin interval.

Parameters:
  • z – Redshift grid.

  • bins – Redshift distributions indexed by bin.

  • bin_edges – Nominal redshift intervals of the bins.

  • unit – Fraction or percent.

  • decimal_places – Number of decimal places, or None.

Returns:

Matrix where entry (i, j) gives the fraction of bin i within the nominal interval of bin j.

Raises:

ValueError – If the intervals, units, or bin masses are invalid.

binny.analysis.comparison.overlap_pairs(z: Any, bins: Mapping[int, Any], *, threshold: float = 10.0, unit: Literal['fraction', 'percent'] = 'percent', method: str = 'min', direction: Literal['high', 'low'] = 'high', normalize: bool = False, rtol: float = 0.001, atol: float = 1e-06, decimal_places: int | None = 2) → list[tuple[int, int, float]]#

Find bin pairs whose comparison values pass a threshold.

Parameters:
  • z – Redshift grid.

  • bins – Redshift distributions indexed by bin.

  • threshold – Minimum or maximum accepted value.

  • unit – Fraction or percent, including the threshold.

  • method – Comparison metric: min, cosine, js, hellinger, or tv.

  • direction – Select values above or below the threshold.

  • normalize – Whether to normalize the distributions.

  • rtol – Relative normalization tolerance.

  • atol – Absolute normalization tolerance.

  • decimal_places – Number of decimal places, or None.

Returns:

Sorted list of matching bin pairs and their values.

Raises:

ValueError – If the direction, metric, or inputs are invalid.

binny.analysis.comparison.pearson_matrix(z: Any, bins: Mapping[int, Any], *, normalize: bool = False, rtol: float = 0.001, atol: float = 1e-06, decimal_places: int | None = 2) → dict[int, dict[int, float]]#

Calculate Pearson correlations between bins in one sample.

Parameters:
  • z – Redshift grid.

  • bins – Redshift distributions indexed by bin.

  • normalize – Whether to normalize the distributions.

  • rtol – Relative normalization tolerance.

  • atol – Absolute normalization tolerance.

  • decimal_places – Number of decimal places, or None.

Returns:

Symmetric matrix of Pearson correlation coefficients.

Raises:

ValueError – If the input distributions are invalid.