binny.tomography.core module#

Tomographic redshift distributions and construction.

class binny.tomography.core.Tomography(z: NDArray[~numpy.float64], nz: NDArray[~numpy.float64], bins: dict[int, NDArray[~numpy.float64]], metadata: dict[str, ~typing.Any] = <factory>, spec: dict[str, ~typing.Any] | None = None, survey_metadata: dict[str, ~typing.Any] = <factory>)#

Bases: object

Tomographic distributions evaluated on a common redshift grid.

Parameters:
  • z – True-redshift grid.

  • nz – Parent redshift distribution.

  • bins – Mapping from bin index to redshift distribution.

  • metadata – Numerical metadata and diagnostics associated with the tomographic binning. Defaults to an empty dictionary.

  • spec – Optional resolved tomography specification, including any configuration overrides. None when no specification was used.

  • survey_metadata – Optional survey-level metadata, including survey properties and provenance. Defaults to an empty dictionary.

property bin_indices: list[int]#

Sorted tomographic bin indices.

bins: dict[int, NDArray[float64]]#
metadata: dict[str, Any]#
property n_bins: int#

Number of tomographic bins.

nz: NDArray[float64]#
spec: dict[str, Any] | None = None#
survey_metadata: dict[str, Any]#
z: NDArray[float64]#
binny.tomography.core.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.