RUFAS.routines.manure.manure_nutrients.manure_nutrient_manager module#
- class RUFAS.routines.manure.manure_nutrients.manure_nutrient_manager.ManureNutrientManager#
Bases:
object
- __init__() None #
Initialize the manure nutrient manager.
- get_values(manure_type: ManureType) ManureNutrients #
Get the current nutrient values stored in the manager by manure type.
Parameters#
- manure_typeManureType
The type of manure.
Returns#
- ManureNutrients
The current nutrient values stored in the manager for the provided ManureType.
Raises#
- KeyError
If the manure type is not in the list of acceptable manure types.
- add_nutrients(nutrients: ManureNutrients) None #
Add or update nutrients to the manager from the manure module by manure type.
Parameters#
- nutrientsManureNutrients
The nutrients to be added to or updated in the manager.
Returns#
None
- request_nutrients(request: NutrientRequest) tuple[NutrientRequestResults | None, bool] #
Handle the request for specific nutrients from the crop and soil module.
This method evaluates the nutrient request made by considering both nitrogen and phosphorus quantities desired for the specified manure type. It calculates the projected manure mass that would satisfy the request and checks against the nutrients available in the manager.
If the request can be fulfilled either partially or wholly, the corresponding amount of nutrients is subtracted from the manager’s internal bookkeeping for the manure type. The method then returns the results of the nutrient request, which detail the amounts of nutrients that can be provided to fulfill the request. If the request cannot be fulfilled at all, the method will return None.
Parameters#
- requestNutrientRequest
The specific nutrient request, including quantities of nitrogen and phosphorus and manure type.
Returns#
- tuple[NutrientRequestResults | None, bool]
A tuple containing the results of the nutrient request and a boolean indicating whether additional manure would be needed to fulfill the request. If the request cannot be fulfilled at all, the first element of the tuple will be None.
- _evaluate_nutrient_request(request: NutrientRequest) tuple[NutrientRequestResults | None, bool] #
Evaluate a nutrient request. The method calculates the projected manure mass based on the request for nitrogen and phosphorus for a specific manure type. It then checks if the projected manure mass can be fulfilled by the available nutrients for that manure type in the manager.
Parameters#
- requestNutrientRequest
The request for nutrients.
Returns#
- tuple[NutrientRequestResults | None, bool]
A tuple containing the results of the nutrient request and a boolean indicating whether additional manure would be needed to fulfill the request. If the request cannot be fulfilled at all, the first element of the tuple will be None.
- static _calculate_projected_manure_mass(request_nutrient: float, nutrient_composition: float) float #
Calculate the projected manure mass based on the nutrient requested and the nutrient’s composition in the manure.
The projected manure mass is calculated by dividing the nutrient request by the nutrient composition. This represents the total manure mass needed to fulfill the nutrient request.
Parameters#
- request_nutrientfloat
The quantity of nutrient requested. Must be a non-negative value.
- nutrient_compositionfloat
The proportion of the nutrient in the manure, represented as a fraction in the range [0, 1].
Returns#
- float
The projected manure mass needed to fulfill the nutrient request. Returns 0.0 if the nutrient composition is zero (indicating that the nutrient is not present in the manure).
Raises#
- ValueError
If the request for nutrient is negative. If the nutrient composition is not in the range [0, 1].
- static _select_projected_manure_mass(projected_manure_masses: list[float]) float #
Select the smallest positive projected manure mass from the given list of projected manure masses.
This method works by first checking if any of the projected manure masses are negative and raises a ValueError if this is the case. However, if all values are zero, it returns zero. Otherwise, it returns the smallest positive value.
Parameters#
- projected_manure_masseslist[float]
The list of projected manure masses.
Returns#
- float
The projected manure mass.
Raises#
- ValueError
If any of the projected manure masses is negative.
- _create_nutrient_request_results(projected_manure_mass: float, manure_type: ManureType) NutrientRequestResults #
Create a NutrientRequestResults object based on the given projected manure mass and manure type.
Note that this method does not check if what is currently available in the manager is enough to fulfill the projected manure mass. It simply creates a NutrientRequestResults object based on the projected manure mass by multiplying the projected manure mass with the nutrient compositions.
Parameters#
- projected_manure_massfloat
The projected manure mass.
Returns#
- NutrientRequestResults
The results of the nutrient request. See
NutrientsRequestResults
for details.
Raises#
- ValueError
If the projected manure mass is negative.
- _remove_nutrients(results: NutrientRequestResults, manure_type: ManureType) None #
Remove nutrients from the manager based on the results of a nutrient request by manure type.
Parameters#
- resultsNutrientRequestResults
The results of a nutrient request. See
NutrientsRequestResults
for details.
Returns#
None
Raises#
- ValueError
If any of the nutrients in the results is greater than what is currently available in the manager.