binny.tomography package#

Construction and representation of tomographic redshift distributions.

binny.tomography.build_predefined_tomography(z: Any, bins: Mapping[int, Any], *, nz: Any | None = None, normalize_bins: bool = False, norm_method: Literal['trapezoid', 'simpson'] = 'trapezoid', include_metadata: bool = False) → Tomography#

Build tomography directly from supplied bin distributions.

The parent n(z) is the sum of the raw bins unless explicitly provided. Optional normalization affects the returned bins, not the parent.

binny.tomography.build_tomography(z: NDArray[float64], nz: NDArray[float64], edges: NDArray[float64] | None = None, assignment: Callable[[NDArray[float64], NDArray[float64]], NDArray[float64]] | None = None, *, bins: Mapping[str, Any] | None = None, method: Literal['deterministic', 'specz', 'photoz'] | None = None, params: Mapping[str, Any] | None = None, z_ph: NDArray[float64] | None = None, nz_ph: NDArray[float64] | None = None, selection_kind: Literal['probability', 'weight'] = 'probability', normalize_input: bool = True, normalize_bins: bool = True, norm_method: Literal['trapezoid', 'simpson'] = 'trapezoid', include_metadata: bool = True, include_photoz_diagnostics: bool = False, save_metadata_path: str | None = None) → Tomography#

Build tomographic redshift distributions from a bin-assignment model.

Bin edges may be supplied directly or constructed from a declarative binning specification. Exactly one of edges or bins must be provided.

Parameters:
  • z – True-redshift grid.

  • nz – Parent redshift distribution.

  • edges – Explicit tomographic bin edges. Mutually exclusive with bins.

  • assignment – Optional custom assignment function returning an array of shape (n_bins, n_z).

  • bins – Declarative binning specification supporting explicit, generated, or mixed binning. Mutually exclusive with edges.

  • method – Built-in assignment model: "deterministic", "specz", or "photoz". Defaults to "deterministic" when no custom assignment is provided.

  • params – Model-specific keyword arguments passed to the selected assignment function.

  • z_ph – Optional observed photometric-redshift grid used to resolve bin edges. Requires nz_ph and method=”photoz”.

  • nz_ph – Optional observed photometric-redshift distribution sampled on z_ph.

  • selection_kind – Whether selections represent probabilities or arbitrary non-negative weights.

  • normalize_input – Whether to normalize the parent distribution before constructing bins. Defaults to True.

  • normalize_bins – Whether to normalize individual bin distributions. Defaults to True.

  • norm_method – Numerical integration method for normalization.

  • include_metadata – Whether to include numerical tomography metadata.

  • include_photoz_diagnostics – Whether to include photo-z assignment probabilities evaluated on the true-redshift grid. Requires method=”photoz” and also enables numerical metadata.

  • save_metadata_path – Optional path for writing tomography metadata in human-readable text form. Metadata can be saved independently of whether it is returned.

Returns:

Tomography result containing bin distributions and metadata.

Raises:
  • ValueError – If the edge inputs, assignment configuration, redshift distributions, binning specification, or diagnostic options are invalid.

  • TypeError – If model parameters are invalid.

binny.tomography.build_tomography_from_spec(z: Any | None = None, nz: Any | None = None, *, tomo_spec: Mapping[str, Any], predefined_bins: Mapping[int, Any] | None = None, include_tomo_metadata: bool = False, include_photoz_diagnostics: bool = False) → Tomography#

Build tomography from a survey-style specification.

Parameters:
  • z – True-redshift grid. Required for photo-z and spec-z tomography, and when predefined bins are supplied directly.

  • nz – Parent redshift distribution. Optional for predefined bins.

  • tomo_spec – Tomography specification defining the binning model, bin edges, and uncertainties.

  • predefined_bins – Optional mapping of externally supplied bin distributions for predefined tomography.

  • include_tomo_metadata – Whether to include numerical binning metadata.

  • include_photoz_diagnostics – Whether to include photo-z assignment diagnostics in the metadata.

Returns:

Tomography containing the constructed bins, optional numerical metadata, and the resolved tomography specification.

Raises:

ValueError – If required arrays are missing or the specification is invalid.

binny.tomography.load_predefined_bins(path: str | Path, *, z_col: int | str = 'z', bin_cols: Mapping[int, int | str] | None = None) → tuple[NDArray[float64], dict[int, NDArray[float64]]]#

Load predefined bins from a text file.

Supports named columns or zero-based integer column positions. Named columns matching bin_<integer> are detected automatically.

Submodules#