Skip to main content

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 default k = -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
    • Interpolation Standard Lactation Curve (ISLC) Method
    • Best Predict 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:

  1. lactationcurve.fitting
  2. lactationcurve.characteristics
  3. lactationcurve.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 lactation milk yield totals |

| ISLC | DataFrame with lactation milk yield totals |

| ISLC_original | DataFrame with original grid-based ISLC totals |

| best_predict_method | DataFrame with best-prediction lactation milk yield totals |

The meaning of a TestId

The TestId is an identifier for a lactation. It is not necessarily the same as a cow ID, because a cow can have multiple lactations across calvings. If a TestId column is not provided, the package treats all records as one lactation and creates a default TestId.

Bayesian (MilkBot API)

  • Set fitting="bayesian" and model="milkbot" in fit_lactation_curve or calculate_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.1.2).

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.1.2},

  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

MIT 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

lactationcurve-1.1.2.tar.gz (607.9 kB view details)

Uploaded Source

Built Distribution

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

lactationcurve-1.1.2-py3-none-any.whl (55.9 kB view details)

Uploaded Python 3

File details

Details for the file lactationcurve-1.1.2.tar.gz.

File metadata

  • Download URL: lactationcurve-1.1.2.tar.gz
  • Upload date:
  • Size: 607.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","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

Hashes for lactationcurve-1.1.2.tar.gz
Algorithm Hash digest
SHA256 36b6f12e962cc8ea9138c21778f1422330760deb604d377b121921cb0767a83c
MD5 c65a7dd39934b69acaa3d3d41ad5e579
BLAKE2b-256 6645d200eb9b3fd8bf939f8ad1a588c852c3d71a4004255b5623b2d87a2e430a

See more details on using hashes here.

File details

Details for the file lactationcurve-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: lactationcurve-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 55.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","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

Hashes for lactationcurve-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8a7983a8e5713c05669a4da6dec3e5d95f18ebb4d1958e3a145839a0c9c25f73
MD5 31cf49f3fa1ddd0ecbe15e672b69c567
BLAKE2b-256 72385735d0d318c007b23fb473e6e5bf27f122fc0aba9ed4248b6cdb1e565fca

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