Skip to content

[Animal] Adds farm-specific genetic distribution inputs to herd_information - #3257

Open
matthew7838 wants to merge 17 commits into
devfrom
genetic-input-expansion
Open

matthew7838 wants to merge 17 commits into
devfrom
genetic-input-expansion

Conversation

@matthew7838

@matthew7838 matthew7838 commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Adds the standard deviations and correlations of the genetic distributions used by the Genetics submodule as optional, farm-specific animal inputs. When they are omitted the CDCB national-average values that were previously hard-coded are used, so existing input files run unchanged.

Context

Issue(s) closed by this pull request: closes #2512

Follows up on the Genetics implementation in #2734.

What

  • Adds nine optional inputs to the herd_information section of the animal input, each defaulting to the CDCB national average in default.json:
    • tbv_fat_std (25.8 kg), tbv_protein_std (13.4 kg), tbv_correlation (0.59)
    • permanent_environment_fat_std (38.8 kg), permanent_environment_protein_std (20.1 kg), permanent_environment_correlation (0.95)
    • temporary_environment_fat_std (64.5 kg), temporary_environment_protein_std (33.4 kg), temporary_environment_correlation (0.78)
  • Adds the matching AnimalConfig attributes (class defaults = CDCB values) and reads them in AnimalConfig.initialize_animal_config().
  • Genetics now draws TBV, permanent environmental effect, and temporary environmental effect values from the AnimalConfig distribution parameters instead of the module-level constants, which are removed. The newborn-calf TBV spread and the EBV estimation noise use the same AnimalConfig TBV standard deviations.
  • Adds the new keys (at their default values) to example_freestall_animal.json and example_open_lot_animal.json.
  • Updates test_animal_genetics.py (parametrized default vs. farm-specific cases for TBV, E_permanent, E_temporary, newborn-calf TBV, and EBV noise) and test_animal_config.py (shared herd_information fixture plus a test that the nine inputs are read).

Why

The TBV, permanent environmental, and temporary environmental variances were hard-coded to the CDCB national averages, so farms with their own genetic evaluation could not use farm-specific values (#2512). The mean phenotype (μ_phenotype) from the same issue is already a user-supplied input through the animal_mean_phenotype CSV blob (by birth year), so no new input was added for it; the alternative of deriving it from annual_milk_yield and the milk fat/protein percentages raised in the issue discussion is left for the Animal Module discussion noted there.

How

  • The inputs are expressed as standard deviations (kg) and correlations, matching the existing *_std animal inputs and the Genetics implementation (the variance is the square of the standard deviation). Each bivariate (fat, protein) distribution needs both standard deviations and its correlation, so the correlations are exposed alongside the variances.
  • The keys live directly in herd_information next to simulate_genetics rather than in a nested object because only string/number/bool properties are auto-filled from their metadata default when missing; a missing nested object would fail validation for existing input files.
  • Standard deviations are bounded at minimum: 0 and correlations at [-1, 1] in the metadata; out-of-range values are repaired to the default with the usual validator warning.
  • Note (unchanged in this PR): Genetics._calculate_ebv_values() scales the EBV noise by the TBV standard deviation rather than its variance. It now reads that value from AnimalConfig, but the formula itself was left as-is so default-input outputs are identical.

Test plan

  • Full unit test suite: 7134 passed. Black, flake8, and mypy clean on the changed files.
  • Real InputManager load of the freestall e2e inputs with a scratch animal file: with the nine keys removed, the pool and AnimalConfig receive the CDCB defaults (validator logs "data fixed ... from None to 25.8" etc.); with custom values they are passed through; with tbv_fat_std = -3 and tbv_correlation = 1.5 both are repaired to the defaults with warnings.

Input Changes

  • Modified RUFAS/input/metadata/properties/default.json: nine new optional number properties under animal_properties.herd_information (listed above), each with a CDCB default.
  • Modified input/data/animal/example_freestall_animal.json and input/data/animal/example_open_lot_animal.json: the nine keys added at their default values.
  • Existing animal input files without the keys keep working and use the CDCB defaults.

Output Changes

  • N/A

Filter

matthew7838 and others added 3 commits September 8, 2026 23:33
…formation

Exposes the CDCB national-average standard deviations and correlations of
the TBV, permanent environmental, and temporary environmental distributions
as optional animal inputs (herd_information) that default to the CDCB values
when omitted. Genetics reads them from AnimalConfig instead of module
constants.
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Current Coverage: 99%

Mypy errors on genetic-input-expansion branch: 1164
Mypy errors on dev branch: 1164
No difference in error counts

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🚨 Please update the changelog. This PR cannot be merged until changelog_WIP.md is updated.
🚨 Unauthorized changes detected in protected files. Please remove these changes if they are not intended.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Current Coverage: 99%

Mypy errors on genetic-input-expansion branch: 1164
Mypy errors on dev branch: 1164
No difference in error counts

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

🚨 Unauthorized changes detected in protected files. Please remove these changes if they are not intended.

@matthew7838 matthew7838 changed the title Adds farm-specific genetic distribution inputs to herd_information [Animal] Adds farm-specific genetic distribution inputs to herd_information Sep 9, 2026

@allisterakun allisterakun left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Very straight-forward changes

Comment thread input/data/animal/example_open_lot_animal.json
@matthew7838
matthew7838 requested review from YijingGong and tomhuhh and removed request for ew3361zh September 10, 2026 04:41
@github-actions

Copy link
Copy Markdown
Contributor

Current Coverage: 99%

Mypy errors on genetic-input-expansion branch: 1164
Mypy errors on dev branch: 1164
No difference in error counts

@github-actions

Copy link
Copy Markdown
Contributor

🚨 Unauthorized changes detected in protected files. Please remove these changes if they are not intended.

@github-actions

Copy link
Copy Markdown
Contributor

Current Coverage: 99%

Mypy errors on genetic-input-expansion branch: 1164
Mypy errors on dev branch: 1164
No difference in error counts

@github-actions

Copy link
Copy Markdown
Contributor

🚨 Unauthorized changes detected in protected files. Please remove these changes if they are not intended.

@github-actions

Copy link
Copy Markdown
Contributor

Current Coverage: 99%

Mypy errors on genetic-input-expansion branch: 1164
Mypy errors on dev branch: 1164
No difference in error counts

@github-actions

Copy link
Copy Markdown
Contributor

🚨 Unauthorized changes detected in protected files. Please remove these changes if they are not intended.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Animal] Custom Farm-Specific Genetics Inputs

2 participants