Skip to content

Calf ration implementation#2043

Open
JoeWaddell wants to merge 41 commits intodevfrom
calf_ration_implement
Open

Calf ration implementation#2043
JoeWaddell wants to merge 41 commits intodevfrom
calf_ration_implement

Conversation

@JoeWaddell
Copy link
Collaborator

@JoeWaddell JoeWaddell commented Oct 23, 2024

Context

Issue(s) closed by this pull request: more completely closes #1137
and #1337 , also should close #2517 and #2016 for calves

What

Adds logic to re-implement previously developed calf ration formulation and requirement calculations.

This will work for both the default user defined ration behavior, and automated "modes", but note that neither utilize the minimize method, like we do for all other animal classes. A) The user defined method gets the pen's average dry matter intake requirement and then applies the percentages in the feed input file. B) The automated version will use the ration as formulated by the equations now housed in calc_intake in CalfRationManager

Why

Calves were backburnered for a while, and had been restricted to using only precisely two inputs, and would crash if users tried selecting other feed IDs.

More context and associated problems

This will require thought around what to do with the "milk_type" input in the animal input JSON, which could be deprecated (see comments by Kristan and Joe)

Default scenario values give only a rough total of 1kg per animal in the calf pen, whereas the diet we hardcoded on main is 3kg. This needs evaluation as to whether A) I've made a mistake in this translation of the old methods to current inputs, or if we're B) intentionally 3X overfeeding by default, or C) the methods themselves need refinement.

Related: given that these are process based methods independent of NASEM/NRC, consideration should be given to how the user may want to handle calf ration formulation independent of the user-defined ration formulation for other animal types, e.g. give some pre-forumlated ration for calves, but use automated formulation methods for all other groups. This level of granularity may not be necessary, but should get input from other SMEs involved in calf nutrition.

How

Iterates over all calves in a calf pen, calculates their intake, then sums those and updates pen attribute for ration_per_animal to reflect total divided by the number of animals in the pen.

Test plan

Currently lacks unit tests for new methods.

Needs more testing with multiple, more complex calf rations.

See "More context and associated problems" and section, as this needs evaluation to see if we're underfeeding with these new methods, and how temperature will/can affect the equations used here.

You can see the basic output using the following graph filter:

{
      "type": "plot",
      "filters": [
        ".*ration_per_animal_for_pen_0_CALF"
      ],
      "title": "Ration per animal for pen 0",
      "variables": [".*"],
      "omit_legend_prefix": true
}

@JoeWaddell JoeWaddell self-assigned this Oct 23, 2024
@JoeWaddell JoeWaddell added the Animal Involves the Animal Module label Oct 23, 2024
@github-actions
Copy link
Contributor

Current Coverage: 95%

Mypy errors on calf_ration_implement branch: 3577
Mypy errors on dev branch: 3576
1 more errors on calf_ration_implement branch

@github-actions
Copy link
Contributor

🚨 Please update the changelog. This PR cannot be merged until changelog.md is updated to reflect the changes.

Updated the order of the code to make it more streamlined.
Copy link
Collaborator

@tomhuhh tomhuhh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job Joe! I did not spot major issues with the code. I noticed that in the calculation of the intake of starters, the original code did not consider the dry matter content of the starter while it considered the dry matter content of whole milk and milk replacer. Also, I could not find the scientific documentation for calf ration calculations on Basecamp so I cannot verify the equation. A quick search on Google with these key words and the parameters also did not result in the information I was looking for. I would like to learn what your and others' thoughts are on whether or not to consider the dry matter content of starters. Thanks!

@tomhuhh
Copy link
Collaborator

tomhuhh commented Nov 11, 2024

Adding a screenshot of the code that I was referring to:

Screenshot 2024-11-11 at 9 24 59 AM

@tomhuhh
Copy link
Collaborator

tomhuhh commented Nov 11, 2024

Also, I would like to document that with the current version and the default input files, if I set the user defined ration to be true, the resulted daily dry matter intake per day is 84.4% to 102.2% of the previously fixed dry matter intake estimates (6 kg/head/d).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this If-else statement eliminate the need for the user input for "milk_type"? If so, can we delete it while keeping the model backwards compatible for input files that have this input? Or, maybe we just make an issue about user input adjustments that need to be made?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct! The intent here was that it could streamline the feed inputs a little bit...with the user simply selecting the feed IDs for calves as they do for the other animal classes, since it's currently a little redundant.

We could still keep this input, but we'd have to think through the logic of when (or if) it should ever override the user defined feeds.

If we do deprecate it: to maintain backwards compatibility (especially with FARM ES) what I thought is that we could keep the option in the metadata, and simply not let it get to the codebase itself. I think we could/should capture it and flag a warning that the input has been deprecated, and the user should specify the feeds in the feed input JSON (we may want to think about a process for any input field deprecation we do in the future).

@PooyaHekmati PooyaHekmati deleted the calf_ration_implement branch June 19, 2025 03:50
@PooyaHekmati PooyaHekmati restored the calf_ration_implement branch June 19, 2025 03:56
@PooyaHekmati PooyaHekmati reopened this Jun 19, 2025
@github-actions
Copy link
Contributor

Current Coverage: 89%

Mypy errors on calf_ration_implement branch: 3263
Mypy errors on dev branch: 3262
1 more errors on calf_ration_implement branch

@github-actions
Copy link
Contributor

🚨 Please update the changelog. This PR cannot be merged until changelog.md is updated.

@github-actions
Copy link
Contributor

Current Coverage: %

Mypy errors on calf_ration_implement branch: 3216
Mypy errors on dev branch: 3210
6 more errors on calf_ration_implement branch

@github-actions
Copy link
Contributor

🚨 Please update the changelog. This PR cannot be merged until changelog.md is updated.
🚨 Flake8 linting errors were found. Please fix the linting issues.
🚨 Some tests have failed.

@github-actions
Copy link
Contributor

Current Coverage: %

Mypy errors on calf_ration_implement branch: 3216
Mypy errors on dev branch: 3210
6 more errors on calf_ration_implement branch

@github-actions
Copy link
Contributor

🚨 Please update the changelog. This PR cannot be merged until changelog.md is updated.
🚨 Flake8 linting errors were found. Please fix the linting issues.
🚨 Some tests have failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Animal Involves the Animal Module

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Animal][Ration] Replace Dummy Values for Calf Calcium and Phosphorus Requirement Calculation Refactoring Calf Ration

4 participants