Lactation curve fitting and analysis library
Project description
lactationcurve (Python)
A toolkit for fitting dairy cow lactation curves, evaluating lactation curve characteristics (LCCs) (time to peak, peak yield, cumulative yield, persistency), and computing 305‑day milk yield using the ICAR guideline.
Contact: Meike van Leerdam, mbv32@cornell.edu
Authors: Judith Osei-Tete, Douwe de Kok, Lucia Trapanese & Meike van Leerdam
Initial authored: 2025‑08‑12
Updated: 2026‑02‑12
Main Lactation curve models implemented:
MilkBot – Flexible four-parameter model describing rise, peak, and decline. (Both frequentist and Bayesian fitting available)
Wood – Classic three-parameter gamma function model.
Wilmink – Linear–exponential hybrid model, with fixed or estimated decay rate.
Ali & Schaeffer – Polynomial–logarithmic model for complex curve shapes.
Fischer – Simplified exponential decay model.
Additional models available for a.o. symbolic LCC derivations: Brody , Sikka , Nelder , Dhanoa , Emmans , Hayashi , Rook , Dijkstra , Prasad .
Model Formulas
-
Wood :
y(t) = a * t^b * exp(-c * t) -
Wilmink :
y(t) = a + b * t + c * exp(k * t)with defaultk = -0.05 -
Ali & Schaeffer :
t_scaled = t / 340,L = ln(340 / t)y(t) = a + b*t_scaled + c*t_scaled^2 + d*L + k*L^2 -
Fischer :
y(t) = a - b*t - a*exp(-c*t) -
MilkBot :
y(t) = a * (1 - exp((c - t)/b) / 2) * exp(-d*t)
Features
- Frequentist fitting (numeric optimization & least squares):
- Wood, Wilmink, Ali & Schaeffer, Fischer, MilkBot
- Bayesian fitting via MilkBot API:
- MilkBot
- Lactation Curve Characteristics — symbolic + numeric:
- time_to_peak, peak_yield, cumulative_milk_yield, persistency
- ICAR procedures cumulative milk yield:
- Test Interval Method
- Input validation/normalization via
validate_and_prepare_inputs - Caching of symbolic expressions for performance
API Overview
The package is organized into three main modules:
lactationcurve.fittinglactationcurve.characteristicslactationcurve.preprocessing
Output Types Summary
| Function | Output |
|---------|--------|
| fit_lactation_curve | Predicted yields (np.ndarray) |
| get_lc_parameters | Tuple of numerical parameters |
| bayesian_fit_milkbot_single_lactation | Dict of MilkBot parameters |
| lactation_curve_characteristic_function | (expr, params, func) |
| calculate_characteristic | float (LCC value) |
| test_interval_method | DataFrame with 305‑day totals |
Bayesian (MilkBot API)
- Set
fitting="bayesian"andmodel="milkbot"infit_lactation_curveorcalculate_characteristic. - Provide an API key via .env
- Choose priors via
continent="USA" | "EU" | "CHEN"(CHEN supplies published priors from literature). - The helper
bayesian_fit_milkbot_single_lactation(...)normalizes differing API responses. - The key can be requested by sending an email to Jim Ehrlich jehrlich@MilkBot.com.
- More information about the API can be found here.
Citation
Citing the lactationcurve package
If you use the lactationcurve package in your research, please consider citing it as follows:
van Leerdam, M. B., de Kok, D., Osei-Tete, J. A., & Hostens, M. (2026). Bovi-analytics/bovi: v.1.1.1. (v.1.0.7).
Zenodo. https://doi.org/10.5281/zenodo.18715145
BibTex:
@software{van_leerdam_2026_lactationcurve,
author = {van Leerdam, Meike Beatrijs and de Kok, D. and Osei-Tete, J. A. and Hostens, M.},
title = {Bovi-analytics/lactation_curve_core: v.1.1.1},
version = {1.0.7},
year = {2026},
publisher = {Zenodo},
doi = {10.5281/zenodo.18715145},
url = {https://doi.org/10.5281/zenodo.18715145}
}
``
A machine-readable citation is included in `CITATION.cff
If you also use the Bayesian fitting functionality that relies on the MilkBot API, please also cite the following paper:
Ehrlich, J.L., 2013. Quantifying inter-group variability in lactation curve shape and magnitude with the MilkBot® lactation model. PeerJ 1, e54.
https://doi.org/10.7717/peerj.54
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lactationcurve-1.0.7.tar.gz.
File metadata
- Download URL: lactationcurve-1.0.7.tar.gz
- Upload date:
- Size: 589.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f30e3404df981d7a8d5e2589042d95c97811f0ea84861d2cf03831b29d71451f
|
|
| MD5 |
7d292248e6aaac5a0c62516129333568
|
|
| BLAKE2b-256 |
d741d72f4ca4ca50880a1d5b341990ea48effd754e69ffc6cb2ba0f9a43cad2a
|
File details
Details for the file lactationcurve-1.0.7-py3-none-any.whl.
File metadata
- Download URL: lactationcurve-1.0.7-py3-none-any.whl
- Upload date:
- Size: 41.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
702b089931e39f2ece7887512bba77f23f7d4ece377c9e1d8b17c879f07e3c55
|
|
| MD5 |
130b6ee3c980ec8e4b66950ea25950c2
|
|
| BLAKE2b-256 |
809d38ff4ea7aec2ce8c425285081bba4f765b1d4afa4d87f2ba06c42a81467c
|