binny.binning.specz module#
Spectroscopic-redshift bin-response models.
- binny.binning.specz.apply_response_matrix(bins: Mapping[int, NDArray[float64]], matrix: NDArray[float64]) dict[int, NDArray[float64]]#
Applies a bin-response matrix to a set of tomographic bin distributions.
Treats the input bins as a stacked array with shape
(n_bins, ...)and returns the mixed binsobs = M @ true. The response matrix is expected to be column-stochastic and compatible with the number of bins and array shapes.- Parameters:
bins – Mapping from bin index to bin distribution arrays. Must contain exactly keys
0..n_bins-1and all arrays must share the same shape.matrix – Response matrix of shape
(n_bins, n_bins).
- Returns:
Dict mapping observed bin index to the mixed bin distribution.
- Raises:
ValueError – If keys/shapes are inconsistent or the matrix is invalid.
- binny.binning.specz.build_specz_response_matrix(n_bins: int, *, catastrophic_frac: Sequence[float] | float = 0.0, leakage_model: Literal['uniform', 'neighbor', 'gaussian'] = 'neighbor', leakage_sigma: Sequence[float] | float = 1.0, response_matrix: NDArray[float64] | None = None) NDArray[float64]#
Constructs a bin-to-bin response matrix for catastrophic reassignment.
Builds a column-stochastic matrix
Mwith entriesM[i, j] = P(i_obs|j_true)that describes reassignment of a fraction of objects in each true bin to other observed bins. If an explicitresponse_matrixis provided, it is validated and returned directly.- Parameters:
n_bins – Number of tomographic bins.
catastrophic_frac – Per-bin catastrophic fraction(s) in [0, 1].
leakage_model – Redistribution rule for the catastrophic fraction.
leakage_sigma – Width parameter for Gaussian leakage in bin-index space.
response_matrix – Optional explicit response matrix overriding the model.
- Returns:
A float array of shape
(n_bins, n_bins)that is column-stochastic.- Raises:
ValueError – If inputs are invalid or the resulting matrix fails validation.
- binny.binning.specz.specz_assignment(z: NDArray[float64], edges: NDArray[float64], *, completeness: Sequence[float] | float = 1.0, catastrophic_frac: Sequence[float] | float = 0.0, leakage_model: Literal['uniform', 'neighbor', 'gaussian'] = 'neighbor', leakage_sigma: Sequence[float] | float = 1.0, response_matrix: NDArray[float64] | None = None, specz_scatter: Sequence[float] | float | None = None, specz_scatter_model: Literal['sigma0_plus_sigma1_1pz'] = 'sigma0_plus_sigma1_1pz', sigma0: float = 0.0, sigma1: float = 0.0) NDArray[float64]#
Returns spectroscopic-redshift selection probabilities for each observed bin.
Constructs true-redshift top-hat selection functions with optional per-bin completeness factors and applies the combined catastrophic reassignment and Gaussian measurement-scatter response matrix.
The resulting selection probabilities are evaluated on the supplied true-redshift grid and are independent of the parent redshift distribution.
- Parameters:
z – True-redshift grid.
edges – True-redshift bin edges.
completeness – Per-bin selection completeness.
catastrophic_frac – Per-bin catastrophic reassignment fraction.
leakage_model – Catastrophic reassignment prescription.
leakage_sigma – Gaussian leakage width in bin-index space.
response_matrix – Optional explicit catastrophic response matrix.
specz_scatter – Optional spectroscopic measurement scatter.
specz_scatter_model – Scatter parameterization.
sigma0 – Constant scatter component.
sigma1 – Redshift-dependent scatter component.
- Returns:
Selection probabilities with shape
(n_bins, n_z).- Raises:
ValueError – If completeness, response matrix, or scatter settings are invalid.
- binny.binning.specz.specz_gaussian_response_matrix(*, z_arr: NDArray[float64], bin_edges: NDArray[float64], specz_scatter: Sequence[float] | float | None, model: Literal['sigma0_plus_sigma1_1pz'] = 'sigma0_plus_sigma1_1pz', sigma0: float = 0.0, sigma1: float = 0.0) NDArray[float64]#
Builds a Gaussian measurement-scatter response matrix for spec-z binning.
Constructs a column-stochastic matrix that maps true bins to observed bins under a Gaussian measurement model.
Response probabilities are averaged continuously over each true-bin interval, assuming uniform weighting in true redshift. The resulting matrix is independent of the sampling resolution and spacing of the redshift grid.
The scatter scale may be provided explicitly as a scalar or per-bin sequence, or derived from the redshift-dependent parameterization
sigma(z) = sigma0 + sigma1 * (1 + z).Numerical integration is performed over a dimensionless coordinate within each true-bin interval. Additional integration points near the bin boundaries improve resolution of narrow Gaussian scatter.
Columns are normalized to conserve the population within the modeled tomographic bins. Probability outside the modeled redshift range is therefore excluded through column renormalization rather than treated as a loss of objects.
- Parameters:
z_arr – True-redshift grid. Retained as an input for consistency with the spectroscopic binning interface. The response calculation does not depend on the grid sampling.
bin_edges – True-redshift bin edges defining true and observed bins.
specz_scatter – Optional scalar or per-bin constant scatter scale.
model – Scatter parameterization used when specz_scatter is None. The supported model is
"sigma0_plus_sigma1_1pz".sigma0 – Additive scatter component.
sigma1 – Redshift-dependent scatter component.
- Returns:
A column-stochastic float array of shape
(n_bins, n_bins).- Raises:
ValueError – If bin edges or scatter settings are invalid, or if the resulting response matrix cannot be normalized or validated.