bestpred 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. bestpred-0.2.1/.agents/plugins/marketplace.json +20 -0
  2. bestpred-0.2.1/.claude-plugin/marketplace.json +14 -0
  3. bestpred-0.2.1/.github/workflows/release.yml +53 -0
  4. bestpred-0.2.1/.gitignore +7 -0
  5. bestpred-0.2.1/CITATION.cff +37 -0
  6. bestpred-0.2.1/LICENSE +202 -0
  7. bestpred-0.2.1/NOTICE +65 -0
  8. bestpred-0.2.1/PKG-INFO +168 -0
  9. bestpred-0.2.1/README.md +147 -0
  10. bestpred-0.2.1/docs/agents-plan.md +78 -0
  11. bestpred-0.2.1/llms.txt +18 -0
  12. bestpred-0.2.1/mcp/Dockerfile +11 -0
  13. bestpred-0.2.1/mcp/README.md +62 -0
  14. bestpred-0.2.1/mcp/pyproject.toml +33 -0
  15. bestpred-0.2.1/mcp/src/bestpred_mcp/__init__.py +3 -0
  16. bestpred-0.2.1/mcp/src/bestpred_mcp/__main__.py +32 -0
  17. bestpred-0.2.1/mcp/src/bestpred_mcp/herd.py +244 -0
  18. bestpred-0.2.1/mcp/src/bestpred_mcp/hosted.py +93 -0
  19. bestpred-0.2.1/mcp/src/bestpred_mcp/server.py +185 -0
  20. bestpred-0.2.1/mcp/tests/test_server.py +137 -0
  21. bestpred-0.2.1/plugins/bestpred/.claude-plugin/plugin.json +10 -0
  22. bestpred-0.2.1/plugins/bestpred/.codex-plugin/plugin.json +28 -0
  23. bestpred-0.2.1/plugins/bestpred/.mcp.json +8 -0
  24. bestpred-0.2.1/plugins/bestpred/README.md +27 -0
  25. bestpred-0.2.1/plugins/bestpred/skills/lactation-records/SKILL.md +40 -0
  26. bestpred-0.2.1/pyproject.toml +41 -0
  27. bestpred-0.2.1/server.json +17 -0
  28. bestpred-0.2.1/src/bestpred/__init__.py +13 -0
  29. bestpred-0.2.1/src/bestpred/__main__.py +5 -0
  30. bestpred-0.2.1/src/bestpred/adjust.py +152 -0
  31. bestpred-0.2.1/src/bestpred/cli.py +51 -0
  32. bestpred-0.2.1/src/bestpred/core.py +537 -0
  33. bestpred-0.2.1/src/bestpred/curves.py +231 -0
  34. bestpred-0.2.1/src/bestpred/data/adjust.scs +755 -0
  35. bestpred-0.2.1/src/bestpred/data/tables.json +1 -0
  36. bestpred-0.2.1/src/bestpred/format4.py +141 -0
  37. bestpred-0.2.1/src/bestpred/tables.py +121 -0
  38. bestpred-0.2.1/tests/data/records.dat +40 -0
  39. bestpred-0.2.1/tests/data/ref_ages.txt +2160 -0
  40. bestpred-0.2.1/tests/data/ref_default.txt +40 -0
  41. bestpred-0.2.1/tests/data/ref_default_daily.txt +4 -0
  42. bestpred-0.2.1/tests/data/ref_kilograms.txt +40 -0
  43. bestpred-0.2.1/tests/data/ref_laclen-330.txt +40 -0
  44. bestpred-0.2.1/tests/data/ref_linear-curves.txt +40 -0
  45. bestpred-0.2.1/tests/data/ref_mt-all-four.txt +40 -0
  46. bestpred-0.2.1/tests/data/ref_old-3x.txt +40 -0
  47. bestpred-0.2.1/tests/data/ref_region-season-curves.txt +40 -0
  48. bestpred-0.2.1/tests/data/ref_season-curves.txt +40 -0
  49. bestpred-0.2.1/tests/data/ref_single-trait.txt +40 -0
  50. bestpred-0.2.1/tests/data/usda_format4.dat +1 -0
  51. bestpred-0.2.1/tests/test_against_usda.py +60 -0
  52. bestpred-0.2.1/tests/test_api.py +78 -0
  53. bestpred-0.2.1/tools/agedriver.c +31 -0
  54. bestpred-0.2.1/tools/compare.py +231 -0
  55. bestpred-0.2.1/tools/driver.f90 +50 -0
  56. bestpred-0.2.1/tools/extract_tables.py +86 -0
  57. bestpred-0.2.1/tools/make_fixtures.py +43 -0
  58. bestpred-0.2.1/tools/reference.sh +23 -0
  59. bestpred-0.2.1/uv.lock +1588 -0
  60. bestpred-0.2.1/validation/README.md +44 -0
  61. bestpred-0.2.1/validation/data/synthetic_daily.csv.gz +0 -0
  62. bestpred-0.2.1/validation/data/synthetic_params.json +950 -0
  63. bestpred-0.2.1/validation/herd_test.py +152 -0
  64. bestpred-0.2.1/validation/make_synthetic.py +114 -0
  65. bestpred-0.2.1/validation/results/error_by_stage.png +0 -0
  66. bestpred-0.2.1/validation/results/summary_305d.csv +13 -0
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "bestpred",
3
+ "interface": {
4
+ "displayName": "BESTPRED"
5
+ },
6
+ "plugins": [
7
+ {
8
+ "name": "bestpred",
9
+ "source": {
10
+ "source": "local",
11
+ "path": "./plugins/bestpred"
12
+ },
13
+ "policy": {
14
+ "installation": "AVAILABLE",
15
+ "authentication": "ON_INSTALL"
16
+ },
17
+ "category": "Education & Research"
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "bestpred",
3
+ "description": "USDA's best prediction of dairy lactation yields, for Claude Code",
4
+ "owner": {
5
+ "name": "Pádraig Lucey"
6
+ },
7
+ "plugins": [
8
+ {
9
+ "name": "bestpred",
10
+ "source": "./plugins/bestpred",
11
+ "description": "305-day and mature-equivalent milk, reliability and persistency from test days, by USDA's best prediction method"
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,53 @@
1
+ # On a GitHub release (or run by hand): test, build bestpred and bestpred-mcp, and publish each to PyPI by trusted
2
+ # publishing (no token stored here). PyPI allows one pending publisher per repository, workflow and environment, so each
3
+ # package publishes from its own environment: "pypi" for bestpred, "pypi-mcp" for bestpred-mcp.
4
+ name: release
5
+
6
+ on:
7
+ release:
8
+ types: [published]
9
+ workflow_dispatch:
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: astral-sh/setup-uv@v6
17
+ - run: uv sync --all-packages && uv pip install pytest anyio
18
+ - run: uv run --no-sync pytest -q && uv run --no-sync pytest -q mcp/tests
19
+ - run: uv build --package bestpred -o dist/bestpred && uv build --package bestpred-mcp -o dist/bestpred-mcp
20
+ - uses: actions/upload-artifact@v4
21
+ with:
22
+ name: dist
23
+ path: dist/
24
+
25
+ publish-bestpred:
26
+ needs: build
27
+ runs-on: ubuntu-latest
28
+ environment: pypi
29
+ permissions:
30
+ id-token: write
31
+ steps:
32
+ - uses: actions/download-artifact@v4
33
+ with:
34
+ name: dist
35
+ path: dist/
36
+ - uses: pypa/gh-action-pypi-publish@release/v1
37
+ with:
38
+ packages-dir: dist/bestpred/
39
+
40
+ publish-bestpred-mcp:
41
+ needs: publish-bestpred
42
+ runs-on: ubuntu-latest
43
+ environment: pypi-mcp
44
+ permissions:
45
+ id-token: write
46
+ steps:
47
+ - uses: actions/download-artifact@v4
48
+ with:
49
+ name: dist
50
+ path: dist/
51
+ - uses: pypa/gh-action-pypi-publish@release/v1
52
+ with:
53
+ packages-dir: dist/bestpred-mcp/
@@ -0,0 +1,7 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .pytest_cache/
5
+ dist/
6
+ build/
7
+ *.egg-info/
@@ -0,0 +1,37 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software, please cite it as below, and cite the original BESTPRED (Cole and VanRaden, 2008)."
3
+ type: software
4
+ title: "bestpred: USDA best prediction of dairy lactation yields, ported to Python"
5
+ abstract: >-
6
+ Python translation of USDA-AGIL's BESTPRED 2.0rc7. Takes a cow's test days and returns 305-day, 365-day and
7
+ to-date milk, fat, protein and SCS (actual and mature equivalent), persistency, reliabilities and the daily
8
+ lactation curve. Checked against the original Fortran to 1e-9 relative on every output.
9
+ authors:
10
+ - family-names: Lucey
11
+ given-names: Pádraig
12
+ orcid: "https://orcid.org/0000-0003-3885-2439"
13
+ version: 0.2.1
14
+ doi: 10.5281/zenodo.23425506
15
+ date-released: 2026-10-18
16
+ license: Apache-2.0
17
+ repository-code: "https://github.com/padge01/bestpred-python"
18
+ keywords:
19
+ - dairy
20
+ - lactation
21
+ - best prediction
22
+ - DHI
23
+ - animal science
24
+ references:
25
+ - type: manual
26
+ title: "A Manual for Use of BESTPRED: A Program for Estimation of Lactation Yield and Persistency Using Best Prediction"
27
+ authors:
28
+ - family-names: Cole
29
+ given-names: John B.
30
+ - family-names: VanRaden
31
+ given-names: Paul M.
32
+ year: 2008
33
+ institution:
34
+ name: "USDA Agricultural Research Service, Animal Genomics and Improvement Laboratory"
35
+ - type: software
36
+ title: "BESTPRED 2.0rc7"
37
+ url: "https://github.com/wintermind/bestpred"
bestpred-0.2.1/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
bestpred-0.2.1/NOTICE ADDED
@@ -0,0 +1,65 @@
1
+ bestpred (Python)
2
+
3
+ This package is a port to Python of BESTPRED 2.0rc7, the best prediction programs of the USDA Agricultural
4
+ Research Service, Animal Genomics and Improvement Laboratory (Paul M. VanRaden and John B. Cole), from
5
+ https://github.com/wintermind/bestpred (commit 23e7fe84280f41c6a37c24dc410911a0b7c2080e). Its coefficient tables
6
+ (src/bestpred/data/tables.json and adjust.scs) are copied from that source.
7
+
8
+ It is not a product of, affiliated with, or endorsed by USDA. Changes from the original: translated from Fortran 90
9
+ and C to Python and NumPy; the screen plots, log files and BLUP output files are left out.
10
+
11
+ As the original's notice requires, its notice follows in full.
12
+
13
+ ======================================================================================================================
14
+ LICENSE (from the original)
15
+ ======================================================================================================================
16
+
17
+ The best prediction programs and source code weren produced by employees of
18
+ the United States government in the course of their official duties, and are
19
+ in the public domain.
20
+
21
+ ======================================================================================================================
22
+ README (from the original)
23
+ ======================================================================================================================
24
+
25
+ Cole, J. B., and P. M. VanRaden. 2008. A Manual for Use of BESTPRED: A Program
26
+ for Estimation of Lactation Yield and Persistency Using Best Prediction.
27
+
28
+ U.S. Department of Agriculture, Agricultural Research Service, Animal Genomics
29
+ and Improvement Laboratory.
30
+
31
+ This manual describes how to obtain, install, and run a Fortran 90 program for
32
+ calculating lactation yields and persistencies using best prediction
33
+ methodology. Chapters also present the theory underlying best prediction,
34
+ describe the methodology used to calculate covariances among pairs of days in
35
+ milk for any combination of traits, and discuss implementation details important
36
+ to anyone considering modifications to the programs. The purpose is to provide
37
+ both background material and step-by-step instructions for successful use of the
38
+ software.
39
+
40
+ The authors of this software do not make any warranty, express or implied, or
41
+ assume any liability or responsibility for the accuracy, completeness, or
42
+ usefulness of any information, apparatus, product, or process disclosed, or
43
+ represent that its use would not infringe privately-owned rights. Reference
44
+ herein to any specific commercial products, processes, or services by trade
45
+ name, trademark, manufacturer, or otherwise, does not necessarily constitute
46
+ or imply its endorsement, recommendation, or favoring by the United States
47
+ Government or the author. The views and opinions of authors expressed herein
48
+ do not necessarily state or reflect those of the United States Government
49
+ and shall not be used for advertising or product endorsement purposes.
50
+
51
+ Permission to use, copy, modify, and distribute this software for any purpose
52
+ without fee is hereby granted, provided that this entire notice is included
53
+ in all copies of any software which is or includes a copy or modification of
54
+ this software and in all copies of the supporting documentation for such
55
+ software.
56
+
57
+ 7-Zip is copyrighted 2007 by Igor Pavlov. Absoft is a registered trademark and
58
+ Absoft Fortran v10 is a trademark of Absoft Corporation, Rochester Hills, MI.
59
+ DB2 is a registered trademark of International Business Machines Corporation,
60
+ Armonk, NY. G95 is copyrighted 2004 by the Free Software Foundation, Boston, MA.
61
+ GCC, the GNU Compiler Collection, is copyrighted 2007 by the Free Software
62
+ Foundation, Boston, MA. Kubuntu is a registered trademark of Canonical Ltd.
63
+ Linux is copyrighted 2007 by Linus Torvalds. Microsoft is a registered trademark
64
+ and Windows is a trademark of Microsoft Corporation, Redmond, WA. Red Hat and
65
+ Red Hat Enterprise Linux are registered trademarks of Red Hat, Inc., Raleigh, NC.
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.5
2
+ Name: bestpred
3
+ Version: 0.2.1
4
+ Summary: USDA's best prediction of dairy lactation yields and persistency (BESTPRED 2.0rc7), ported to Python and checked against the original.
5
+ Project-URL: Homepage, https://github.com/padge01/bestpred-python
6
+ Project-URL: Original, https://github.com/wintermind/bestpred
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ License-File: NOTICE
10
+ Keywords: animal science,best prediction,dairy,dhi,lactation,usda
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Scientific/Engineering
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: numpy>=1.24
16
+ Provides-Extra: test
17
+ Requires-Dist: pytest; extra == 'test'
18
+ Provides-Extra: validation
19
+ Requires-Dist: pandas; extra == 'validation'
20
+ Description-Content-Type: text/markdown
21
+
22
+ # bestpred
23
+
24
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.23425506.svg)](https://doi.org/10.5281/zenodo.23425506)
25
+
26
+ Python translation of the USDA best prediction of lactation yields (BESTPRED).
27
+
28
+ Takes a cow's test days and returns 305-day, 365-day and to-date milk, fat, protein and SCS (actual and mature
29
+ equivalent), persistency, reliabilities, the data collection rating, and the cow's daily lactation curve.
30
+
31
+ Best prediction is the method USDA has used for official lactation records since 1998 (VanRaden, 1997; Cole et al.,
32
+ 2009). The original is USDA-AGIL's public-domain Fortran and C,
33
+ [BESTPRED 2.0rc7](https://github.com/wintermind/bestpred). This port gives the same numbers.
34
+
35
+ ## How it was checked
36
+
37
+ USDA's code was compiled from source, and both programs ran on the same random lactations: 1 to 15 test days,
38
+ duplicate tests, LER segments, 3X milking, owner-sampler and unusable supervision codes, missing components, all six
39
+ breeds, parities 1 to 9, herd means present and absent.
40
+
41
+ - **Every output and the full daily curves agree to 1e-9 relative** (typically 1e-12) for 300 lactations under each
42
+ of 13 settings: the default, single-trait, multi-trait with SCS, the three 3X options, 365-day and 330-day
43
+ lactations, linear, region, calving-season and region-by-season curves, and kilograms.
44
+ - **Mature-equivalent factors agree bit for bit** (aiplage and adjscs) on 43,200 combinations of breed, state, year,
45
+ month, parity, previous days open and age base.
46
+ - **USDA's example record** gives the same results line as their program, character for character.
47
+
48
+ `tests/` holds fixtures from that reference build, so `pytest` runs without a Fortran compiler. To rebuild the
49
+ reference and run the full comparison yourself (needs gcc and gfortran):
50
+
51
+ ```bash
52
+ tools/reference.sh /tmp/bestpred-ref
53
+ python tools/compare.py --driver /tmp/bestpred-ref/driver --n 300
54
+ ```
55
+
56
+ ## Tested against daily meter weights
57
+
58
+ 600 synthetic lactations shaped like a California Holstein herd. 305-day yield projected from test days drawn
59
+ monthly from daily weights, compared with the true daily total.
60
+
61
+ ![Mean absolute error of the 305-day projection by tests up to 60, 120 and 200 days in milk and all tests: best prediction 7.9, 5.4, 3.0, 1.8%; herd-curve ratio 8.5, 6.0, 3.6, 2.0%; test intervals plus herd curve 8.3, 5.5, 3.0, 1.8%](validation/results/error_by_stage.png)
62
+
63
+ Method, data, table and scripts: [validation/](validation/).
64
+
65
+ ## For AI agents
66
+
67
+ An agent can't work out a lactation record in its head, but it can run this. `bestpred-mcp` puts best prediction
68
+ behind four tools any agent can call (Claude, ChatGPT and Codex, Cursor, VS Code, Gemini CLI):
69
+
70
+ ```bash
71
+ uvx bestpred-mcp
72
+ ```
73
+
74
+ - **Claude Code:** `claude mcp add bestpred -- uvx bestpred-mcp`, or the plugin with its skill:
75
+ `claude plugin marketplace add padge01/bestpred-python` then `claude plugin install bestpred@bestpred`
76
+ - **Claude Desktop, Cursor, Gemini CLI:** `{ "mcpServers": { "bestpred": { "command": "uvx", "args": ["bestpred-mcp"] } } }`
77
+ - **Codex:** the plugin with its skill: `codex plugin marketplace add padge01/bestpred-python`, then install BESTPRED
78
+ from the app's Plugins tab (or `codex plugin add bestpred@bestpred`); or the server alone in `~/.codex/config.toml`:
79
+ `[mcp_servers.bestpred]` with `command = "uvx"` and `args = ["bestpred-mcp"]`
80
+
81
+ Then: "Work out 305-day milk for every cow in `tests.csv`." The tools take a herd's test-day export (DHI or DairyComp
82
+ columns), one cow's test days, a cow's expected daily curve, and USDA's age factors. Details in [mcp/](mcp/).
83
+
84
+ ## Install
85
+
86
+ ```bash
87
+ pip install bestpred
88
+ ```
89
+
90
+ Python 3.10 or later, NumPy only.
91
+
92
+ ## Use it
93
+
94
+ From Python, with test days as a DHI test or a parlor export gives them:
95
+
96
+ ```python
97
+ from bestpred import TestDay, bestpred
98
+
99
+ tests = [
100
+ TestDay(dim=12, milk=78.0, fat=4.4, protein=3.2, scs=3.1),
101
+ TestDay(dim=43, milk=96.5, fat=3.7, protein=2.9, scs=2.0),
102
+ TestDay(dim=71, milk=99.0, fat=3.5, protein=3.0, scs=1.8),
103
+ TestDay(dim=104, milk=94.2, fat=3.6, protein=3.1, scs=2.4),
104
+ ]
105
+ res = bestpred(tests, herdavg=(26000, 980, 800, 2.8), agefac=(1, 1, 1, 1), cowid='H', parity=2,
106
+ fresh='20260301')
107
+
108
+ res.yields('actual')['milk']['305'] # projected 305-d milk, lb
109
+ res.rel_yield[0] # reliability of that projection
110
+ res.persistency[0] # milk persistency (SD units, 0 is average)
111
+ res.daily_herd[1, 0] + res.daily_bp[1, 0] # the cow's predicted daily milk, days 0..365 (slot 0 unused)
112
+ ```
113
+
114
+ | Argument | Meaning |
115
+ |---|---|
116
+ | `herdavg` | Herd 305-d mature-equivalent milk, fat, protein (lb or kg) and mean SCS. 0 for unknown: the breed mean is used. |
117
+ | `agefac` | Factors that turn actual into mature-equivalent yield. `bestpred.age_factors()` computes USDA's; `(1, 1, 1, 1)` leaves yields as they are. |
118
+ | `cowid` | Only the first letter matters: breed A, B, G, H, J or M. |
119
+ | `TestDay.super` | Supervision code: 1 supervised, 2 owner-sampler, 0 or 4 unusable, and so on as in Format 4. |
120
+ | `times_milked`, `times_weighed`, `times_sampled` | Milkings that day and how many were weighed or sampled (AM-PM testing). |
121
+ | `mrd` | Days averaged into a test (1 for a normal test day; more for LER). |
122
+
123
+ `bestpred.Settings` holds the options from USDA's `bestpred.par`: single- or multi-trait, the 3X adjustment, lactation
124
+ length, which standard curves, and pounds or kilograms.
125
+
126
+ USDA Format 4 records run straight from the command line and give the program's `results_v2.dcr` lines, or JSON:
127
+
128
+ ```bash
129
+ bestpred records.dat
130
+ bestpred records.dat --json
131
+ ```
132
+
133
+ ## Things the port keeps from the original
134
+
135
+ The aim is the same numbers as USDA's program, so behavior that changes results is kept and marked `sic` in the code.
136
+ Worth knowing:
137
+
138
+ - When a herd mean is missing, the breed mean is taken from the 1995 table for first lactations and the 2000 table
139
+ for later ones (the year-group index is the parity group).
140
+ - The partial-record 3X factor compares the last test against `end1` (capped at 305 days) instead of `end2`.
141
+ - Duplicate test days are dropped (the first is kept); overlapping LER segments are shortened.
142
+ - USDA's command-line program replaces a record's length with its last test day (`--keep-length` turns that off
143
+ here), and its parameter reader quietly resets the calving-season curves (C, T, D, U) to linear. Programs that call
144
+ the routine directly can use them, and so can this package.
145
+
146
+ Found while porting:
147
+
148
+ - With bounds checking on (`-fcheck=all`), the original stops when the last usable test day has no usable yield: a
149
+ plotting loop reads one element before an array. USDA's production build has no bounds checking, and the results
150
+ don't use that value.
151
+ - An SCS age adjustment can land exactly on .5. Compilers that fuse multiply-adds (by default on Apple silicon)
152
+ round it the other way from plain IEEE double arithmetic. This port gives the plain result, as on x86.
153
+
154
+ ## References
155
+
156
+ - VanRaden, P.M. 1997. Lactation yields and accuracies computed from test day yields and (co)variances by best
157
+ prediction. J. Dairy Sci. 80:3015–3022.
158
+ - Cole, J.B., D.J. Null, and P.M. VanRaden. 2009. Best prediction of yields for long lactations. J. Dairy Sci.
159
+ 92:1796–1810.
160
+ - Cole, J.B., and P.M. VanRaden. 2008. A manual for use of BESTPRED: a program for estimation of lactation yield and
161
+ persistency using best prediction. USDA-ARS-AGIL.
162
+
163
+ ## License
164
+
165
+ The port is Apache-2.0. The original is public domain, written by employees of the US government. Its notice is
166
+ reproduced in full in [NOTICE](NOTICE), as it asks. This package is not a product of, or endorsed by, USDA.
167
+
168
+ Ported by Pádraig Lucey ([dairydatascience.com](https://dairydatascience.com)).