agrifoodpy.food.model
Module for food intervention models and interfaces with external packages
Functions
|
Scales items in a Food Balance Sheet, while optionally maintaining |
|
Scales quantities in a food balance sheet using a conversion |
|
Self-sufficiency ratio |
|
Import-dependency ratio |
Module Contents
- agrifoodpy.food.model.balanced_scaling(fbs, scale, element, items=None, constant=False, origin=None, add_to_origin=True, elasticity=None, fallback=None, add_to_fallback=True, out_key=None, datablock=None)
Scales items in a Food Balance Sheet, while optionally maintaining total quantities
Scales selected item quantities on a Food Balance Sheet, with the option to keep the sum over an element DataArray constant. Changes can be propagated to a set of origin FBS elements according to an elasticity parameter.
- Parameters:
fbs (xarray.Dataset) – Input food balance sheet Dataset
scale (float) – Scaling parameter after full adoption
element (string) – Name of the DataArray to scale
items (list, optional) – List of items to scaled in the food balance sheet. If None, all items are scaled and ‘constant’ is ignored
constant (bool, optional) – If set to True, the sum of element remains constant by scaling the non selected items accordingly
origin (string, list, optional) – Names of the DataArrays which will be used as source for the quantity changes. Any change to the “element” DataArray will be reflected in this DataArray
add_to_origin (bool, array, optional) – Whether to add or subtract the difference from the respective origins
elasticity (float, array, optional) – Relative fraction of the total difference to be assigned to each origin element. Values are not normalized.
fallback (string) – Name of the DataArray to use as fallback in case the origin quantities fall below zero
add_to_fallback (bool, optional) – Whether to add or subtract the difference below zero in the origin DataArray to the fallback array.
out_key (string, tuple) – Output datablock path to write results to. If not given, input path is overwritten
datablock (dict, optional) – Dictionary containing data
- Returns:
data – Food balance sheet Dataset with scaled values.
- Return type:
xarray.Dataarray
- agrifoodpy.food.model.fbs_convert(fbs, convertion_arr, out_key=None, datablock=None)
Scales quantities in a food balance sheet using a conversion dataarray, dataset, or scaling factor.
- Parameters:
fbs (str, xarray.Dataset) – Datablock paths to the food balance sheet datasets or the datasets themselves.
convertion_arr (str, xarray.DataArray, tuple or float) – Datablock path to the conversion array, datablock-key tuple, or the array or float itself.
out_key (str, list) – Datablock key of the resulting dataset to be stored in the datablock.
datablock (Dict) – Dictionary containing data.
- Returns:
Updated datablock if a datablock is provided.
xarray.Dataset with converted quantities if no datablock is provided.
- Return type:
dict or xarray.Dataset
- agrifoodpy.food.model.SSR(fbs, items=None, per_item=False, production='production', imports='imports', exports='exports', out_key=None, datablock=None)
Self-sufficiency ratio
Self-sufficiency ratio (SSR) or ratios for a list of item imports, exports and production quantities.
- Parameters:
fbs (xarray.Dataset) – Input Dataset containing an “Item” coordinate and, optionally, a “Year” coordinate.
items (list, optional) – list of items to compute the SSR for from the food Dataset. If no list is provided, the SSR is computed for all items.
per_item (bool, optional) – Whether to return an SSR for each item separately. Default is false
production (string, optional) – Name of the DataArray containing the production data
imports (string, optional) – Name of the DataArray containing the imports data
exports (string, optional) – Name of the DataArray containing the exports data
datablock (dict, optional) – Dictionary containing the food balance sheet Dataset.
- Returns:
data – Self-sufficiency ratio or ratios for the list of items, one for each year of the input food Dataset “Year” coordinate.
- Return type:
xarray.Dataarray
- agrifoodpy.food.model.IDR(fbs, items=None, per_item=False, imports='imports', production='production', exports='exports', out_key=None, datablock=None)
Import-dependency ratio
Import-ependency ratio (IDR) or ratios for a list of item imports, exports and production quantities.
- Parameters:
fbs (xarray.Dataset) – Input Dataset containing an “Item” coordinate and, optionally, a “Year” coordinate.
items (list, optional) – list of items to compute the IDR for from the food Dataset. If no list is provided, the IDR is computed for all items.
per_item (bool, optional) – Whether to return an IDR for each item separately. Default is false.
imports (string, optional) – Name of the DataArray containing the imports data
exports (string, optional) – Name of the DataArray containing the exports data
production (string, optional) – Name of the DataArray containing the production data
datablock (dict, optional) – Dictionary containing the food balance sheet Dataset.
- Returns:
data – Import-dependency ratio or ratios for the list of items, one for each year of the input food Dataset “Year” coordinate.
- Return type:
xarray.Datarray