RUFAS.biophysical.feed_storage.feed_manager module#
- RUFAS.biophysical.feed_storage.feed_manager.CROP_TO_STORAGE_MAPPING: Dict[CropCategory, List[Storage]] = {CropCategory.ALFALFA: [<class 'RUFAS.biophysical.feed_storage.hay.Hay'>, <class 'RUFAS.biophysical.feed_storage.silage.Silage'>, <class 'RUFAS.biophysical.feed_storage.baleage.Baleage'>], CropCategory.CORN: [<class 'RUFAS.biophysical.feed_storage.grain.Grain'>, <class 'RUFAS.biophysical.feed_storage.silage.Silage'>], CropCategory.GRASS: [<class 'RUFAS.biophysical.feed_storage.hay.Hay'>, <class 'RUFAS.biophysical.feed_storage.silage.Silage'>, <class 'RUFAS.biophysical.feed_storage.baleage.Baleage'>], CropCategory.SMALL_GRAIN: [<class 'RUFAS.biophysical.feed_storage.hay.Hay'>, <class 'RUFAS.biophysical.feed_storage.grain.Grain'>, <class 'RUFAS.biophysical.feed_storage.silage.Silage'>, <class 'RUFAS.biophysical.feed_storage.baleage.Baleage'>], CropCategory.SOY: [<class 'RUFAS.biophysical.feed_storage.grain.Grain'>]}#
Maps each StorageType enum element to the associated Storage subclass.
- RUFAS.biophysical.feed_storage.feed_manager.STORAGE_TYPE_TO_CLASS_MAP: dict[StorageType, type[Storage]] = {StorageType.BAG: <class 'RUFAS.biophysical.feed_storage.silage.Bag'>, StorageType.BALEAGE: <class 'RUFAS.biophysical.feed_storage.baleage.Baleage'>, StorageType.BUNKER: <class 'RUFAS.biophysical.feed_storage.silage.Bunker'>, StorageType.DRY: <class 'RUFAS.biophysical.feed_storage.grain.Dry'>, StorageType.HIGH_MOISTURE: <class 'RUFAS.biophysical.feed_storage.grain.HighMoisture'>, StorageType.PILE: <class 'RUFAS.biophysical.feed_storage.silage.Pile'>, StorageType.PROTECTED_INDOORS: <class 'RUFAS.biophysical.feed_storage.hay.ProtectedIndoors'>, StorageType.PROTECTED_TARPED: <class 'RUFAS.biophysical.feed_storage.hay.ProtectedTarped'>, StorageType.PROTECTED_WRAPPED: <class 'RUFAS.biophysical.feed_storage.hay.ProtectedWrapped'>, StorageType.UNPROTECTED: <class 'RUFAS.biophysical.feed_storage.hay.Unprotected'>}#
Ratio of the price of an on-farm price to the price of buying that feed from an off farm source.
- class RUFAS.biophysical.feed_storage.feed_manager.FeedManager(feed_config: dict[str, list[Any]], nutrient_standard: NutrientStandard, crop_to_rufas_ids_mapping: dict[str, list[int]])#
Bases:
object
Manages the feed storage, handling crop reception, purchasing, degradation processing, feed distribution, and querying available feeds.
Attributes#
- Dict[StorageType, Storage]
Containts the list of active storage units in the simulation and their mapping from StorageType(Enum).
- __init__(feed_config: dict[str, list[Any]], nutrient_standard: NutrientStandard, crop_to_rufas_ids_mapping: dict[str, list[int]]) None #
- update_available_feed_amounts() None #
Updates the amounts feeds available based on what is currently stored.
- translate_crop_config_name_to_rufas_id(next_harvest_dates: dict[str, date | None]) dict[int, date] #
Remaps crop configs and their next harvest date to RuFaS feed IDs and their next harvest date.
- _query_result_factory(crop_category: CropCategory, crop_type: CropType, amount: float) Dict[str, CropCategory | CropType | float] #
- receive_crop(harvested_crop: HarvestedCrop, storage_type: StorageType) None #
Receives a harvested crop and assigns it to a storage unit.
Parameters#
- harvested_cropHarvestedCrop
The harvested crop to be stored.
- storage_typeStorageType
The type of storage to use for this crop.
Raises#
- ValueError
If the crop type is not compatible with the storage type.
- process_degradations(weather: Weather, time: RufasTime) None #
Processes the degradation of all stored feeds over time.
- give_feed(amount: float, crop_type: CropType) float #
Distributes feed to the Animal module based on the FIFO principle.
Parameters#
- amountfloat
The amount of feed to distribute.
- crop_typeCropType
The type of crop to distribute.
Returns#
- float
The actual amount of feed distributed.
- report_stored_feeds(time: RufasTime) None #
Outputs total amounts of feeds currently stored by the FeedManager.
- manage_daily_feed_request(requested_feed: RequestedFeed, time: RufasTime) bool #
Returns true if requested feeds can be provided, either through on-farm feeds or by purchasing.
- get_total_inventory(inventory_date: date, weather: Weather, time: RufasTime) TotalInventory #
Gets the inventory expected to be held in storage at the specified date.
Parameters#
- inventory_datedate
Date at which inventory of feeds should be estimated for.
- weatherWeather
Weather instance containing all weather data for the simulation.
- timeRufasTime
RufasTime instance containing the current time of the simulation.
Returns#
- TotalInventory
Total inventory of feeds projected to be held at the current date.
Raises#
- ValueError
If the requested inventory date has already passed in the simulation.
- manage_planning_cycle_purchases(ideal_feeds: IdealFeeds, time: RufasTime) None #
Purchases as much of the ideal feeds as possible, while respecting the Planning Allowance, storage capacity, future harvests, budget, etc.
- manage_ration_interval_purchases(requested_feeds: RequestedFeed, time: RufasTime) None #
Manages the purchasing of feeds at the beginning of a ration interval.
- _query_available_feed_totals(query_feed_ids: list[int], stored_crops: list[HarvestedCrop] | None = None) dict[int, float] #
Gets the current dry matter mass of each feed ID currently in storage.
Parameters#
- query_feed_idslist[RUFAS_ID]
List of RuFaS Feed IDs to get amounts of feed stored for.
- stored_cropslist[HarvestedCrop] | None, default None
Stored crops to tally feed amounts from. If None, tallies feed amounts from all feeds currently stored.
Returns#
- dict[RUFAS_ID, float]
Map of RuFaS Feed IDs to the amounts of each in storage (kg dry matter).
- query_available_feeds(query_crop_types: List[CropType] | None = None, query_crop_categories: List[CropCategory] | None = None, query_storage_types: List[StorageType] | None = None) List[Dict[str, CropCategory | CropType | float]] #
Queries the available amount of feed in storage.
Parameters#
- query_crop_typesList[CropType], optional, default=None
The types of crop to query (if None, all crop types are queried).
- query_crop_categoriesList[CropCategory], optional, default=None
The categories of crop to query (if None, all crop categories are queried).
- query_storage_typesList[StorageType], optional, default=None
The types of storage to query (if None, all storages types are queried).
Returns#
- List[QUERY_RESULT_DATA_TYPE]
The amount of available feed, either as a total or for a specific crop type.
- purchase_feed(feeds_to_purchase: dict[int, float], time: RufasTime) None #
Records amounts and cost of feed purchased, and orchestrates storing them.
Parameters#
- feeds_to_purchasedict[RUFAS_ID, float]
Mapping of RuFaS Feed IDs to the amounts of that feed to be purchased (kg dry matter).
- timeRufasTime
RufasTime object.
- _store_purchased_feed(rufas_id: int, purchase_amount: float, time: RufasTime) None #
Stores feeds which have been purchased.
Parameters#
- rufas_idRUFAS_ID
RuFaS Feed ID of the feed that is to be stored (unitless).
- purchase_amountfloat
Amount of feed that was purchased (kg dry matter).
- timeRufasTime
RufasTime object.
- _deduct_feeds_from_inventory(feeds_to_deduct: dict[int, float]) None #
Removes feeds from storage in a FIFO manner.
Parameters#
- feeds_to_deductdict[RUFAS_ID, float]
Mapping of RuFaS Feed IDs to the amounts of feed that will be removed from storage (kg dry matter).
Raises#
- ValueError
If the amount of feed to deduct is greater than the amount in storage.
- _select_rufas_id_for_harvested_crop(crop_ids: list[int], feed_ids: list[int]) int | None #
Choose which feed a harvested crop will be fed as.
Parameters#
- crop_idslist[RUFAS_ID]
All RuFaS IDs that a crop may be fed as.
- feed_idslist[RUFAS_ID]
List of RuFaS Feed IDs that are being selected from.
Returns#
- RUFAS_ID | None
The RuFaS Feed ID that the harvested crop will be mapped to. If there is no feed that the crop can be fed as None will be returned.
Notes#
Farm grown feeds can map to multiple RuFaS Feed IDs, this ensures they are only counted as a single ID.
- _setup_available_feeds(feed_config: dict[str, list[Any]], nutrient_standard: NutrientStandard) list[Feed] #
Creates list of feeds available for use in the simulation.
Parameters#
- feed_configlist[dict[str, Any]]
Mapping of the feeds available for purchase to the prices of those feeds.
- nutrient_standardNutrientStandard
Indicates whether the NASEM or NRC nutrient standards is being used.
Returns#
- list[Feed]
Nutrition and price information of feeds available in the simulation.
- _process_feed_library(nutrient_standard: NutrientStandard) dict[int, dict[str, Any]] #
Collects and processes the feed library input so that it can be translated into a simulation-friendly format.
Parameters#
- nutrient_standardNutrientStandard
Indicates whether the NASEM or NRC nutrient standards is being used.
Returns#
- dict[RUFAS_ID, dict[str, Any]]
Mapping of RuFaS feed IDs to the nutritional properties of those feeds.