RUFAS.biophysical.animal.animal_genetics.animal_genetics module#

RUFAS.biophysical.animal.animal_genetics.animal_genetics.BASE_CHANGE_LOOKUP_TABLE = {datetime.date(2005, 1, 1): 0, datetime.date(2010, 1, 1): 132, datetime.date(2014, 12, 1): 184, datetime.date(2020, 4, 1): 231}#

The only breed currently supported in this module is Holsteins.

class RUFAS.biophysical.animal.animal_genetics.animal_genetics.AnimalGenetics#

Bases: object

Attributes#

net_meritdict[str, dict[str, dict[str, float]]], default {}

Lookup table of Net Merit averages and standard deviations (lifetime USD), separated by breed and time.

top_semendict[str, dict[str, float]], default {}

Lookup table of Top Listing Semen estimated Predicted Transmitting Ability, separated by breed.

year_month_of_first_net_merit_value: str

The earliest net merit value available in year and month (YYYY-MM) format.

year_month_of_last_net_merit_value: str

The latest net merit value available in year and month (YYYY-MM) format.

year_month_of_first_top_semen_value: str

The earliest top semen value available in year and month (YYYY-MM) format.

year_month_of_last_top_semen_value: str

The latest top semen value available in year and month (YYYY-MM) format.

net_merit: dict[str, dict[str, dict[str, float]]] = {}#
top_semen: dict[str, dict[str, float]] = {}#
year_month_of_first_net_merit_value: str#
year_month_of_last_net_merit_value: str#
year_month_of_first_top_semen_value: str#
year_month_of_last_top_semen_value: str#
classmethod initialize_class_variables() None#

This method initializes the class variables for net_merit and top_semen.

static net_merit_base_change(original_net_merit: dict[str, dict[str, dict[str, float]]]) dict[str, dict[str, dict[str, float]]]#

This function performs the base change for the net merit data.

Parameters#

original_net_merit: dict[str, dict[str, dict[str, float]]]

The original net merit data, $USD.

Returns#

dict[str, dict[str, dict[str, float]]]

The net merit data after base change, $USD.

Notes#

The CDCB reevaluates and adjusts the net merit value to keep it within a reasonable range by changing the baseline every five years. Therefore, to realign the past data with the current values, we first change every value to match the oldest value, and shift all data back into the reasonable range.

References#

https://aipl.arsusda.gov/reference/base2010.htm

https://aipl.arsusda.gov/reference/base2014.htm

https://uscdcb.com/wp-content/uploads/2020/02/Norman-et-al-Genetic-Base-Change-April-2020-FINAL_new.pdf

static net_merit_fill_gap(original_net_merit: dict[str, dict[str, dict[str, float]]]) dict[str, dict[str, dict[str, float]]]#

The input net merit data only has three entries per year, this function fills in the gap in between entries by using linear approximation.

Parameters#

original_net_merit: dict[str, dict[str, dict[str, float]]]

The original net merit data, $USD.

Returns#

dict[str, dict[str, dict[str, float]]]

The net merit data after filling the gap in between entries, $USD.

static assign_net_merit_value_to_animals_entering_herd(birth_date: str, breed: Breed) float#

This function calculates the net merit value for animals entering the herd, either during initialization or for animals bought during the simulation.

Parameters#

birth_date: str

The birthdate of the animal in the format “YYYY-MM-DD”.

breed: str

The breed of the animal.

Returns#

float

The net merit value of the animal, $USD.

Notes#

With the birthdate and the breed of the animal, this function first looks up the mean and standard deviation of the net merit value, then generates a random value from the distribution as the net merit value.

static assign_net_merit_value_to_newborn_calf(time: RufasTime, breed: Breed, dam_net_merit_value: float) float#

This function calculates the net merit value for the newborn calves.

Parameters#

time: RufasTime

The RufasTime instance that contains the birthdate of the newborn calf. This function will be called on the day of birth for the newborn calf; therefore, the current date will be the birthdate of the calf.

breed: str

The breed of the newborn calf.

dam_net_merit_value: float

The net merit value of the dam (mother cow).

Returns#

float

The net merit value of the newborn calf, $USD.

Notes#

With the birthdate and the breed of the animal, this function first looks up the top listing semen value. The mean for the net merit value of the newborn can then be calculated as the sum of the top listing semen value and the net merit value of the dam. The standard deviation is the square root of the Mendelian sampling variance, which is simply half of the population variance.

static _clamp_birth_year_month_in_data_range(birth_year_month: str, is_for_net_merit: bool) str#

Checks if the birth month of an animal is available in either the net merit or top semen data, and clamps the month to the earliest or latest date if the date is not available.

Parameters#

birth_year_monthstr

The year and month of an animal’s birth, in the format “YYYY-MM”.

is_for_net_meritbool

True if the birth month is being checked against the net merit data, False if it is being checked against the top semen data.

Returns#

str

The birth month of the animal, clamped between the earliest and latest dates available.