RUFAS.biophysical.animal.herd_factory module#

class RUFAS.biophysical.animal.herd_factory.HerdFactory(init_herd: bool = False, save_animals: bool = False, save_animals_path: Path = PosixPath('output'))#

Bases: object

Class to initialize herd for simulation.

Attributes#

breedstr

The breed of the animals in the simulation, retrieved from input data.

CIint

Calving interval from the animal configuration, retrieved from input data.

initial_animal_numint

The initial number of animals in the simulation, retrieved from input data.

simulation_daysint

The number of days the simulation will run to generate herd, retrieved from input data.

pre_animal_populationAnimalPopulation

An instance of AnimalPopulation representing the animal population before random sampling with replacement.

post_animal_populationAnimalPopulation

An instance of AnimalPopulation representing the animal population after random sampling with replacement.

post_animal_population: AnimalPopulation#
__init__(init_herd: bool = False, save_animals: bool = False, save_animals_path: Path = PosixPath('output')) None#

Initializes HerdFactory.

Parameters#

init_herdbool, default=False

A flag to indicate whether to initialize through simulation or from input data.

save_animalsbool, default=False

Indicates whether to save the generated animals to JSON files.

save_animals_pathPath, default=Path(“output/”)

The directory path where the animal data JSON files will be saved if save_animals is True.

classmethod set_post_animal_population(animal_population: AnimalPopulation) None#

Sets the post-animal population for the class.

Parameters#

animal_populationAnimalPopulation

An instance of AnimalPopulation that represents the updated animal population.

Returns#

None

_calf_and_heiferI_update(animal: Animal) DailyRoutinesOutput#

Updates the daily routines specific for calf and heiferI.

Parameters#

animalAnimal

The animal instance to update. Must be of type CALF or HEIFER_I.

Returns#

DailyRoutinesOutput

The updated daily routines output after processing the animal’s daily growth and life stage update.

Raises#

TypeError

If the animal type is not CALF or HEIFER_I.

_heiferII_update(animal: Animal) DailyRoutinesOutput#

Updates the daily routines for heiferII.

Parameters#

animal: Animal

The animal instance to update. Must be of type AnimalType.HEIFER_II.

Returns#

DailyRoutinesOutput

The updated daily routines output containing the status of the animal.

Raises#

TypeError

If the animal type is not HEIFER_II.

_heiferIII_update(animal: Animal) DailyRoutinesOutput#

Updates the daily routines for heiferIII.

Parameters#

animalAnimal

The animal instance to update. Must be of type AnimalType.HEIFER_III.

Returns#

DailyRoutinesOutput

The updated daily routines output containing the status of the animal.

Raises#

TypeError

If the provided animal is not of type AnimalType.HEIFER_III.

_cow_update(animal: Animal) DailyRoutinesOutput#

Updates the daily routines of a cow.

Parameters#

animalAnimal

An instance of the Animal class representing the cow to be updated.

Returns#

DailyRoutinesOutput

An object that contains updates related to the cow’s daily routines such as reproduction outputs (newborn calf configuration) and animal life stage status.

Raises#

TypeError

If the provided animal is not of type cow.

_calves_update() None#

Calves update for generating herd simulation

_heiferIs_update() None#

heiferIs update for generating herd simulation

_heiferIIs_update() None#

HeiferIIs update for generating herd simulation

_cow_give_birth(cow: Animal) None#

Handles the birth process of a calf when a cow gives birth.

Parameters#

cowAnimal

The cow that is giving birth.

Returns#

None

_heiferIIIs_update(day: int) None#

HeiferIIIs update for generating herd simulation

_cows_update() None#

Cows update for generating herd simulation

_generate_animals() AnimalPopulation#

Function to generate an AnimalPopulation object through simulation

_backtrack_animal_birth_date(days_born: int, time: RufasTime) str#

Function to backtrack the birthdate of an animal loaded from data by subtracting the age of the animal from the simulation start date.

_init_animal_from_data(animal_type: str, animal_data: dict[str, Any]) Animal#

Function to initialize an animal object from input data

_initialize_herd_from_data() AnimalPopulation#

Function to initialize an AnimalPopulation object from input data

_random_sample_with_replacement() AnimalPopulation#

Function to randomly sample the herd with replacement

_random_sample_with_replacement_by_type(animal_type: str) list[Animal]#

Function to randomly sample a specific animal type with replacement

initialize_herd() None#

Initialize an AnimalPopulation object for simulation, either from input data or generate from simulation. This function also optionally saves the generated herd data into a JSON file. The initialized herd with be randomly sampled with replacement, and set as the class attribute post_animal_population.