binny.binning.specs module#

Validate dictionary specifications for one-dimensional bin construction.

binny.binning.specs.restrict_bin_range(z: NDArray[float64], nz: NDArray[float64], bin_range: tuple[float, float] | None) → tuple[NDArray[float64], NDArray[float64]]#

Restrict sampled data to an interval, interpolating its endpoints.

The sampling coordinates and their associated density are restricted to the requested interval. If an endpoint does not coincide with an existing sample, its density is obtained by linear interpolation.

The original arrays are not modified.

Parameters:
  • z – Strictly increasing one-dimensional sampling coordinates.

  • nz – Density or weights evaluated on z.

  • bin_range – Optional interval containing the lower and upper boundaries. If omitted, the complete arrays are returned.

Returns:

Pair containing the restricted sampling coordinates and corresponding interpolated density values.

Raises:

ValueError – If the sampling arrays are invalid, the interval is malformed, or its boundaries lie outside the grid.

binny.binning.specs.validate_bins(bins: Mapping[str, Any]) → tuple[Literal['explicit', 'generated', 'mixed'], dict[str, Any]]#

Validate a binning specification and identify its construction mode.

Exactly one of edges, scheme, or segments selects the binning mode.

Explicit binning accepts supplied boundaries. Generated binning accepts a registered scheme, a number of bins, and an optional coordinate interval. Mixed binning combines independently specified schemes over adjacent intervals.

Scheme-specific parameters are checked by the registered scheme resolver rather than by this function.

Parameters:

bins – Mapping describing explicit, generated, or mixed binning.

Returns:

Pair containing the selected binning mode and a validated shallow copy of the specification.

Raises:
  • TypeError – If bins is not a mapping.

  • ValueError – If the specification selects multiple modes, contains unsupported keys, or has invalid parameters.