Skip to main content

agrifoodpy-shocks

AgriFoodPy-shocks is an extension package for resilience modeling in agrifood systems, compatible with the AgriFoodPy framework. These models simulate the effects of food system shocks, including resilience building interventions and vulnerability exposing crises. The effects include food supply and availability perturbations and land use change.

Installation

agrifoodpy-shocks can be installed directly from this repository using pip:

pip install git+https://github.com/BAFR-UK/agrifoodpy-shocks.git

Usage

The models included here are compatible with the AgriFoodPy framework and can be included in a pipeline using the node structure through a Python script interface or using a YAML pipeline configuration file.

Python Scripting

Python scripting provides a flexible environment to define fine tuned inputs for the shock registering functions.

from agrifoodpy_shocks.resilience import (
    initialize_resilience_datasets,
    register_intervention,
    register_crisis,
    process_shocks
)

# Create pipeline object
fs = Pipeline()

# Load datablock data
...

# Add node to initialize resilience datasets and register interventions
fs.add_node(
    function=initialize_resilience_datasets,
    name="Initialize",
    params={
        "fbs": "food",
        "channels":["Bio", "Log", "Lab", "Mark"]},
        "return_key":["resilience", "vulnerability", "severity"])

# Define resilience array to be passed to the node constructor
resilience_array = xr.DataArray(
    data= [0.8, 0.0, 0.0, 0.0]
    coords= {"channels":["Bio", "Log", "Lab", "Mark"]},
    dims= ["channels"]
)

# Add node to register intervention
fs.add_node(
    function=register_intervention,
    name="Drought-resistant crops",
    params= {
        "items":"Wheat",
        "element":"production",
        "resilience":resilience_array,
        "resilience_dataset":"resilience",
        "return_key":"resilience" 
        })

# Define time dependent severity array to be passed to node constructor 
years = np.arange(2020, 2050)
severity_array = xr.DataArray(
    data= np.zeros(len(years))
    coords= {"Year":years},
    dims= ["Year"]
)

vulnerability_array = xr.DataArray(
    data= [0.7, 0.0, 0.2, 0.0]
    coords= {"channels":["Bio", "Log", "Lab", "Mark"]},
    dims= ["channels"]
)

# Add node to register crisis
fs.add_node(
    function=register_crisis,
    name="Severe drought",
    params= {
        "items":"Wheat",
        "element":"production",
        "vulnerability":vulnerability_array,
        "severity":severity_array,
        "vulnerability_dataset":"resilience",
        "severity_dataset":"severity",
        "return_key":"resilience" 
        })

Pipeline configuration YAML

The YAML configuration file approach allows for easy to read and share pipeline definitions.

#example.yaml

nodes:
...

  # Interventions
  - function: agrifoodpy_shocks.resilience.register_intervention
    name: "Drought-resistant crops"
    params:
      items: "Wheat"
      element: "production"
      adoption: !scale.linear [2020, 2020, 2030, 2050, 0.0, 1.0]
      resilience: !xarray.DataArray
        data: [0.8, 0.0, 0.0, 0.0]
        coords: {channels: ["Bio", "Log", "Lab", "Mark"]}
        dims: ["channels"]
      resilience_dataset: "resilience"
      return_key: "resilience"


  # Crises
  - function: agrifoodpy_shocks.resilience.register_crisis
    name: "Severe drought"
    params:
      items: "Wheat"
      element: "production"
      # fbs: "food"
      severity_dataset: "severity"
      vulnerability_dataset: "vulnerability"
      severity: !scale.piecewise_constant
        years: [2020, 2025, 2028, 2030, 2050]
        values: [0.0, 0.5, 0.2, 0.0, 0.0]
      vulnerability: !xarray.DataArray [
        [0.9, 0.0, 0.1, 0.0],
        {channels: ["Bio", "Log", "Lab", "Mark"]}, "channels"]
      return_key: ["vulnerability", "severity"]

The examples folder contains complete examples and notebooks to execute end to end simulations of shocks to a food balance sheet.

Contributing

AgriFoodPy and AgriFoodPy-shocks are open-source projects which aim at improving the transparency of evidence base food system interventions and policy making. As such, we are happy to hear the input and ideas from the community.

If you want to contribute, have a look at the discussions page or open a new issue.

For a comprehensive guide, please refer to the contributing guidelines in the main AgriFoodPy repository to open a pull request to contribute new functionality.

Metadata

Release files for agrifoodpy-shocks 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agrifoodpy-shocks 0.1.0
File Size Uploaded
agrifoodpy_shocks-0.1.0.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agrifoodpy-shocks 0.1.0
File Interpreter ABI Platform
agrifoodpy_shocks-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 kB

Release files / agrifoodpy_shocks-0.1.0.tar.gz

Download URL agrifoodpy_shocks-0.1.0.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
92b1c565329160ad6a580f1c27f740fc0690a67ff9f518c7915a554155ebedc7
BLAKE2b-256 checksum
How to use checksums
aa55252b4e2022eb49da17cd01a70c5985deb12f0dbf11a8e5fc6f89ce5cf7a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / agrifoodpy_shocks-0.1.0-py3-none-any.whl

Download URL agrifoodpy_shocks-0.1.0-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4468d768f4afc68390cea4b202aabb7f061f341e02740c59bee600773585d08
BLAKE2b-256 checksum
How to use checksums
a76b090bfa732fc5192a860fccdd01f28db2c8f5ad33cffb5f0c3487513cb6aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page