RUFAS.biophysical.feed_storage.feed_manager module#

RUFAS.biophysical.feed_storage.feed_manager.ON_FARM_TO_PURCHASED_PRICE_RATION = 0.01#

A type alias representing the context in which a feed purchase was initiated.

class RUFAS.biophysical.feed_storage.feed_manager.FeedManager(feed_config: dict[str, list[Any]], nutrient_standard: NutrientStandard, feed_storage_configs: dict[str, Any], feed_storage_instances: dict[str, list[str]])#

Bases: object

Manages the feed storage, handling crop reception, purchasing, degradation processing, feed distribution, feed purchase management and reporting, and querying available feeds.

Parameters#

feed_configdict[str, list[Any]]

Configuration for the feeds available in the simulation.

nutrient_standardNutrientStandard

Nutrient standard used in the simulation (NASEM or NRC).

crop_to_rufas_ids_mappingdict[str, list[RUFAS_ID]]

Mapping from crops to their corresponding RUFAS IDs.

feed_storage_configsdict[str, Any]

Configurations for the feed storage units.

feed_storage_instancesdict[str, list[str]]

References to the specific feed storage units to be created.

Attributes#

_omOutputManager

Output manager for reporting feed-related data.

_available_feedslist[NASEMFeed | NRCFeed]

List of feeds available for purchase and feeding in the simulation, including their nutritional properties and prices.

active_storagesdict[StorageType, Storage]

Contains the list of active farmgrown crop storage units in the simulation and their mapping from StorageType.

purchased_feed_storagePurchasedFeedStorage

Storage for purchased feeds.

planning_cycle_allowancePlanningCycleAllowance

Represents the allowances for feed purchases during a planning cycle.

runtime_purchase_allowanceRuntimePurchaseAllowance

Represents the allowances for feed purchases during runtime.

crop_to_rufas_iddict[str, RUFAS_ID]

Maps crop configurations to their corresponding RUFAS IDs for harvested crops.

_cumulative_feed_requestsdict[RUFAS_ID, float]

Total amount of each feed requested over time (kg dry matter).

_cumulative_purchased_feeds_feddict[RUFAS_ID, float]

Total amount of purchased feeds fed to animals to date (kg dry matter).

_cumulative_farmgrown_feeds_feddict[RUFAS_ID, float]

Total amount of farmgrown feeds fed to animals to date (kg dry matter).

_cumulative_purchased_feedsdict[RUFAS_ID, float]

Total amount of purchased feeds acquired to date (kg dry matter).

__init__(feed_config: dict[str, list[Any]], nutrient_standard: NutrientStandard, feed_storage_configs: dict[str, Any], feed_storage_instances: dict[str, list[str]]) None#
property available_feeds: list[Feed]#

Returns the list of available feeds.

_create_all_storages(feed_storage_configs: dict[str, Any], feed_storage_instances: dict[str, list[str]]) None#

Creates all feed storage instances based on the provided configurations.

Parameters#

feed_storage_configsdict[str, Any]

A dictionary that contains configurations for all available feed storage types.

feed_storage_instancesdict[str, list[str]]

A dictionary that contains feed storage instance names.

report_feed_manager_balance(simulation_day: int) None#

Reports the balance of feed purchased, requested, and fed to date.

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.

receive_crop(harvested_crop: HarvestedCrop, simulation_day: int) None#

Receives a harvested crop and assigns it to the proper storage unit.

Parameters#

harvested_cropHarvestedCrop

The harvested crop to be stored.

simulation_dayint

The current simulation day, used for tracking storage time.

process_degradations(weather: Weather, time: RufasTime) None#

Processes the degradation of all stored feeds over time.

report_feed_storage_levels(simulation_day: int, reporting_suffix: str) None#

Reports the daily storage levels of farm grown and purchased feeds.

report_cumulative_purchased_feeds(simulation_day: int) None#

Outputs the cumulative purchased feeds to the output manager.

report_stored_farmgrown_feeds(simulation_day: int, reporting_suffix: str) None#

Outputs total amounts of farmgrown feeds currently stored by the FeedManager.

manage_daily_feed_request(requested_feed: RequestedFeed, time: RufasTime) tuple[bool, dict[str, dict[int, float]]]#

Manages the daily feed request by checking available inventory and purchasing additional feed if necessary.

Parameters#

requested_feedRequestedFeed

The feeds and amounts requested for feeding on the current day.

timeRufasTime

RufasTime instance containing the current time of the simulation.

Returns#

tuple[bool, dict[str, dict[RUFAS_ID, float]]]

A tuple where the first element is True if the feed request can be fulfilled (False otherwise), and the second element is a dictionary detailing the amounts of feed deducted from purchased and farmgrown sources.

get_total_projected_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: dict[int, float] | 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_cropsdict[RUFAS_ID, float] | 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).

purchase_feed(feeds_to_purchase: dict[int, float], time: RufasTime, purchase_type: Literal['daily_feed_request', 'ration_interval', 'planning_cycle']) 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.

purchase_typePurchaseType

Type of purchase being made, used for output variable naming.

_store_purchased_feed(rufas_id: int, purchase_amount: float, time: RufasTime) None#

Stores feeds which have been purchased and adjusts for shrink.

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], simulation_day: int) dict[str, dict[int, float]]#

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

simulation_dayint

The current simulation day, used for tracking feed removal.

Returns#

dict[str, dict[RUFAS_ID, float]]

A dictionary with two keys: ‘purchased’ and ‘farmgrown’. Each key maps to another dictionary that contains the RuFaS Feed IDs and the corresponding amounts of feed deducted (kg dry matter) from purchased and farmgrown sources, respectively.

Raises#

ValueError

If the amount of feed to deduct is greater than the amount in storage.

_lookup_storage_rufas_id(crop_name: str) int#

Looks up and returns the RuFaS Feed ID associated with a given crop name in storage.

Parameters#

crop_namestr

The name of the crop to look up.

Returns#

RUFAS_ID

The RuFaS Feed ID associated with the crop in its appropriate storage.

Raises#

ValueError

If no storage with the given crop name is found or there is no rufas ID for the crop in this storage.

_gather_available_feeds() list[HarvestedCrop | PurchasedFeed]#

Gathers all available feeds from active storages and purchased feed storage.

Returns#

list[HarvestedCrop | PurchasedFeed]

A list of all available feeds. The list is sorted by HarvestedCrops (oldest -> newest) followed by PurchasedFeeds in their original order.

_check_feed_availability(target_rufas_id: int, feed: HarvestedCrop | PurchasedFeed) bool#

Helper function that checks if a feed can be fed to animals based on the RuFaS ID and the feeds to deduct.

Parameters#

target_rufas_idRUFAS_ID

RuFaS Feed ID of the feed that is being checked (unitless).

feedHarvestedCrop | PurchasedFeed

The feed object to check for availability.

Returns#

bool

True if the feed can be fed to animals, False otherwise.

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