RUFAS.routines.animal.life_cycle.herd_factory module#

class RUFAS.routines.animal.life_cycle.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.

__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.

_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

_heiferIIIs_update(day: int) None#

HeiferIIIs update for generating herd simulation

_cows_update(time: RufasTime) None#

Cows update for generating herd simulation

_generate_animals(time: RufasTime) AnimalPopulation#

Function to generate an AnimalPopulation object through simulation

_backtrack_animal_birth_date(animal_data: dict[str, Any], time: RufasTime) str#

Function to backtrack the birth date 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], time: RufasTime) Calf | HeiferI | HeiferII | HeiferIII | Cow#

Function to initialize an animal object from input data

_initialize_herd_from_data(time: RufasTime) 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[Calf] | List[HeiferI] | List[HeiferII] | List[HeiferIII] | List[Cow]#

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 added to the InputManager pool.