binny.axes.bin_edges module#

Module for computing bin edges based on different strategies.

binny.axes.bin_edges.equal_information_edges(x: Any, info_density: Any, n_bins: int) ndarray#

Return bin edges with equal integrated information per bin.

This is the same construction as equal_number_edges(), but the supplied weights represent an information density rather than counts. Each bin contains the same integral of info_density over x.

Parameters:
  • x – 1D axis values (must be strictly increasing).

  • info_density – 1D information density defined on x.

  • n_bins – Number of bins.

Returns:

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

Raises:

ValueError – If inputs are invalid or the total integrated information is non-positive.

binny.axes.bin_edges.equal_number_edges(x: Any, weights: Any, n_bins: int) ndarray#

Returns bin edges with equal integrated weight per bin.

This constructs edges along x such that each bin encloses the same integrated weight over x. When weights represent galaxy counts or number density, this yields equal-number (equipopulated) bins.

Parameters:
  • x – 1D axis values (must be strictly increasing).

  • weights – 1D weights defined on x (e.g. counts, number density).

  • n_bins – Number of bins.

Returns:

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

Raises:

ValueError – If inputs are not 1D, have mismatched shapes, contain non-finite values, are not strictly increasing in x, or if the total integrated weight is non-positive.

binny.axes.bin_edges.equidistant_chi_edges(z: Any, chi: Any, n_bins: int) ndarray#

Returns bin edges uniform in comoving distance, expressed in z.

Requires chi(z) is monotonic and z and chi are matched 1D arrays. Useful for cosmological applications where uniform spacing in comoving distance is desired.

Parameters:
  • z – 1D array of redshift values.

  • chi – 1D array of comoving distance values corresponding to z.

  • n_bins – Number of bins.

Returns:

Array of bin edges in redshift of shape (n_bins + 1,), uniform in comoving distance.

Raises:

ValueError – If chi is not strictly increasing.

binny.axes.bin_edges.equidistant_edges(x_min: float, x_max: float, n_bins: int) ndarray#

Returns uniformly spaced bin edges between x_min and x_max.

This method includes both endpoints. Works for any 1D axis: redshift, ell, k, etc. Useful for linear scales.

Parameters:
  • x_min – Minimum value of the axis.

  • x_max – Maximum value of the axis.

  • n_bins – Number of bins.

Returns:

Array of bin edges of shape (n_bins + 1,), uniformly spaced.

binny.axes.bin_edges.geometric_edges(x_min: float, x_max: float, n_bins: int) ndarray#

Returns geometrically spaced bin edges between x_min and x_max.

Geometric spacing means the ratio between successive edges is constant, i.e. edges[k+1] / edges[k] is the same for all k. The returned edges include both endpoints.

Notes

Geometric spacing is the multiplicative analogue of linear spacing. It is effectively the same as “log-spaced edges” (equal spacing in log(x)), just expressed in ratio form (via np.geomspace) rather than via a chosen log base (via np.logspace).

Parameters:
  • x_min – Lower endpoint of the axis (must be > 0).

  • x_max – Upper endpoint of the axis (must be > 0 and > x_min).

  • n_bins – Number of bins.

Returns:

Array of bin edges with shape (n_bins + 1,).

binny.axes.bin_edges.log_edges(x_min: float, x_max: float, n_bins: int) ndarray#

Returns logarithmically spaced bin edges between x_min and x_max.

The returned edges are equally spaced in log10(x) and include both endpoints.

Notes

The edges are equally spaced in log10(x) (via np.logspace). For positive endpoints, this produces the same spacing as geometric spacing (constant ratio between successive edges), up to floating-point rounding.

Parameters:
  • x_min – Lower endpoint of the axis (must be > 0).

  • x_max – Upper endpoint of the axis (must be > 0 and > x_min).

  • n_bins – Number of bins.

Returns:

Array of bin edges with shape (n_bins + 1,).