RUFAS.routines.feed.feed module#
- RUFAS.routines.feed.feed.daily_feed_routine(feed, fields, animal_manager)#
- Description:
Executes the functions that run the daily feed routines for both storage and feed management.
- Args:
feed: an instance of the Feed object fields: an instance of the Field object (contains harvest information) animal_manager: an instance of the AnimalManager object
- RUFAS.routines.feed.feed.annual_feed_routine(feed)#
- class RUFAS.routines.feed.feed.Feed(data: PurchasedFeedTypedDict)#
Bases:
object
- __init__(data: PurchasedFeedTypedDict)#
- Description:
Stores the information for the feeds managed by the farm, and the methods for storage.
- Args:
data: the feed information from the input JSON file
- summarize_feed_storage()#
- Description:
Summarize nutrients and losses over the managed storage receptacles
- class Storage(data)#
Bases:
object
- __init__(data)#
- Description:
A subclass of feed storage specifying a single storage receptacle.
- Args:
- data: a dictionary containing information to define the storage
receptacle
- calibrate_storage(crop)#
- Description:
Calibrates the feed storage loss model to the crop being stored in the receptacle. Based on information provided by Kevin Painke-Buisse of the DFRC 2019 “pseudocode_feed” F.1.4
- Args:
crop: The crop to be stored
- forage_quality_assessment(feed)#
- Description:
Updates values in the storage object relevant to the quality of the feed utilizing feed database functions
- Args:
feed: an instance of class Feed
- store_crop(feed, crop)#
- Description:
Helper method for “storing” the specified crop Updates mineral components and losses as a crop is stored. “pseudocode_feed” F.1.1
- Args:
feed: instance of the Feed class crop: the crop to be stored,
an instance of the family of classes under BaseCrop defined in the crop_types folder
- calculate_losses()#
- Description:
Calculates mineral losses for the storage method once all crops are stored “pseudocode_feed” F.1.3
- reset_storage()#
- Description:
Storage class method resets receptacle to initial settings.
- static required_inventory(storage, animal_manager)#
- Description:
Computes the required inventory necessary across all animals for a given forage based on the count of the animals, the body weight, and inclusion percent associated with the input forage. This class method for the feed class updates feed class variables along with class variables associated with the input storage object. Each calculation has a reference to the respective calculation in the pseudocode
- Args:
storage: a storage object that contains forage being assessed animal_manager: the class object Animal Manager which tracks the state of the animals
- static forage_inventory_plan(storage)#
- Description:
Assess farm grown forage stocks and plan maximum intake of each forage to ensure there is enough forage to last a FULL YEAR. Forage inventory is conducted at least 1x/year after harvest and then at a user specified number of times. This function calculates those values and stores it in the input storage object. Each calculation has a reference to its respective calculation in the pseudocode
- Args:
storage: the storage object containing the forage being assessed
- daily_feed_storage(fields)#
- Description:
Executes daily routines relating to crop and feed storage, which handles newly harvested crops.Yield is stored at harvest in available storage grouped by crop type and quality. Once used, that storage receptacle is removed from the list of available storage. If insufficient storage is specified, a “standard” storage receptacle is generated.
- Args:
fields : an instance of the Field object (contains harvest information)
- daily_feed_management(animal_manager)#
- Description:
Executes daily routines relating to feed management, specifically a daily feedout process and checking for new forages that need an inventory plan. If the list new_forages contains a forage which had been harvested at least 30 days ago, forage_inv_plan will be called.
- Args:
animal_manager: The state of the AnimalManager class object
- reset_feed_data()#
- Description:
Resets the accumulated data so they can be interpreted as annual sums. Option to reset feed storage model entirely each year.
- get_all_feed_units(purchased_feeds, grown_feeds)#
- Description:
Constructs and returns a dictionary of where the keys are the feed IDs and the values are dictionaries containing the name and the units of the feed.
- Args:
- purchased_feeds: the list of entries (ints) of feeds that are
purchased
grown_feeds: the list of entries (ints) of feeds that will be grown
- Returns:
a dictionary where the keys are the feed IDs and the values are dictionaries with feed information: - if the feed is purchased, ID is the string form of the ID (e.g. ‘2’) - if the feed is grown, ID is the string form of the ID plus ‘g’ (e.g. ‘8g’) - feed name is as it is in the user_feeds table - units is the string representing the units for the feed (e.g. ‘kg’)
- get_quality_specific_purchased_feed_ids(entries: int | List[int]) List[int] #
- Description:
Constructs and returns a dictionary of the purchased feed IDs based on whether the quality of each feed can be determined at harvest.
- Args:
entries: the purchased feed entries
- Returns:
a dictionary where the keys are the feed entries and the keys are the feed IDs that can be used to find nutrient values in the nutrients table
- get_quality_specific_feed_costs(input_feed_ids: List[int]) Dict[str, float] #
Returns an updated version of the purchased feed costs dictionary. A purchased feed id key will be updated if it is in the list of entries split by mid-maturity. Args:
input_feed_ids: A list of purchased feed ids.
- Returns:
A dictionary that stores key-value pairs, where the keys are purchased feed ids (potentially updated) and the values are feed costs.
- add_to_available_feeds(new_grown_feeds, DM_list, NDF_list)#
- Description:
Appends the nutrient values of new_grown_feeds to the available_feeds dictionary according to their quality (if applicable). If a feed is not split by quality, then the values at the respective indices of DM_list and NDF_list are ignored.
- Args:
- new_grown_feeds: the list of feed entries to be added to
available_feeds with nutrient values based on their quality
- DM_list: the list of dry matter percentages for each feed in
new_grown_feeds (indices match up)
- NDF_list: the list of NDF percentages for each feed in
new_grown_feeds (indices match up)
- update_available_feed(feed_id, nutrient, new_val)#
- Description:
Updates the dictionary of available feeds with a particular nutrient value.
- Args:
- feed_id: string - the ID of the feed to be modified (string should
end in ‘g’ if it is a grown feed
nutrient: the nutrient to be modified new_val: the new value of the nutrient
- remove_from_available_feeds(feeds_to_be_removed)#
- Description:
Removes the IDs in feeds_to_be_removed from available_feeds.
- Args:
feeds_to_be_removed: a list of feed IDs
- get_nutrient_vals(feed_ids, is_grown)#
- Description:
Constructs and returns the dictionary of nutrient values for the feeds represented by feed_ids.
- Args:
feed_ids: list of feed IDs is_grown: boolean - true if the feeds represented by feed_ids are
grown, false if purchased
Returns: a dictionary where the keys are the the feed identifiers and the values are nutrient dictionaries
- get_calf_feeds()#
- _pack_into_dict(var_names: List[str], var_values: List[Any]) Dict[str, Any] #
Pack the provided variable names and values into a dictionary.
Parameters#
- var_namesList[str]
List of keys for the resulting dictionary.
- var_valuesList[Any]
Corresponding values for the keys specified in var_names.
Returns#
- Dict[str, Any]
Dictionary constructed from the provided variable names and values.
Raises#
- ValueError
If the lengths of var_names and var_values are not the same.
Notes#
Ensure that both var_names and var_values have the same length. Each name in var_names will be paired with its corresponding value from var_values.
Example#
>>> self._pack_into_dict(['a', 'b'], [1, 2]) {'a': 1, 'b': 2}
- _retrieve_data(data_source: str, var_names: List[str] = None, unique_value: bool = False, identifier: str = None, desired_rows: List[Any] = None, compare_val: int = None, low_col: str = None, high_col: str = None) List[Dict[str, Any]] #
This function retrieves and filters the desired data, pack each “row” into a dictionary object, and returns a list of desired rows
- data_sourcestr
Path to retrieve the desired data from IM.
- var_namesList[str] = None
A list of desired variables (columns) to retrieve. If omitted, all existing columns are returned.
- unique_value: bool = False
If True, returns only unique values. Default is False.
- identifier: str = None
Column name used for filtering based on desired_rows. Both identifier and desired_rows must be provided for filtering.
- desired_rows: List[Any] = None
Desired row values for filtering. Rows with these values in the identifier column are returned.
- compare_val: int = None
Baseline value for comparison. Used with low_col and high_col to filter rows. The “compare_val” should fall in the range of [low_col_value, high_col_value], otherwise the current row will be ignored.
- low_col: str = None
Column indicating the lower bound for comparison with compare_val.
- high_col: str = None
Column indicating the upper bound for comparison with compare_val.
- List[Dict[str, Any]]
Returns a list of dictionaries, each dictionary corresponds to a row in the csv file.
Retrieve specific columns:
>>> self._retrieve_data(data_source="NASEM_Comp", var_names=["rufas_id", "Name", "feed_type"]) Returns rows from the data source "NASEM_Comp" with columns "rufas_id", "Name", and "feed_type" packed into dictionaries.
2. Filter by specific rows based on an identifier: >>> self._retrieve_data(data_source=”NASEM_Comp”, identifier=”rufas_id”, desired_rows=[1, 2, 157]) Returns rows where the “rufas_id” column has values 1, 2 or 157.
3. Use a value for range comparison: >>> self._retrieve_data(data_source=”NASEM_Comp”, compare_val=5, low_col=”lower_limit”, high_col=”limit”) Returns rows where the “compare_val” of 5 lies between the values in columns “lower_limit” and “limit”.
4. Retrieve unique values from specified columns: >>> self._retrieve_data(data_source=”NASEM_Comp”, var_names=[“rufas_id”, “Name”], unique_value=True) Returns unique rows (based on “rufas_id” and “Name” columns) from the data source “NASEM_Comp”.
5. No filters or specific columns, retrieve all data: >>> self._retrieve_data(data_source=”NASEM_Comp”) Returns all rows from the data source “NASEM_Comp” with all columns packed into dictionaries.
6. Filtering with range comparison and specific desired rows: >>> self._retrieve_data(data_source=”NASEM_Comp”, identifier=”feed_type”, desired_rows=[“Conc”], compare_val=10, low_col=”lower_limit”, high_col=”limit”)
Returns rows where the “feed_type” column has values “Conc” and where the value 10 lies between the values in columns “lower_limit” and “limit”.