RUFAS.biophysical.feed_storage.storage module#

class RUFAS.biophysical.feed_storage.storage.Storage(capacity: float = inf)#

Bases: object

Abstract class representing a general storage structure.

Attributes#

acceptable_cropsList[CropCategory]

The list of crop categories that this storage can recieve.

capacityfloat

The maximum capacity of the storage, currently set to infinity.

storedList[HarvestedCrop]

A list of HarvestedCrop objects representing the crops stored.

crude_protein_loss_coefficientfloat, default 0.0

Fractional coefficient used to adjust crude protein after dry matter loss.

starch_loss_coefficientfloat, default 0.0

Fractional coefficient used to adjust starch after dry matter loss.

adf_loss_coefficientfloat, default 0.0

Fractional coefficient used to adjust ADF after dry matter loss.

ndf_loss_coefficientfloat, default 0.0

Fractional coefficient used to adjust NDF after dry matter loss.

lignin_loss_coefficientfloat, default 0.0

Fractional coefficient used to adjust lignin after dry matter loss.

ash_loss_coefficientfloat, default 0.0

Fractional coefficient used to adjust ash after dry matter loss.

Methods#

stored_mass()

The total mass (kg) of currently stored crops

receive_crop(crop: HarvestedCrop, time: RufasTime)

Receives a harvested crop and adds it to the storage.

process_degradations(current_conditions: CurrentDayConditions, time: RufasTime)

Processes the degradations and losses of the stored crops.

give_feed(amount: float, crop_type: str)

Gives out a specified amount of feed of a certain crop type.

reset_mass_attributes_after_loss(self, crop: HarvestedCrop, dry_matter_loss: float, moisture_loss: float)

Resets mass related attributes after loss of dry matter and/or moisture.

record_stored_crops(self)

Records information about total mass and nutrient content of the stored crops.

calculate_dry_matter_loss_to_gas(dry_matter: float, time_in_silo: int)

Calculates the dry matter loss to gas.

calculate_bale_density(initial_dry_matter: float)

Calculates the density of a bale.

recalculate_nutrient_percentage(

initial_nutrient_percentage: float, loss_coefficient: float, dry_matter_loss: float, initial_dry_matter: float

)

Recalculates a single nutrient percentage after dry matter loss.

__init__(capacity: float = inf)#
property stored_mass: float#

The total mass (kg) of currently stored crops

receive_crop(crop: HarvestedCrop) None#

Receives a harvested crop and adds it to the storage.

Parameters#

cropHarvestedCrop

The harvested crop to be added to the storage.

Returns#

None

Raises#

NotImplementedError

If the storage’s acceptable crops is not populated.

ValueError

If the crop’s category is not compatible with the storage.

Exception

If adding the crop exceeds the storage’s capacity.

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

Processes the degradations and losses of nutrients and dry matter in the stored crops.

Parameters#

weatherWeather

Weather instance containing all weather information for the simulation.

timeRufasTime

RufasTime instance tracking the current time of the simulation.

Notes#

This method also records the total amount of gaseous dry matter loss happened from all stored crops.

project_degradations(crops: list[HarvestedCrop], weather: Weather, time: RufasTime) list[HarvestedCrop]#

Projects the state of crops currently stored at a given future date.

Parameters#

cropslist[HarvestedCrop]

List of HarvestedCrops to project degradations for.

weatherWeather

Weather instance containing all weather information for the simulation.

timeRufasTime

RufasTime instance containing the date at which the state of the stored crops should be projected.

Returns#

list[HarvestedCrop]

Crops in the state they are projected to be in at the given date.

_calculate_degradation_values(crop: HarvestedCrop, weather: Weather, time: RufasTime) dict[str, Any]#

Calculates the loss from the given crop and state of the remaining crop mass.

Parameters#

cropHarvestedCrop

Crop for which degradations are being calculated.

weatherWeather

Weather instance containing all weather information for the simulation.

timeRufasTime

RufasTime instance tracking the current time of the simulation.

Returns#

dict[str, Any]

Mapping the attributes of the crop after degradation to their values.

give_feed(amount: float, crop_type: CropType) None#

Gives out a specified amount of feed of a certain crop type.

Parameters#

amountfloat

The amount of feed to give out.

crop_typeCropType

The type of crop to give out.

remove_empty_crops() None#

Removes all crops with no dry matter mass left.

_calculate_mass_attributes_after_loss(crop: HarvestedCrop, dry_matter_loss: float, moisture_loss: float) dict[str, float]#

Resets the dry mass, fresh mass, and dry matter percentage attributes in a stored crop after loss of both dry matter and moisture.

Parameters#

cropHarvestedCrop

The stored crop that has lost dry matter.

dry_matter_lossfloat

Amount of dry matter the crop lost on the current day (kg).

moisture_lossfloat

Amount of moisture (water) the crop lost on the current day (kg).

Returns#

dict[str, float]

Fresh mass and dry matter percentage of the crop after loss (kg and percentage, respectively).

Notes#

The amount of dry matter mass remaining is calculated first, then the remaining amount of fresh mass. After these two attributes have been set, the dry matter percentage is recalculated and set.

record_stored_crops() None#

Records the total mass and nutrient amounts held in storage.

_get_total_nutritive_amount(nutrient_name: str) float#

