diff --git a/RUFAS/biophysical/animal/herd_manager.py b/RUFAS/biophysical/animal/herd_manager.py index 5c31672d3e..e7a31f928c 100644 --- a/RUFAS/biophysical/animal/herd_manager.py +++ b/RUFAS/biophysical/animal/herd_manager.py @@ -81,7 +81,6 @@ def __init__( time: RufasTime, is_ration_defined_by_user: bool, available_feeds: list[Feed], - simulate_animals: bool, ) -> None: """ Initializes the pens and the animal herd in the simulation with data from @@ -97,8 +96,6 @@ def __init__( True if user-defined rations are used for the herd, otherwise false. available_feeds : list[Feed] Nutrition information of feeds available to formulate animals rations with. - simulate_animals : bool - True if animals should be simulated, otherwise false. """ self.im = InputManager() self.om = OutputManager() @@ -112,7 +109,7 @@ def __init__( AnimalConfig.milk_fat_percent, AnimalConfig.true_protein_percent, AnimalModuleConstants.MILK_LACTOSE ) - self.simulate_animals = simulate_animals + # self.simulate_animals = simulate_animals self.calves: list[Animal] = [] self.heiferIs: list[Animal] = [] @@ -160,21 +157,21 @@ def __init__( self.initialize_pens(animal_config_data["pen_information"]) - if self.simulate_animals: - herd_population = HerdFactory.post_animal_population - self.calves, self.heiferIs, self.heiferIIs, self.heiferIIIs, self.cows, self.replacement_market = ( - herd_population.calves, - herd_population.heiferIs, - herd_population.heiferIIs, - herd_population.heiferIIIs, - herd_population.cows, - herd_population.replacement, - ) + # if self.simulate_animals: + herd_population = HerdFactory.post_animal_population + self.calves, self.heiferIs, self.heiferIIs, self.heiferIIIs, self.cows, self.replacement_market = ( + herd_population.calves, + herd_population.heiferIs, + herd_population.heiferIIs, + herd_population.heiferIIIs, + herd_population.cows, + herd_population.replacement, + ) - self.allocate_animals_to_pens(time.simulation_day) - self.initialize_nutrient_requirements(weather, time, available_feeds) + self.allocate_animals_to_pens(time.simulation_day) + self.initialize_nutrient_requirements(weather, time, available_feeds) - self._print_animal_num_warnings(animal_config_data["herd_information"]) + # self._print_animal_num_warnings(animal_config_data["herd_information"]) @property def animals_by_type(self) -> dict[AnimalType, list[Animal]]: @@ -390,52 +387,52 @@ def print_herd_snapshot(self, txt: str) -> None: f"cows: {len(self.cows)}\t" ) - def _print_animal_num_warnings(self, herd_data: dict[str, Any]) -> None: - """ - If simulate_animals is false, creates warnings if there are more than 0 animals for any of the animal types, - and logs how many warnings were generated - Otherwise, if simulate_animals is true, logs that it is true - - Parameters - ---------- - herd_data : Dict[str, Any] - dictionary containing information about the herd - - """ - - animal_keys = { - "calf_num", - "heiferI_num", - "heiferII_num", - "heiferIII_num_springers", - "cow_num", - } - - info_map = { - "class": self.__class__.__name__, - "function": self._print_animal_num_warnings.__name__, - "simulate_animals": self.simulate_animals, - "herd_data_animal_nums": {key: herd_data[key] for key in animal_keys}, - } - - counter = 0 - - if not self.simulate_animals: - for key in animal_keys: - if herd_data[key] != 0: - self.om.add_warning( - f"invalid_{key}_warning", - f"Warning: simulate_animals is false, but {key} is not.", - info_map, - ) - counter += 1 - self.om.add_log( - "num_warnings_associated_with_simulate_animals", - f"{counter} warnings were associated with simulate_animals", - info_map, - ) - else: - self.om.add_log("simulate_animals_flag", "simulate_animals is true", info_map) + # def _print_animal_num_warnings(self, herd_data: dict[str, Any]) -> None: + # """ + # If simulate_animals is false, creates warnings if there are more than 0 animals for any of the animal types, + # and logs how many warnings were generated + # Otherwise, if simulate_animals is true, logs that it is true + + # Parameters + # ---------- + # herd_data : Dict[str, Any] + # dictionary containing information about the herd + + # """ + + # animal_keys = { + # "calf_num", + # "heiferI_num", + # "heiferII_num", + # "heiferIII_num_springers", + # "cow_num", + # } + + # info_map = { + # "class": self.__class__.__name__, + # "function": self._print_animal_num_warnings.__name__, + # "simulate_animals": self.simulate_animals, + # "herd_data_animal_nums": {key: herd_data[key] for key in animal_keys}, + # } + + # counter = 0 + + # if not self.simulate_animals: + # for key in animal_keys: + # if herd_data[key] != 0: + # self.om.add_warning( + # f"invalid_{key}_warning", + # f"Warning: simulate_animals is false, but {key} is not.", + # info_map, + # ) + # counter += 1 + # self.om.add_log( + # "num_warnings_associated_with_simulate_animals", + # f"{counter} warnings were associated with simulate_animals", + # info_map, + # ) + # else: + # self.om.add_log("simulate_animals_flag", "simulate_animals is true", info_map) def _reset_daily_statistics(self) -> None: """Reset the daily herd statistics.""" @@ -1407,8 +1404,8 @@ def formulate_rations( Feeds requested to be purchased for the newly formulated rations. """ - if not self.simulate_animals: - return RequestedFeed({}) + # if not self.simulate_animals: + # return RequestedFeed({}) self.clear_pens() self.allocate_animals_to_pens(simulation_day) diff --git a/RUFAS/simulation_engine.py b/RUFAS/simulation_engine.py index cfadbba4e3..46cf74ddd3 100644 --- a/RUFAS/simulation_engine.py +++ b/RUFAS/simulation_engine.py @@ -144,10 +144,6 @@ def __init__(self, simulation_type: SimulationType) -> None: self.om = OutputManager() self.im = InputManager() self.time = RufasTime() - self.herd_manager = None - self.field_manager = None - self.feed_manager = None - self.manure_manager = None self.simulation_type = simulation_type self.simulate_animals = self.simulation_type.simulate_animals self.simulate_fields = self.simulation_type.simulate_fields @@ -208,7 +204,6 @@ def _initialize_simulation(self) -> None: self.time, is_ration_defined_by_user=self.is_ration_defined_by_user, available_feeds=self.available_feeds, - simulate_animals=self.simulate_animals, ) # if self.simulate_manure: @@ -448,7 +443,7 @@ def _execute_daily_animal_operations(self) -> tuple[dict[str, ManureStream], dic requested_feed = self.herd_manager.collect_daily_feed_request() is_ok_to_feed_animals, daily_feeds_fed = ( self.feed_manager.manage_daily_feed_request(requested_feed, self.time) - if self.feed_manager is not None + if self.simulate_feed else True ), FeedFulfillmentResults.fulfill_feed_request_as_purchased(requested_feed) diff --git a/RUFAS/task_manager.py b/RUFAS/task_manager.py index 3fade6da5a..8342e7cf39 100644 --- a/RUFAS/task_manager.py +++ b/RUFAS/task_manager.py @@ -660,11 +660,11 @@ def task( return f"{output_prefix} ({task_id})" @staticmethod - def handle_herd_initializaition(args: dict[str, Any], output_manager: OutputManager) -> None: + def handle_herd_initialization(args: dict[str, Any], output_manager: OutputManager) -> None: """Handles initialization of the herd based on specified arguments.""" info_map = { "class": TaskManager.__name__, - "function": TaskManager.handle_herd_initializaition.__name__, + "function": TaskManager.handle_herd_initialization.__name__, "units": MeasurementUnits.UNITLESS, } output_manager.add_log("Herd initialization start", "Initializing herd data...", info_map) @@ -693,7 +693,8 @@ def handle_single_simulation_run(args: dict[str, Any], output_manager: OutputMan output_manager.add_log("Starting the simulation", "Starting the simulation", info_map) - TaskManager.handle_herd_initializaition(args, output_manager) + if simulation_type.simulate_animals: + TaskManager.handle_herd_initialization(args, output_manager) simulator = SimulationEngine(simulation_type=simulation_type) simulator.simulate() @@ -988,7 +989,7 @@ def _handle_herd_init_tasks( ) -> None: """Handler for all methods related to herd initialization.""" args["init_herd"] = True - TaskManager.handle_herd_initializaition(args=args, output_manager=output_manager) + TaskManager.handle_herd_initialization(args=args, output_manager=output_manager) TaskManager.handle_post_processing( args=args, input_manager=input_manager,