Skip to main content

A package for fitting and analyzing microbial growth curves.

Project description

growthcurves

A Python package for fitting and analyzing microbial growth curves.

Supports logistic, Gompertz, and Richards parametric models with automatic growth statistics extraction (specific growth rate, doubling time, phase boundaries) and non-parametric methods (spline fitting and sliding window).

Installation

pip install growthcurves

For development:

pip install -e ".[dev]"

Quick start

import growthcurves as gc
import numpy as np

# Example time series (hours) and OD measurements
time = np.linspace(0, 24, 100)
od = 0.01 + 1.5 / (1 + np.exp(-0.5 * (time - 10)))  # synthetic logistic data

# Fit a parametric model and extract growth statistics
fit_result = gc.parametric.fit_parametric(time, od, method="mech_logistic")
stats = gc.utils.extract_stats(fit_result, time, od)

print(f"Max OD:               {stats['max_od']:.3f}")
print(f"Specific growth rate: {stats['mu_max']:.4f} h⁻¹")
print(f"Doubling time:        {stats['doubling_time']:.2f} h")

# Or use a non-parametric spline fit
spline_fit = gc.non_parametric.fit_non_parametric(time, od, umax_method="spline")
spline_stats = gc.utils.extract_stats(spline_fit, time, od)

print(f"\nSpline fit results:")
print(f"Specific growth rate: {spline_stats['mu_max']:.4f} h⁻¹")
print(f"Doubling time:        {spline_stats['doubling_time']:.2f} h")

Available models

Parametric models

Mechanistic models (ODE-based)

Model Function Parameters
Mech. Logistic models.mech_logistic_model mu, K, N0, y0
Mech. Gompertz models.mech_gompertz_model mu, K, N0, y0
Mech. Richards models.mech_richards_model mu, K, N0, beta, y0
Mech. Baranyi models.mech_baranyi_model mu, K, N0, h0, y0

Mechanistic models are defined as ordinary differential equations (ODEs) and fitted using numerical integration.

Phenomenological models (ln-space)

Model Function Parameters
Phenom. Logistic models.phenom_logistic_model A, mu_max, lam, N0
Phenom. Gompertz models.phenom_gompertz_model A, mu_max, lam, N0
Phenom. Gompertz* models.phenom_gompertz_modified_model A, mu_max, lam, alpha, t_shift, N0
Phenom. Richards models.phenom_richards_model A, mu_max, lam, nu, N0

Phenomenological models are fitted directly to ln(OD/OD0) data.

Non-parametric methods

Method Function Key parameters
Spline non_parametric.fit_non_parametric spline_s (smoothing)
Sliding window non_parametric.fit_non_parametric window_points

The spline method fits a smoothing spline to log-transformed OD data and calculates growth rate from the spline's derivative. This provides a flexible, model-free approach that adapts to the data shape. The smoothing parameter spline_s controls the balance between fit quality and smoothness (default: 0.01 for tight fit to data).

The sliding window method estimates growth rate by fitting a linear regression to log-transformed data within a moving window, identifying the window with maximum slope.

Spline fitting (non-parametric)

The spline method provides a model-free approach to growth curve analysis by fitting a smoothing spline to log-transformed OD data:

  1. Transform OD data: $y_{\text{log}} = \ln(N)$
  2. Fit a cubic smoothing spline $s(t)$ to $(t, y_{\text{log}})$ using scipy.interpolate.UnivariateSpline
  3. Calculate specific growth rate: $\mu(t) = \frac{d,s(t)}{dt}$
  4. Find maximum growth rate: $\mu_{\max} = \max_{t} \mu(t)$
Parameter Meaning
spline_s Smoothing factor (default: 0.01)
k Spline degree (default: 3, cubic)

The smoothing parameter spline_s controls the tradeoff between fit quality and smoothness. Lower values produce tighter fits to data; higher values produce smoother curves. The default of 0.01 produces a tight fit that closely follows the data, which can be increased for noisier datasets.

Derived growth statistics

Statistic Formula
Specific growth rate $\mu = \dfrac{1}{N}\dfrac{dN}{dt}$
Doubling time $t_d = \dfrac{\ln 2}{\mu_{\max}}$

Key features

  • Parametric fitting — fit logistic, Gompertz, or Richards models with automatic parameter estimation
  • Non-parametric methods — model-free growth rate estimation using:
    • Spline fitting — smoothing splines on log-transformed data with derivative-based growth rate calculation
    • Sliding window — moving window linear fits to log-transformed data
  • Growth statistics — automatic extraction of max OD, specific growth rate (µ_max), doubling time, and exponential-phase boundaries
  • Derivative analysis — first and second derivatives with Savitzky-Golay smoothing
  • No-growth detection — automatic identification of non-growing samples
  • Model comparison — RMSE fit-quality metric for comparing fits

Documentation and tutorial

An interactive tutorial notebook is available at docs/tutorial/tutorial.ipynb. It covers model fitting, derivative analysis, parameter extraction, and cross-model comparison using a realistic microbial growth dataset.

Citation

If you use this package, please cite it as described in CITATION.cff.

License

GPL-3.0-or-later. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

growthcurves-0.4.0.tar.gz (183.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

growthcurves-0.4.0-py3-none-any.whl (131.0 kB view details)

Uploaded Python 3

File details

Details for the file growthcurves-0.4.0.tar.gz.

File metadata

  • Download URL: growthcurves-0.4.0.tar.gz
  • Upload date:
  • Size: 183.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for growthcurves-0.4.0.tar.gz
Algorithm Hash digest
SHA256 44b5858cef138d721ad5f03a568165db36323c919534135ad9c768270b571c4e
MD5 580f574fb8bb31c6b434adabdcb7c742
BLAKE2b-256 b90409c1f43117dbb67e466801caf977f2beaf5e3696d2aa65d27e7b82347119

See more details on using hashes here.

File details

Details for the file growthcurves-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: growthcurves-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 131.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for growthcurves-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e3b1b3580cce11d085ab059711114ed245921e03d83fb30ccce864e729b10f8
MD5 d89359b179692061f6da1ca266819b9b
BLAKE2b-256 1a9d53bce87d7e32a0df6a0c8819d8964bc1d28559dd518a2dd6fad48e4971db

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page