agrifoodpy.food.model ===================== .. py:module:: agrifoodpy.food.model .. autoapi-nested-parse:: Module for food intervention models and interfaces with external packages Functions --------- .. autoapisummary:: agrifoodpy.food.model.balanced_scaling agrifoodpy.food.model.fbs_convert agrifoodpy.food.model.SSR agrifoodpy.food.model.IDR Module Contents --------------- .. py:function:: 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. :param fbs: Input food balance sheet Dataset :type fbs: xarray.Dataset :param scale: Scaling parameter after full adoption :type scale: float :param element: Name of the DataArray to scale :type element: string :param items: List of items to scaled in the food balance sheet. If None, all items are scaled and 'constant' is ignored :type items: list, optional :param constant: If set to True, the sum of element remains constant by scaling the non selected items accordingly :type constant: bool, optional :param origin: 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 :type origin: string, list, optional :param add_to_origin: Whether to add or subtract the difference from the respective origins :type add_to_origin: bool, array, optional :param elasticity: Relative fraction of the total difference to be assigned to each origin element. Values are not normalized. :type elasticity: float, array, optional :param fallback: Name of the DataArray to use as fallback in case the origin quantities fall below zero :type fallback: string :param add_to_fallback: Whether to add or subtract the difference below zero in the origin DataArray to the fallback array. :type add_to_fallback: bool, optional :param out_key: Output datablock path to write results to. If not given, input path is overwritten :type out_key: string, tuple :param datablock: Dictionary containing data :type datablock: dict, optional :returns: **data** -- Food balance sheet Dataset with scaled values. :rtype: xarray.Dataarray .. py:function:: 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. :param fbs: Datablock paths to the food balance sheet datasets or the datasets themselves. :type fbs: str, xarray.Dataset :param convertion_arr: Datablock path to the conversion array, datablock-key tuple, or the array or float itself. :type convertion_arr: str, xarray.DataArray, tuple or float :param out_key: Datablock key of the resulting dataset to be stored in the datablock. :type out_key: str, list :param datablock: Dictionary containing data. :type datablock: Dict :returns: - Updated datablock if a datablock is provided. - xarray.Dataset with converted quantities if no datablock is provided. :rtype: dict or xarray.Dataset .. py:function:: 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. :param fbs: Input Dataset containing an "Item" coordinate and, optionally, a "Year" coordinate. :type fbs: xarray.Dataset :param items: list of items to compute the SSR for from the food Dataset. If no list is provided, the SSR is computed for all items. :type items: list, optional :param per_item: Whether to return an SSR for each item separately. Default is false :type per_item: bool, optional :param production: Name of the DataArray containing the production data :type production: string, optional :param imports: Name of the DataArray containing the imports data :type imports: string, optional :param exports: Name of the DataArray containing the exports data :type exports: string, optional :param datablock: Dictionary containing the food balance sheet Dataset. :type datablock: dict, optional :returns: **data** -- Self-sufficiency ratio or ratios for the list of items, one for each year of the input food Dataset "Year" coordinate. :rtype: xarray.Dataarray .. py:function:: 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. :param fbs: Input Dataset containing an "Item" coordinate and, optionally, a "Year" coordinate. :type fbs: xarray.Dataset :param items: list of items to compute the IDR for from the food Dataset. If no list is provided, the IDR is computed for all items. :type items: list, optional :param per_item: Whether to return an IDR for each item separately. Default is false. :type per_item: bool, optional :param imports: Name of the DataArray containing the imports data :type imports: string, optional :param exports: Name of the DataArray containing the exports data :type exports: string, optional :param production: Name of the DataArray containing the production data :type production: string, optional :param datablock: Dictionary containing the food balance sheet Dataset. :type datablock: dict, optional :returns: **data** -- Import-dependency ratio or ratios for the list of items, one for each year of the input food Dataset "Year" coordinate. :rtype: xarray.Datarray