Calculates the total amount of the specifed nutrient that is currently held in storage.

Parameters#

nutrient_namestr

The name of the target nutrient attribute in HarvestedCrop.

Returns#

float

Total amount of the target nutrient in the stored crops (kg).

calculate_dry_matter_loss_to_gas(crop: HarvestedCrop, weather_conditions: list[CurrentDayConditions], time: RufasTime) float#

Calculates the dry matter loss to gas, specific to dry matter loss from fermentation.

Parameters#

cropHarvestedCrop

The stored crop that is losing dry matter.

weather_conditionslist[CurrentDayConditions]

List of daily weather conditions over which dry matter loss will be calculated.

timeRufasTime

RufasTime instance containing the time that loss should be processed up to.

Returns#

float

The amount of dry matter lost to gas, specific to fermentation (kg).

References#

Notes#

If the ambient temperature or dry matter percentage of the crop do not fall within the acceptable ranges, then no dry matter loss occurs. Alfalfa uses different parameters and limits for calculating dry matter loss, but the structure of the loss equation remains the same.

Note that the current time is not needed for calculating the dry matter loss to fermentation, but it allows the interface to remain uniform across all implementations of calculate_dry_matter_loss_to_gas.

_get_conditions(last_degradations_time: date, current_time: RufasTime, weather: Weather) list[CurrentDayConditions]#

Gets the weather conditions for the days between the current time and the time that degradations were last processed.

Parameters#

last_degradations_timedate

The last day a crop’s degradations were processed.

current_timeRufasTime

RufasTime instance containing the current time of the simulation.

weatherWeather

Weather instance containing all weather data for the simulation.

Notes#

If the current day is the same as or before the last day that the crop was degraded, no weather conditions will be returned.

_process_moisture_loss(time: RufasTime, loss_period: int, final_moisture_percentage: float) None#

Deducts and records the moisture that has been lost from all crops in storage since the last time degradations were processed.

Parameters#

timeRufasTime

RufasTime instance containing the time that loss should be processed up to.

loss_periodint

Number of days over which moisture is lost after crop is stored.

final_moisture_percentagefloat

Percentage of fresh mass that is moisture in the crop after all moisture loss has occurred.

_project_moisture_loss(crops: list[HarvestedCrop], time: RufasTime, loss_period: int, final_moisture_percentage: float) list[HarvestedCrop]#

Creates a HarvestedCrop with projected moisture loss accounted for.

Parameters#

croplist[HarvestedCrop]

HarvestedCrops to project moisture loss for.

timeRufasTime

RufasTime instance containing the time that loss should be processed up to.

loss_periodint

Number of days over which moisture is lost after crop is stored.

final_moisture_percentagefloat

Percentage of fresh mass that is moisture in the crop after all moisture loss has occurred.

Returns#

list[HarvestedCrop]

Crops with the projected moisture loss incorporated into their values.

_calculate_values_after_moisture_loss(crop: HarvestedCrop, time: RufasTime, loss_period: int, final_moisture_percentage: float) dict[str, float]#

Calculates amount of moisture lost from a crop in storage since the last time degradations were processed.

Parameters#

cropHarvestedCrop

Crop for which moisture loss will be calculated.

timeRufasTime

RufasTime instance containing the time that loss should be calculated up to.

loss_periodint

Number of days over which moisture is lost after crop is stored.

final_moisture_percentagefloat

Percentage of fresh mass that is moisture in the crop after all moisture loss has occurred.

Returns#

dict[str, float]

Mapping of the crop’s mass values after moisture loss and the amount of moisture it lost.

_calculate_moisture_loss(crop: HarvestedCrop, time: date, loss_period: int, final_moisture_percentage: float) float#

Calculates the moisture lost from a crop since it was stored.

Parameters#

cropHarvestedCrop

The crop to process moisture loss in.

timedate

The date that loss should be processed up to.

loss_periodint

Number of days over which moisture is lost after crop is stored.

final_moisture_percentagefloat

Percentage of moisture left in the crop after all moisture loss has occurred.

Returns#

float

Moisture loss from the crop that occurred in the first 30 days of storage (kg).

References#

recalculate_nutrient_percentage(initial_nutrient_percentage: float, loss_coefficient: float, dry_matter_loss: float, initial_dry_matter: float) float#

Calculates the updated relative nutrient percentage after dry matter has been lost from a stored crop.

Parameters#

initial_nutrient_percentagefloat

Nutrient percentage in stored crop before loss.

loss_coefficientfloat

Fractional loss coefficient that regulates how quickly this nutrient is lost.

dry_matter_lossfloat

Amount of dry matter lost from stored crop in kg.

initial_dry_matterfloat

Amount of dry matter stored crop contained before loss in kg.

Returns#

float

The nutrient percentage after dry matter loss.

Notes#

When stored crops lose dry matter, they do not always lose proportional amounts of the nutrients they are composed of. In this case, the concentration of the nutrient within the dry matter changes which is why it must be recalculated. If a negative nutrient percentage would be calculated after losing dry matter, the percentage is calculated to be 0 and a warning is logged to the OuputManager. If a negative nutrient percentage would have been calculated, a warning is logged to the Output Manager that the method is preventing this. If all dry matter is lost from the stored crop, the updated percentage of the nutrient in the dry matter is set as 0 to prevent a division by zero error.