RUFAS.routines.animal.pen module#
- class RUFAS.routines.animal.pen.Pen(pen_id: int, pen_name: str, vertical_dist_to_milking_parlor: float, horizontal_dist_to_milking_parlor: float, number_of_stalls: int, housing_type: str, bedding_type: str, pen_type: str, manure_handling: str, manure_separator: str, manure_separator_after_digestion: str, manure_storage: str, animal_combination: AnimalCombination, max_stocking_density: float)#
Bases:
object
Manages a pen’s operation. Stores the characteristics of the pen and the animals that are housed in it any point in the simulation. This class also keeps track of some key characteristics of the average animal in the pen.
Attributes#
- pen_idint
The pen’s unique pen ID. Obtained from the input file.
- vertical_dist_to_milking_parlorfloat
The vertical distance to milking parlor, measured in kilometers. Obtained from the input file.
- horizontal_dist_to_milking_parlorfloat
The horizontal distance to milking parlor, measured in kilometers. Obtained from the input file.
- number_of_stallsint
The number of stalls. Obtained from the input file.
- housing_typestring
The housing type of the pen. Obtained from the input file.
- bedding_typestring
The bedding type of the pen. Obtained from the input file.
- pen_typestring
The pen type (freestall or tiestall). Obtained from the input file.
- manure_handlingstring
The manure handling method used to clean the pen.
- manure_separatorstring
The type of manure separator that processes manure excreted in the pen.
- manure_separator_after_digestionstring
The type of manure separator that processes manure from the pen after it’s been in a digestor.
- manure_storagestring
The type of manure storage receptacle that stores manure excreted in the pen.
- avg_p_intakefloat
The average phosphorus intake of the animals in the pen.
- avg_p_reqfloat
The average phosphorus requirements of the animals in the pen.
- avg_p_animalfloat
The average phosphorus content/mass of the animals in the pen.
- animals_in_pendictionary
A dictionary of all animals in this pen that maps animal id to animal object.
- classes_in_penset
The set (no repeats) of all the classes to which the animals in the pen belong.
- avg_DBWfloat
The average daily change in (delta) body weight of the animals in the pen. Used for ration formulation.
- avg_BWfloat
The average body weight of the animals in the pen. Used for ration formulation.
- avg_DMIestfloat
The average dry matter intake estimation of the animals in the pen. Used for ration formulation
- avg_nutrient_rqmtsdict
Contains the average nutrient requirements of the animals in the pen. Used for ration formulation
- avg_milkfloat
The average milk production of the animals in the pen. Used for (lactating cow) ration formulation
- avg_CP_milkfloat
The average milk crude protein content of the animals in the pen. Used for (lactating cow) ration formulation
- rationdict
Contains the ration for all the animals in the pen.
- ration_nutrient_amountdict
Contains the total amount of different nutrients in the current ration.
- ration_nutrient_concdict
Contains the concentration of different nutrients in the current ration.
- dry_matter_intakefloat
The dry matter intake value of the animals in the pen.
- avg_growthfloat
The average growth of the animals in the pen.
- MEdietfloat
The metabolizable energy concentration of the diet fed to the pen.
- _manure_dict_templatedict
The dictionary template for the manure attributes (manure, calf_total, etc)
- manuredict
Contains the total manure excretion of all animals in the pen.
- calf_totaldict
Contains the total manure excretion of the calves in the pen.
- heifer_totaldict
Contains the total manure excretion of the heifers in the pen.
- dry_totaldict
Contains the total manure excretion of the dry cows in the pen.
- lactating_totaldict
Contains the total manure excretion of the lactating cows in the pen.
- animal_combinationAnimalCombination
Represents the valid animal type combinations in the pen.
- __init__(pen_id: int, pen_name: str, vertical_dist_to_milking_parlor: float, horizontal_dist_to_milking_parlor: float, number_of_stalls: int, housing_type: str, bedding_type: str, pen_type: str, manure_handling: str, manure_separator: str, manure_separator_after_digestion: str, manure_storage: str, animal_combination: AnimalCombination, max_stocking_density: float) None #
Initializes a pen with the given arguments.
Parameters#
- pen_idint
the unique id number of the pen
- vertical_dist_to_milking_parlorfloat
vertical distance to milking parlor, km
- horizontal_dist_to_milking_parlor: float
horizontal distance to milking parlor, km
- number_of_stallsint
number of stalls in the pen
- housing_typestr
housing type of the pen
- bedding_typestr
bedding type of the pen
- pen_typestr
freestall or tiestall
- manure_handlingstr
the manure handling method used to clean the pen
- manure_separatorstr
the manure separator that processes manure excreted in this pen
- manure_separator_after_digestionstr
the second manure separator that processes manure excreted in this pen post-digestor
- manure_storagestr
the manure storage receptacle that stores manure excreted in this pen
- animal_combinationAnimalCombination
the valid animal combinations inside this pen, an instance of the AnimalCombination Enum
- max_stocking_densityfloat
maximum stocking density allowed for pen
- property current_stocking_density: float#
Returns the current stocking density of the pen.
Returns#
- float
the current stocking density of the pen.
- property is_populated: bool#
Returns whether the pen is populated.
Returns#
- bool
True if the pen is populated, False otherwise.
- property needs_ration_formulation: bool#
Returns whether pen needs a ration formulated.
- This is currently written to cover the case in which a ration was not formulated due to the pen being empty,
but was populated in subsequent days.
Returns#
- bool
True if pen needs ration formulation.
- set_avg_nutrient_rqmts(avg_nutrient_rqmts: Dict[str, float | EssentialAminoAcidRequirements]) None #
Sets the pen’s average nutrient requirements
Parameters#
- avg_nutrient_rqmts: Dict[str, float]
The new average nutrient requirements
- set_milk_avgs(avg_milk: float, avg_CP_milk: float, avg_milk_production_reduction: float) None #
Sets the pen’s average milk and average CP milk.
Parameters#
- avg_milk: float
The new average nutrient requirements
- avg_CP_milk: float
The new average CP milk
- add_new_animals(new_animals: List[Calf | HeiferI | HeiferII | HeiferIII | Cow]) None #
Adds all animals in new_animals to the pen.
Parameters#
- new_animals: List[Calf | Cow | HeiferI | HeiferII | HeiferIII]
list of new animals to be added to the pen
- update_animal_combination(animal_combination: AnimalCombination) None #
Sets the pen’s animal combination to animal_combination
Parameters#
- animal_combination: AnimalCombination
the new AnimalCombination
- update_classes_in_pen() None #
Updates the classes contained within the pen
- update_animals(new_animals: List[Any], animal_combination: AnimalCombination) None #
Calls functions that will add new animals to the pen and update associated attributes.
Parameters#
- new_animals: List[Calf | Cow | HeiferI | HeiferII | HeiferIII]
list of new animals to be added to the pen
- animal_combination: AnimalCombination
an AnimalCombination Enum representing the type of the new animals
- manure_sums(manure: Dict[float, int], curr_manure: AnimalManureExcretions, animal_dict: Dict[float, int]) Tuple[Dict[float, int], Dict[float, int]] #
Accumulator helper function for calc_manure. The function finds sums of manure components for each animal in the pen and the total manure for each animal type.
Parameters#
- manure: Dict[float, int]
A dictionary that contains the the accumulated manure excretion values for all animals
- curr_manure: AnimalManureExcretions
A dictionary that contains the manure excretion values used to update the manure and animal dictionaries in the AnimalManureExcretions class definition.
- animal_dict: Dict[float, int]
A dictionary that contains the manure excretion values for specific animals in the pen
Returns#
- Tuple[Dict[float, int], Dict[float, int]]
A tuple containing the updated manure dictionary and the updated animal dictionary.
- calc_manure(feed, methane_model: str)#
Calculates the manure excretion of the animals in the pen.
Parameters#
- feed: Feed
An object of the Feed class containing information about the feed.
- methane_modelstr
Methane model used for calculations.
- _copy_manure_template()#
- reset_manure()#
- calc_avg_growth() None #
Calculates the average growth of the animals in the pen.
- calc_daily_walking_dist()#
Sets the daily walking distance for the cows in the pen (if any).
- call_p_rqmts()#
Calls each animal’s method to calculate phosphorus requirements.
- daily_p_update()#
Calls each animal’s method to calculate daily phosphorus update.
- remove_animals_by_ids(animal_ids: List[int]) None #
Removes animals from the pen by their ids.
Notes#
Because this method takes O(n) time, it is recommended that the caller of this method should prepare a list of animal ids to be removed from the pen first, and then call this method with that list once.
Parameters#
- animal_idsList[int]
List of animals that match the given ids to be removed from the pen.
- clear()#
Clears the pen attributes for re-allocation.
- subset_class_feeds(feed) None #
Subsets the feed_ids list to appropriately include the feeds necessary for that pen object, based on the animal type(s) that are currently in the pen.
Parameters#
- feedFeed
An object of the Feed class.
- static _get_prefix_and_default_manure_excretion(animal: Calf | HeiferI | HeiferII | HeiferIII | Cow, is_lactating_cow=False) Tuple[str, AnimalManureExcretions] #
Get the prefix and default manure value for a given animal.
Parameters#
- animal: Calf | HeiferI | HeiferII | HeiferIII | Cow
The animal instance for which to get the prefix and manure.
- is_lactating_cow: bool, optional
True if the animal is a lactating cow, False otherwise. Default is set to False.
Returns#
- Tuple[str, AnimalManureExcretions]
A tuple containing the prefix and default manure value for the animal.
Raises#
- ValueError
If prefix for animal type is not found.
- _calc_animal_manure_excretion(animal: Calf | HeiferI | HeiferII | HeiferIII | Cow, methane_model: str, methane_mitigation_method: str, methane_mitigation_additive_amount: float) Tuple[str, AnimalManureExcretions] #
Calculate the manure excretion for a given animal and return the prefix and excretions.
Parameters#
- animal: Calf | HeiferI | HeiferII | HeiferIII | Cow
The animal instance for which to calculate manure excretion.
- feed: Feed
An object of the Feed class containing information about the feed.
- methane_model: str
Methane model used for calculations.
- methane_mitigation_method: str
Methane mitigation method used.
- methane_mitigation_additive_amount: float
Amount of methane mitigation additive, mg/kg dry matter intake (DMI).
Returns#
- Tuple[str, AnimalManureExcretions]
A tuple containing the prefix and calculated manure excretion for the animal.
- static _update_animal_manure_excretion_data(manure_excretions_output_data: dict[str, dict[str, str | AnimalManureExcretions]], prefix: str, manure: AnimalManureExcretions, animal: Calf | HeiferI | HeiferII | HeiferIII | Cow) None #
Update the manure excretion dictionaries and the self.manure variable.
Parameters#
- manure_excretions_output_data: dict[str, dict[str, str | AnimalManureExcretions]]
Dictionary mapping prefixes to animal manure data.
- prefix: str
Prefix related to the animal type.
- manure: AnimalManureExcretions
Manure excretions data for the animal.
- animal: Calf | HeiferI | HeiferII | HeiferIII | Cow
The animal instance for which to update the manure excretion data.
Returns#
None
- calc_total_manure(methane_model: str, methane_mitigation_method: str, methane_mitigation_additive_amount: float, manure_excretions_output_data: dict[str, dict[str | AnimalManureExcretions]]) None #
Calculate the total manure excreted by all animals in the pen.
Parameters#
- feed: Feed
An object of the Feed class that stores the feed information managed by the farm
- methane_model: str
Methane model used for methane emission calculations, including “Mutian”, “Mills”, “IPCC”.
- methane_mitigation_method: str
Methane mitigation method used to reduce enteric methane emissions, including “3-NOP”, “Monensin”, “Essential Oils”, and “Seaweed”.
- methane_mitigation_additive_amount: float
The amount of methane mitigation feed additive that is added, mg/kg dry matter intake (DMI). The recommended dose for 3-NOP is between 40 and 100 mg/kg DMI, while that for monensin is between 16 and 36 mg/kg DMI.
- manure_excretions_output_datadict[str, dict[str | AnimalManureExcretions]]
Dictionary mapping prefixes to animal manure data.
Returns#
None
- _set_animal_nutrient_values(animal, animal_grouping_scenario, feed, temp, phosphorus_concentration) None #
Set the nutrient values for the animal.
Parameters#
- animalUnion[Calf, HeiferI, HeiferII, HeiferIII, Cow]
The animal to set the nutrient values for.
animal_grouping_scenario feed temp phosphorus_concentration : float
Returns#
None
- _calc_new_ration(num_animals: int)#
Calculate the new ration for the pen based on the number of animals in the pen.
Parameters#
- num_animalsint
The number of animals in the pen.
Returns#
- rationDict[str, Union[float, str]]
The new ration for the pen.
- add_animal(animal, animal_grouping_scenario, feed, temp, phosphorus_concentration: float) None #
Add an animal to the pen and adjust the ration accordingly.
Parameters#
- animalUnion[Calf, HeiferI, HeiferII, HeiferIII, Cow]
The animal to be added to the pen.
animal_grouping_scenario feed temp phosphorus_concentration : float
Returns#
None
- remove_animal(animal_id: int) None #
Remove an animal from the pen by its id and adjust the ration accordingly.
Parameters#
- animal_idint
The id of the animal to be removed from the pen.
Returns#
None
- _count_lactating_cows() int #
Returns the count of lactating cows currently held in this pen.
- get_manure_data() PenManureData #
Packages manure data from this pen.