growthcurves package#

growthcurves.blank_subtraction(N: ndarray, blank: ndarray) ndarray[source]#

Subtract blank values from time data series of growth measurements.

Performs element-wise subtraction of blank measurements from measurements. This is commonly used for baseline correction in optical density measurements.

Parameters:
  • N (numpy.ndarray) – Data series to be corrected (e.g., OD measurements)

  • blank (numpy.ndarray) – Blank/background measurements to subtract. Must be the same length as N, or a scalar value to subtract from all N points.

Returns:

Blank-subtracted N

Return type:

numpy.ndarray

Examples

>>> import numpy as np
>>> N = np.array([0.5, 0.6, 0.7, 0.8])
>>> blank = np.array([0.05, 0.05, 0.05, 0.05])
>>> corrected = blank_subtraction(N, blank)
>>> corrected
array([0.45, 0.55, 0.65, 0.75])
growthcurves.compare_methods(t: ndarray, N: ndarray, model_family: str = 'all', phase_boundary_method: str = None, **fit_kwargs) tuple[source]#

Fit multiple models and extract growth statistics for comparison.

This all-in-one convenience function fits all models in a specified family, extracts their statistics, and returns both for analysis and visualization.

Parameters:
  • t (numpy.ndarray) – Time array for fitting

  • N (numpy.ndarray) – OD N array for fitting

  • model_family (str, optional) – Which family of models to fit. Options: - “mechanistic” : All mechanistic models (mech_logistic, mech_gompertz, etc.) - “phenomenological” : All phenomenological models - “all” : All available models Default: “all”

  • phase_boundary_method (str, optional) – Method for calculating phase boundaries (“threshold” or “tangent”). If None, uses default for each model type.

  • **fit_kwargs – Additional keyword arguments to pass to fitting functions (e.g., spline_s=100, window_points=15)

Returns:

Returns (fits, stats) where: - fits: Dictionary mapping method names to fit result dictionaries - stats: Dictionary mapping method names to statistics dictionaries The stats dictionary can be passed directly to plot_growth_stats_comparison().

Return type:

tuple of (dict, dict)

Examples

>>> # Fit and compare all mechanistic models
>>> fits, stats = gc.inference.compare_methods(t,
                                               N,
                                               model_family="mechanistic")
>>>
>>> # Plot comparison
>>> fig = gc.plot.plot_growth_stats_comparison(stats, title="Mechanistic Models")
>>> fig.show()
>>>
>>> # Fit phenomenological models with tangent phase boundaries
>>> fits, stats = gc.inference.compare_methods(
...     t, N,
...     model_family="phenomenological",
...     phase_boundary_method="tangent"
... )
growthcurves.fit_model(t: ndarray, N: ndarray, model_name: str, lag_threshold: float = 0.15, exp_threshold: float = 0.15, phase_boundary_method=None, **kwargs) tuple[dict, dict][source]#

Fit a growth model to the provided t and N.

Parameters:
  • t (np.ndarray) – Time points corresponding to N (in hours).

  • N (np.ndarray) – Growth data points corresponding to t.

  • model_name (str) – One of the models in mech_logistic, mech_gompertz, mech_richards, mech_baranyi, phenom_logistic, phenom_gompertz, phenom_gompertz_modified, phenom_richards, spline, sliding_window.

  • lag_threshold (float, optional) – Fraction of μ_max to define end of lag phase (threshold method, default: 0.15).

  • exp_threshold (float, optional) – Fraction of μ_max to define end of exponential phase (threshold method, default: 0.15).

  • phase_boundary_method (str, optional) – Method to determine phase boundaries (“tangent”, “threshold”, or None for default for model class).

  • **kwargs – Additiona keyword arguments to be passed to fitting and inference functions.

Returns:

Return tuple of two dictionaries: (fit_res, stats_res) - fit_res: Dictionary containing fitted model parameters. - stats_res: Dictionary containing goodness-of-fit statistics and growth metrics

Return type:

tuple[dict, dict]

growthcurves.get_all_models()[source]#

Return a set of all model names (parametric + non-parametric).

growthcurves.get_all_parametric_models()[source]#

Return a set of all parametric model names (mechanistic + phenomenological).

growthcurves.get_model_category(model_type)[source]#

Return the category of a model type.

Parameters:

model_type – Model type string

Returns:

“mechanistic”, “phenomenological”, or “non_parametric”

Return type:

Category string

Raises:

ValueError – If model_type is not recognized

growthcurves.path_correct(N: ndarray, path_length_cm: float) ndarray[source]#

Correct optical density measurements to a standard 1 cm path length.

Normalizes OD measurements taken at a specific path length to what they would be at a 1 cm path length using Beer-Lambert law (OD is proportional to path length).

Parameters:
  • N (numpy.ndarray) – Optical density measurements to correct

  • path_length_cm (float) – Actual path length of the measurement in centimeters (must be > 0)

Returns:

Path-corrected N normalized to 1 cm path length

Return type:

numpy.ndarray

Raises:

ValueError – If path_length_cm is not positive

Examples

>>> import numpy as np
>>> # Measurement taken with 0.5 cm path length
>>> N = np.array([0.25, 0.30, 0.35])
>>> corrected = path_correct(N, path_length_cm=0.5)
>>> corrected  # OD values as if measured with 1 cm path
array([0.5, 0.6, 0.7])
>>> # Measurement taken with 2 cm path length
>>> N = np.array([1.0, 1.2, 1.4])
>>> corrected = path_correct(N, path_length_cm=2.0)
>>> corrected
array([0.5, 0.6, 0.7])

Notes

The correction uses the relationship: OD_1cm = OD_measured / path_length

This assumes the Beer-Lambert law holds (linear relationship between absorbance and path length), which is typically valid for OD < 1.0-1.5.

Submodules#