lfkit.utils.integrators module#

Numerical integration utilities.

This module provides small reusable helpers for integrating tabulated values over fixed or variable finite bounds. These helpers do not encode any luminosity function, photometry, or cosmology assumptions.

lfkit.utils.integrators.integrate_between_variable_bounds(y, *, lower, upper, integrand_fn, n_grid=512, y_name='y', lower_name='lower', upper_name='upper', n_grid_name='n_grid')[source]#

Integrate a callable between finite bounds that may vary with y.

Parameters:
  • y (float | Sequence[float] | ndarray[tuple[Any, ...], dtype[float64]]) – Coordinate values at which to evaluate the integral.

  • lower (float | Sequence[float] | ndarray[tuple[Any, ...], dtype[float64]]) – Lower integration bound. May be scalar or array-like.

  • upper (float | Sequence[float] | ndarray[tuple[Any, ...], dtype[float64]]) – Upper integration bound. May be scalar or array-like.

  • integrand_fn (Callable[[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]], ndarray[tuple[Any, ...], dtype[float64]]]) – Callable evaluated as integrand_fn(x_grid, y_grid).

  • n_grid (int) – Number of integration points.

  • y_name (str) – Name used for y in error messages.

  • lower_name (str) – Name used for lower in error messages.

  • upper_name (str) – Name used for upper in error messages.

  • n_grid_name (str) – Name used for n_grid in error messages.

Returns:

Integral values with the broadcast shape of y, lower, and upper.

Return type:

ndarray[tuple[Any, …], dtype[float64]]

lfkit.utils.integrators.safe_divide(numerator, denominator, *, fill_value=0.0)[source]#

Divide arrays safely, replacing invalid or zero-denominator results.

Parameters:
  • numerator (float | Sequence[float] | ndarray[tuple[Any, ...], dtype[float64]]) – Values in the numerator.

  • denominator (float | Sequence[float] | ndarray[tuple[Any, ...], dtype[float64]]) – Values in the denominator.

  • fill_value (float) – Value returned where the denominator is zero or where the division would produce a non-finite result.

Returns:

Broadcasted division result with invalid entries replaced by fill_value.

Return type:

ndarray[tuple[Any, …], dtype[float64]]