growthcurves.non_parametric module#
Non-parametric fitting methods for growth curves.
This module provides non-parametric methods for growth curve analysis, including sliding window fitting and no-growth detection.
All methods operate in linear OD space (not log-transformed).
- growthcurves.non_parametric.fit_non_parametric(t, N, method='sliding_window', window_points=15, smooth='fast', use_weights=False, **kwargs)[source]#
Calculate growth statistics using non-parametric methods.
This unified function supports multiple methods for calculating the maximum specific growth rate (Umax):
“sliding_window”: Finds maximum slope in log-transformed OD across windows
“spline”: Fits spline to entire curve and calculates from derivative
- Parameters:
t (Iterable[float]) – Time array (hours)
N (Iterable[float]) – OD values
method (str, optional) – Method for calculating Umax (“sliding_window” or “spline”), by default “sliding_window”
window_points (int, optional) – Number of points in sliding window (for sliding_window method), by default 15
smooth (str, optional) –
- Smoothing mode/value for spline method, by default “fast”
”fast”: notebook auto-default rule mapped to lam
”slow”: GCV-selected smoothing (auto GCV)
float: manual lam value
use_weights (bool, optional) – Whether to apply OD-dependent weighting for spline method, by default False
- Returns:
Dictionary with entries for - params: Model parameters (includes fit_t_min, fit_t_max, and other method-specific values) - model_type: Method used for fitting
- Return type:
- Raises:
ValueError – Method must be “sliding_window” or “spline”. Smooth must be “fast”, “slow”, or a non-negative float.
- growthcurves.non_parametric.fit_sliding_window(t, N, window_points=15, step=None, n_fits=None, **kwargs)[source]#
Calculate maximum specific growth rate using the sliding window method.
Finds the maximum specific growth rate by fitting a line to log-transformed OD N in consecutive windows using the Theil-Sen estimator, selecting the window with the steepest slope.
- Parameters:
t – Time array (hours)
N – OD values (baseline-corrected, must be positive)
window_points – Number of points in each sliding window
step – Step size for sliding window (default: 1 if step is None and n_fits is None)
n_fits – Approximate number of fits to perform (default: None). Ignored if step is provided.
- Returns:
- slope: Slope of the linear fit in log space
(equals specific growth rate, h⁻¹)
intercept: Intercept of the linear fit in log space
time_at_umax: Time at maximum growth rate (hours)
model_type: “sliding_window”
Returns None if calculation fails.
- Return type:
Dict with model parameters
- growthcurves.non_parametric.fit_spline(t, N, smooth='fast', use_weights=False)[source]#
Calculate maximum specific growth rate using spline fitting.
Fits a smoothing spline to log-transformed OD N and calculates the maximum specific growth rate from the spline’s derivative.
- Parameters:
t – Time array (hours)
N – OD values
smooth – Smoothing mode/value. - “fast”: notebook auto-default rule mapped to lam - “slow”: GCV-selected smoothing (lam=None) - float: manual lam value
use_weights – Whether to apply OD-dependent weighting (default: False)
- Returns:
- t_knots: Spline knot points (t values)
spline_coeffs: Spline coefficients
spline_k: Spline degree (3)
time_at_umax: Time at maximum growth rate (hours)
model_type: “spline”
Returns None if calculation fails.
- Return type:
Dict with model parameters