binny.axes.mixed_edges module#

Module that constructs bin edges for mixed binning strategies.

binny.axes.mixed_edges.mixed_edges(segments: Sequence[Mapping[str, Any]], *, x: Any | None = None, weights: Any | None = None, info_density: Any | None = None, z: Any | None = None, chi: Any | None = None, total_n_bins: int | None = None) ndarray#

Computes bin edges for a mixed binning strategy across multiple segments.

Each segment specifies a binning method and a number of bins. Segment edge arrays are concatenated in order; shared boundaries are de-duplicated (the first edge of each subsequent segment is dropped) so the output is a single increasing edge array.

Segment specification:

Each element of segments is a mapping with keys:

  • "method": Binning method name or alias (resolved via binny.utils.validators.resolve_binning_method()).

  • "n_bins": Number of bins in this segment (integer).

  • "params": Optional mapping of method-specific parameters. Any missing required parameter may be provided as a global keyword argument to mixed_edges().

Global inputs:

Some methods require arrays (e.g. x/weights). These may be provided globally or per segment via params. A ValueError is raised if a required input is missing.

Parameters:
  • segments – Sequence of segment specifications.

  • x – 1D axis values (used by equal-number / equal-information methods).

  • weights – 1D weights on x (used by "equal_number").

  • info_density – 1D information density on x (used by "equal_information").

  • z – 1D redshift grid (used by "equidistant_chi").

  • chi – 1D comoving distance grid corresponding to z (used by "equidistant_chi").

  • total_n_bins – Optional total number of bins for validation (sum of segment n_bins).

Returns:

1D array of combined bin edges with shape (sum(n_bins) + 1,).

Raises:

ValueError – If segment specs are invalid, a required input is missing, a method is unknown, or segment edges are invalid/incompatible.