DemandAndConversions
The DemandAndConversions module takes parameters for e.g. population, diets, demand for non-food and export uses and waste and conversion factors to calculate total national demand for crop (crop_prod) and animal products (animal_prod), by-products (by_prod) and crop residues (crop_resid) as well as generated by-products, wastes and import demand.
Supply and demand for dairy fats are balanced with the _fix_cream_balance() helper function that induce exports of low- or high-fat dairy products to resolve the balance.
%%{init: {
"flowchart": {
"nodeSpacing": 10,
"rankSpacing": 20,
"padding": 3,
"curve": "linear"
},
"themeVariables": {
"fontSize": "12px"
}
}}%%
flowchart TD
%% -------------------------
%% Main orchestration
%% -------------------------
A["<b>DemandAndConversions</b>"]:::mod_main --> C["<b>.calculate()</b>"]:::method
C --> GP["<b>.get_population()</b>"]:::method
FD["<b>.calculate_food_demand()</b>"]:::method
NFX["<b>.get_non_food_and_export_demand()</b>"]:::method
%% Resolve recipes for multiple demand tables
RR["<b>.resolve_recipies()</b>"]:::method
W["<b>.calculate_waste()</b>"]:::method
NS["<b>.calculate_nutrient_supply()</b>"]:::method
PD["<b>.calculate_product_demand_and_by_products()</b>"]:::method
%% -------------------------
%% Population
%% -------------------------
P_POP["<b>DemandAndConversions.par.</b>
population, population_region"]:::param --> GP
GP --> DA_POP["<b>DemandAndConversions.data_attr.</b>
population, population_per_region"]:::data
DA_POP --> FD
%% -------------------------
%% Food demand (diet -> kg/year by origin & production system)
%% -------------------------
P_CONS["<b>DemandAndConversions.par.</b>
consumption, share_imported, share_in_prod_system"]:::param --> FD
FD --> DA_FD["<b>DemandAndConversions.data_attr.</b>
food_demand"]:::data
DA_FD ---> W
DA_FD ---> NS
%% -------------------------
%% Non-food + Export demand
%% -------------------------
P_NFX["<b>DemandAndConversions.par.</b>
non_food_demand, export_demand"]:::param --> NFX
NFX ---> DA_NFX["<b>DemandAndConversions.data_attr.</b>
non_food_demand, export_demand"]:::data
%% -------------------------
%% Waste calculation (stage losses)
%% -------------------------
P_WASTE["<b>DemandAndConversions.par.</b>
waste_share"]:::param --> W
W ---> DA_FTP["<b>DemandAndConversions.data_attr.</b>
food_demand_to_processing, waste"]:::data
%% -------------------------
%% Nutrient supply (diet composition)
%% -------------------------
P_COMP["<b>DemandAndConversions.par.</b>
composition"]:::param --> NS
NS --> DA_NDA_NS["<b>DemandAndConversions.data_attr.</b>
nutrient_supply"]:::data
%% -------------------------
%% Recipe resolution (compound foods -> ingredients)
%% -------------------------
RR --> PD
P_REC["<b>DemandAndConversions.par.</b>
recipie"]:::param --> RR
%% -------------------------
%% Product demand & by-products
%% -------------------------
P_CF["<b>DemandAndConversions.par.</b>
conv_factor_main, conv_factor_by"]:::param --> PD
%% Inputs to demand aggregation
DA_FTP --> PD
DA_NFX --> PD
%% Outputs
PD ---> DA_CPD["<b>DemandAndConversions.data_attr.</b>
crop_prod_demand, animal_prod_demand, crop_resid_demand, by_prod_demand,
by_products, by_prod_per_crop_prod, by_prod_per_animal_prod"]:::data
%% (Optional) internal helper logic (not class methods)
PD_H["_get_demand()
_fix_cream_balance()
_attribute_secondary_by_prod()
"]:::helper --> PD
%% -------------------------
%% Styles
%% -------------------------
classDef mod_main fill:#509e2f80,stroke:#203f13,stroke-width:2px,font-size:13,color:#203f13;
classDef mod_mgmt fill:#6ad1e380,stroke:#125560,stroke-width:2px,font-size:13,color:#125560;
classDef mod_opt fill:#d9d9d680,stroke:#43433e,stroke-width:2px,font-size:13,color:#43433e;
classDef data fill:#fee8c880,stroke:#b30000,stroke-width:0.5px,font-size:11,color:#b30000;
classDef param fill:#d7f4ee80,stroke:#165044,stroke-width:0.5px,font-size:11,color:#165044;
classDef method fill:#ffffff80,stroke:#000000,stroke-width:1px,font-size:12,color:#000000;
classDef helper fill:#f5f5f580,stroke:#616161,stroke-width:2px,font-size:12,color:#212121;
classDef settings fill:#ffd5f680,stroke:#aa0088,stroke-width:1px,font-size:11,color:#aa0088;
Hold "Alt" / "Option" to enable pan & zoom
View Docstring
Signature:
DemandAndConversions(par: ParameterRetriever)
Docstring:
Class that calculates demand for domestic and imported crop and animal products, as
well as generated food waste and by-products etc. A per capita diet is defined in
the parameter Excel sheet along with parmeters for import shares, conversion
factors, waste levels, etc.
Parameters
----------
par : ParameterRetriever object
Attributes set on init
----------------------
None
Attributes set by FoodDemand.calculate()
----------------------------------------
population : int [millions]
food_demand : pandas.DataFrame [kg/year]
Demand for food per production system and origin (domestic, imported)
food_demand_to_processing : pandas.DataFrame [kg/year]
Food demand after accounting for household, retail and processing wastes
crop_prod_demand : pandas.DataFrame
crop_by_products : pandas.DataFrame
animal_prod_demand : pandas.DataFrame
animal_by_products : pandas.DataFrame
waste : pandas.DataFrame [kg/year]
Generated waste at household, retail and processing. Only includes domestically
generated waste assuming that processing waste for imported foods occur abroad.
File: CIBUSmod/main_modules/demand_and_conversions.py