RUFAS.routines.animal.life_cycle.heiferII module#
- RUFAS.routines.animal.life_cycle.heiferII.random() x in the interval [0, 1). #
- class RUFAS.routines.animal.life_cycle.heiferII.HeiferII(args)#
Bases:
HeiferI
This class represents the attributes and activities that are characteristic of heifers in the second stage of their life cycle.
Class Attributes#
- statscollections.defaultdict[str, int]
A dictionary that stores statistics about all the heiferIIs instances that have been created. Currently, the following statistics are being tracked: - num_ai_performed: The number of times AI was performed across all heiferIIs. - num_successful_conceptions: The number of successful conceptions out of all AI performed. - num_ai_performed_in_ED: The number of times AI was performed in the ED protocol. - num_successful_conceptions_in_ED: The number of successful conceptions out of all AI performed in the ED. - num_ai_performed_in_TAI: The number of times AI was performed in the TAI protocol. - num_successful_conceptions_in_TAI: The number of successful conceptions out of all AI performed in the TAI. - num_ai_performed_in_SynchED: The number of times AI was performed in the SynchED protocol. - num_successful_conceptions_in_SynchED: The number of successful conceptions out of all AI performed in the SynchED.
- stats = {}#
- __init__(args)#
- Description:
- initialize the heifer in this stage from the first stage and
initialize or assigns the repro program parameters
- Input:
args.id: id of the animal args.breed: breed of the animal args.birth_date: the date of the simulation when the calf was born args.daysBorn: age of the animal args.repro_program: reproduction program used in heifer,
three of them: ED, TAI, and synch-ED programs
- args.repro_sub_protocol: string indicating the sub-type of the reproduction protocol being used. Can be
“5dCG2P”, “5dCGP”, “2P”, “CP” or “N/A”.
- args.tai_method_h: timed-AI protocols used for
reproduction programs, three of them: 5dCG2P, 5dCGP, and user-defined
- args.synch_ed_method_h: synch ed protocols used for
reproduction programs, two of them: 2P and CP
(optional: include the following to assign animal information) args.birth_weight: the birth weight of the animal args.body_weight: current body weight of the animal args.wean_weight: the wean weight of the animal args.mature_body_weight: the mature body weight of the animal args.events: events of the animal args.estrus_count : number of estrus during ED program args.estrus_day: the age when the heifer is estrus in ED program args.tai_program_start_day_h: start day for heifers in TAI program args.synch_ed_program_start_day_h: start day for heifers in synch_ED program args.synch_ed_estrus_day: the age when the heifer is estrus in synch_ED program args.synch_ed_stop_day: the age the the synch protocol stop for this round args.conception_rate: conception rate associated with repro programs and protocols args.ai_day: the age of animal for scheduled AI args.abortion_day: the age of the animal when abortion happens args.days_in_preg: days science pregnancy args.gestation_length: the prejected gestation args.p_gest_for_calf
- get_bw_change()#
Calculates the body weight change for a heifer, depending on if she is pregnant or not. If the gestation_length of the animal is equal to its days_in_preg, the difference is set to 1 (otherwise results in a division by 0 error).
Returns: the daily body weight change for a heifer
- init_values(args)#
Initialize repro program values
- assign_heiferII_values(args)#
Assign the repro program with given vales
- get_heiferII_values()#
Get current information from the heiferII
- set_nutrient_rqmts(temperature: float, animal_grouping_scenario, nutrient_conc: Dict[str, float] = {}, metabolizable_energy: float = 15.625, previous_DMI: float = 10.0) None #
Calculates this heiferII’s nutrient requirements.
- calc_manure_excretion(methane_model: str, nutrient_amount: Dict[str, float], nutrient_conc: Dict[str, float]) None #
Calculates and sets the manure excretion components.
Parameters#
- methane_modelstr
Methane model used for methane emission calculations, including Boadi, IPCC.
- nutrient_amountDict[str, float]
Amounts of nutrients in pen ration, calculated per animal, see Notes section for units.
- nutrient_concDict[str, float]
Concentrations of nutrients in pen ration, calculated per animal, percentages.
Notes#
- nutrient_amount_units = {
“dm”: “kg/animal”, “CP”: “percent of DM”, “ADF”: “percent of DM”, “NDF”: “percent of DM”, “lignin”: “percent of DM”, “ash”: “percent of DM”, “phosphorus”: “percent of DM”, “potassium”: “percent of DM”, “N”: “percent of DM”, }
- phosphorus_rqmts(DMI: float) None #
Calculates and sets the animal’s phosphorus requirement.
Parameters#
- DMIfloat
Dry Matter Intake (kg).
- update(sim_day)#
Controls heifer’s grow with average daily gain based on user’s input until breeding start day. Here is the place to change growth rate with heifer feeding methods later when we have heifer nutrition from the ration formulation module. Breeding starts with assigned reproduction program. RufasTime to move to the 3rd stage – replacement stage determined based on gestion length and user input of replacement time. Culling for reproduction problem occur when heifer doesn’t get pregnant for a long time.
# TODO: Refactor this method. Git issue #1038.
- Returns:
cull_stage: culling for reproduction failure third_stage: move to next stage – heiferIII stage when time comes
- _simulate_estrus(start_day: int, sim_day: int, estrus_note: str, avg_estrus_cycle: float, std_estrus_cycle: float, max_cycle_length: float = inf) None #
Calculate and set the next estrus day for the animal.
Parameters#
- start_dayint
The start day plus the estrus cycle length is the day of the next estrus.
- sim_dayint
The current day of the entire simulation.
- estrus_notestr
A note that describes the reason for simulating estrus.
- avg_estrus_cyclefloat
The average estrus cycle length.
- std_estrus_cyclefloat
The standard deviation of the estrus cycle length.
- max_cycle_lengthfloat
The maximum estrus cycle length.
Returns#
None
- static _compare_randomized_rate_less_than(reference_rate: float) bool #
Compare a randomized rate to a reference rate.
Parameters#
- reference_ratefloat
The reference rate to compare to.
Returns#
- bool
True if the randomized rate is less than the reference rate, False otherwise.
- log_event(event_day: int, sim_day: int, event_note: str) None #
Log a specific event on a given day in the simulation.
Parameters#
- event_dayint
The day of the animal’s life when the event occurred.
- sim_dayint
The current day of the entire simulation.
- event_notestr
A note or description associated with the event.
- static get_avg_estrus_cycle() int #
Get the average estrus cycle length for heifers (days).
Returns#
- int
The average estrus cycle length for heifers (days).
- static get_std_estrus_cycle() float #
Get the standard deviation of the estrus cycle length for heifers (days).
Returns#
- float
The standard deviation of the estrus cycle length for heifers (days).
- static get_avg_estrus_cycle_after_pgf() int #
Get the average estrus cycle length for heifers and cows after PGF (days).
Returns#
- int
The average estrus cycle length for heifers and cows after PGF (days).
- static get_std_estrus_cycle_after_pgf() float #
Get the standard deviation of the estrus cycle length for heifers and cows after PGF (days).
Returns#
- float
The standard deviation of the estrus cycle length for heifers and cows after PGF (days).
- get_general_estrus_detection_rate() float #
Get the general estrus detection rate for heifers.
Returns#
- float
The general estrus detection rate for heifers.
- static _get_user_defined_synch_ed_estrus_detection_rate() float #
Get the user-defined estrus detection rate for heifers used in the SynchED protocol.
Returns#
- float
The user-defined estrus detection rate for heifers used in the SynchED protocol.
- static _get_default_synch_ed_estrus_detection_rate() float #
Get the default estrus detection rate for heifers used in the SynchED protocol.
Returns#
- float
The default estrus detection rate for heifers used in the SynchED protocol.
- _get_user_defined_or_default_synch_ed_estrus_detection_rate() float #
Get the estrus detection rate for heifers used in the SynchED protocol.
Returns#
- float
The estrus detection rate for heifers used in the SynchED protocol.
- get_general_conception_rate() float #
Get the general conception rate for heifers.
Returns#
- float
The general conception rate for heifers.
- static get_user_defined_tai_conception_rate() float #
Get the user-defined conception rate for heifers used in TAI protocols.
This is to contrast with the estrus conception rate used in the ED protocol.
Returns#
- float
The specific conception rate for heifers used in the TAI protocol.
- static _get_default_TAI_conception_rate() float #
Get the default conception rate for heifers used in TAI protocols.
Notes#
This is to contrast with the estrus conception rate used in the ED protocol.
Returns#
- float
The default conception rate for heifers used in the TAI protocol.
- _get_user_defined_or_default_TAI_conception_rate() float #
Get the conception rate for heifers used in TAI protocols.
This is to contrast with the estrus conception rate used in the ED protocol.
Returns#
- float
The conception rate for heifers used in the TAI protocol.
- _detect_estrus(detection_rate: float) bool #
Determine if estrus was detected.
Estrus is detected if a randomized rate is less than the estrus detection rate.
Parameters#
- detection_ratefloat
The reference estrus detection rate to compare to.
Returns#
- bool
True if estrus was detected, False otherwise.
- execute_ed_protocol(sim_day: int) None #
Execute the ED protocol.
Notes#
The two main differences between how estrus detection is handled in the ED protocol and the SynchED protocol are: 1. The estrus detection rate and conception rate are different. 2. Here, when estrus is not detected, another estrus is simulated. In the SynchED protocol,
when estrus is not detected, TAI will be performed next.
Parameters#
- sim_dayint
The current day of the entire simulation.
Returns#
None
- _handle_generic_estrus_detection(sim_day: int) None #
Perform a typical estrus detection used in the ED protocol.
Parameters#
sim_day : int
Returns#
- _handle_estrus_detection(sim_day: int, on_estrus_detected: Callable[[int], None], on_estrus_not_detected: Callable[[int], None]) None #
A skeletal method for handling estrus detection that needs to be provided with the appropriate functions to call when estrus is detected and when estrus is not detected.
Parameters#
- sim_dayint
The current day of the entire simulation.
- on_estrus_detectedCallable[[int], None]
A function to call when estrus is detected.
- on_estrus_not_detectedCallable[[int], None]
A function to call when estrus is not detected.
Returns#
None
- _handle_estrus_detected(sim_day: int) None #
Perform the typical actions associated with estrus detection as used in the ED protocol.
Parameters#
- sim_dayint
The current day of the entire simulation.
Returns#
None
- _handle_estrus_not_detected(sim_day: int) None #
Perform the typical actions associated with estrus not being detected as used in the ED protocol.
Parameters#
- sim_dayint
The current day of the entire simulation.
Returns#
None
- _deliver_hormones(hormones: list[str], delivery_day: int, sim_day: int) None #
Deliver hormones to the heifer.
Parameters#
- hormoneslist[str]
A list of hormones to deliver. Supported options: ‘GnRH’, ‘PGF’, ‘CIDR’.
- delivery_dayint
The day of the heifer’s life when the hormones were delivered.
- sim_dayint
The current day of the entire simulation.
Returns#
None
- _execute_hormone_delivery_schedule(sim_day: int, schedule: dict[int, dict]) None #
Execute a hormone delivery schedule.
Parameters#
- sim_dayint
The current day of the entire simulation.
- scheduledict[int, dict]
A dictionary of days and actions to perform on those days.
Returns#
None
- static _get_breeding_start_day() int #
Get the day of the heifer’s life when breeding starts.
Returns#
- int
The day of the heifer’s life when breeding starts.
- static get_user_defined_repro_data(attribute: str) Any #
Get the reproduction data for heifers defined by the user.
Parameters#
- attributestr
The attribute to get from the reproduction data.
Returns#
- Any
The value of the attribute.
Raises#
- KeyError
If the attribute is not a valid attribute.
- static get_user_defined_repro_protocol() str #
Get the reproduction protocol for heifers defined by the user.
Returns#
- str
The reproduction protocol for heifers defined by the user.
- static get_user_defined_repro_sub_protocol() str #
Get the reproduction sub protocol for heifers defined by the user.
Returns#
- str
The reproduction sub protocol for heifers defined by the user.
- static _get_default_repro_sub_protocol(protocol: str) str #
Get the default reproduction sub-protocol for heifers for a given reproduction protocol.
Notes#
The default reproduction sub-protocol for heifers is defined in the InternalReproSettings class.
Parameters#
- protocolstr
The reproduction protocol to get the default sub protocol for.
Returns#
- str
The default reproduction sub protocol for heifers for the given reproduction protocol.
- _get_user_defined_or_default_repro_sub_protocol() str #
Get the reproduction sub protocol for the heifer.
Notes#
When the current reproduction protocol is the same as the user-defined protocol, the user-defined sub-protocol is used. Otherwise, the default sub-protocol for the current reproduction protocol is used.
Returns#
- str
The reproduction sub-protocol for the heifer.
- static get_user_defined_repro_sub_properties() dict #
Get the reproduction sub properties for heifers defined by the user.
Returns#
- dict
The reproduction sub properties for heifers defined by the user.
- execute_tai_protocol(sim_day: int) None #
Execute the timed artificial insemination (TAI) protocol.
Parameters#
- sim_dayint
The current day of the entire simulation.
Returns#
None
- execute_synch_ed_protocol(sim_day: int) None #
Execute the SynchED protocol.
This method may be called every day after the heifer enters the breeding phase. However, only on certain days will the heifer receive hormone injections or be checked for estrus.
Parameters#
- sim_dayint
The current day of the entire simulation.
Returns#
None
- _set_up_hormone_schedule(animal_category: Literal['heifers', 'cows'], repro_sub_protocol: str, start_from: int) None #
Set up the hormone delivery schedule for the heifer. Used in TAI and SynchED protocols.
Parameters#
- animal_categoryLiteral[‘heifers’, ‘cows’]
The animal category to use. Either ‘heifers’ or ‘cows’.
- repro_sub_protocolstr
The reproduction sub protocol to use.
- start_fromint
The day of the heifer’s life when the hormone delivery schedule starts.
Returns#
None
Raises#
- Exception
If there is no hormone delivery schedule for the animal category.
- _handle_synch_ed_hormone_delivery_and_set_estrus_day(sim_day: int) None #
Handle hormone delivery and set the estrus day for the heifers in the SynchED program.
Estrus day is calculated and set after the last hormone delivery.
Parameters#
- sim_dayint
The current day of the entire simulation.
Returns#
None
- _handle_synch_ed_estrus_detection(sim_day: int) None #
Handle estrus detection in the heifers in the SynchED program.
If estrus is detected, AI day is set to the next day.
Parameters#
- sim_dayint
The current day of the entire simulation.
Returns#
None
- _handle_estrus_not_detected_in_synch_ed(sim_day: int) None #
Handle the scenario where estrus is not detected in the heifers in the SynchED program.
Parameters#
- sim_dayint
The current day of the entire simulation.
Returns#
None
- _set_repro_program(sim_day: int, repro_program: str) None #
Set the reproduction program for the heifer.
Parameters#
- sim_dayint
The current day of the entire simulation.
- repro_programstr
The reproduction program to set.
Returns#
None
Raises#
- ValueError
If the reproduction program is not valid.
- open(sim_day: int) None #
Open heifer after abortion or pregnancy loss.
Notes#
Regardless of the reproduction program used for the first breeding, the rebreeding program is estrus detection (ED). The new estrus day will be the abortion day plus the estrus cycle length.
Parameters#
- sim_dayint
The current day of the entire simulation.
- property is_pregnant#
Determine if the heifer is pregnant.
Returns#
- bool
True if the heifer is pregnant, False otherwise.
- _perform_ai(sim_day: int) None #
Perform artificial insemination on the heifer.
Parameters#
- sim_dayint
The current day of the entire simulation.
Returns#
None
- _increment_ai_counts() None #
Increment the performed AI counts across all heifers.
Notes#
The following counts are incremented: - num_ai_performed: the total number of AIs performed - num_ai_performed_in_ED: the number of AIs performed in the ED protocol - num_ai_performed_in_TAI: the number of AIs performed in the TAI protocol - num_ai_performed_in_SynchED: the number of AIs performed in the SynchED protocol
Note that a heifer can go through multiple breeding programs in its lifetime. For example, a heifer can be bred using the TAI protocol, then open, then bred using the ED protocol.
Returns#
None
- _increment_successful_conceptions() None #
Increment the successful conception counts across all heifers.
The following counts are incremented: - num_successful_conceptions: the total number of successful conceptions - num_successful_conceptions_in_ED: the number of successful conceptions in the ED protocol - num_successful_conceptions_in_TAI: the number of successful conceptions in the TAI protocol - num_successful_conceptions_in_SynchED: the number of successful conceptions in the SynchED protocol
Note that a heifer can go through multiple breeding programs in its lifetime. For example, a heifer can be bred using the TAI protocol, then open, then bred using the ED protocol.
Returns#
None
- _handle_successful_conception(sim_day: int)#
Handle a successful conception in the heifer by logging the event and initializing pregnancy parameters.
Parameters#
- sim_dayint
The current day of the entire simulation.
Returns#
None
- _handle_failed_conception(sim_day: int) None #
Handle a failed conception in the heifer by logging the event and simulating estrus.
Parameters#
- sim_dayint
The current day of the entire simulation.
Returns#
None
- static _calculate_gestation_length() int #
Calculate the gestation length of the heifer (days).
Returns#
- int
The gestation length of the heifer (days).
- static _calculate_calf_birth_weight(breed: Literal['HO', 'JE']) float #
Calculate the birth weight of the calf.
Parameters#
- breedLiteral[‘HO’, ‘JE’]
The breed of the heifer.
Returns#
- float
The birth weight of the calf.
- _initialize_pregnancy_parameters() None #
Initialize the pregnancy parameters for the heifer.
Returns#
None
- preg_update(sim_day: int) None #
Update the pregnancy status of the heifer.
Parameters#
- sim_dayint
The current day of the entire simulation.
Returns#
None
- _handle_preg_check(preg_check_config: PregCheckConfig, sim_day)#
Handle a pregnancy check by logging the event and terminating the pregnancy if necessary.
Parameters#
- preg_check_configdict[str, str | int | float]
A dictionary of pregnancy check configuration values.
- sim_dayint
The current day of the entire simulation.
Returns#
None