Skip to main content

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

Generated API documentation is available at bovi-analytics.github.io/bovi/lactationcurve.html.

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: (Insert your used version number here).

Zenodo. https://doi.org/10.5281/zenodo.18715144

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

GNU AGPLv3 License

Metadata

Release files for lactationcurve 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lactationcurve 1.3.0
File Size Uploaded Provenance Actions
lactationcurve-1.3.0.tar.gz 638.5 kB Without provenance Details for lactationcurve-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lactationcurve 1.3.0
File Interpreter ABI Platform Actions
lactationcurve-1.3.0-py3-none-any.whl Python 3 none any Details for lactationcurve-1.3.0-py3-none-any.whl

Total release size: 716.0 kB

Release files / lactationcurve-1.3.0.tar.gz

Download URL lactationcurve-1.3.0.tar.gz
Size 638.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ca8a3aa613c68d31f63d423796fa2df2e4b5e3012cd59e07e0508a20c5bac128
BLAKE2b-256 checksum
How to use checksums
052604b4d84bcd95353e6ac3756a27fe943be31958807e90d36326b2293dde73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","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}

Release files / lactationcurve-1.3.0-py3-none-any.whl

Download URL lactationcurve-1.3.0-py3-none-any.whl
Size 77.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04f0b2c610c9295c5b004af611e0c56fe8a9e8e6da6d5c19afb1c3dbf0b7b215
BLAKE2b-256 checksum
How to use checksums
58eb3980ca10152fe65ecfe202fe4a56aa8a62d5bfd53aca6369c93378202826
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","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}

Security for lactationcurve 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page