Code Monkey home page Code Monkey logo

agrifoodpy's Introduction

AgriFoodPy

Documentation Status Tests

AgriFoodPy is a collection of methods for manipulating and modelling agrifood data. It provides modelling for a variety of aspects of the food system, including food consumption paterns, environmental impact and emissions data, population and land use. It also provides an interface to run external models by using xarray as the data container.

In addition to this package, we have also pre-packaged some datasets for use with agrifood. These can be found on the agrifoodpy_data repository https://github.com/FixOurFood/agrifoodpy-data

Installation:

AgriFoodPy can be installed using pip, by running

pip install agrifoodpy

UK data to test the package is available from the agrifoodpy_data repository which currently can be installed using

pip install git+https://github.com/FixOurFood/agrifoodpy-data.git@importable

Usage:

Each of the four basic modules on AgriFoodPy (Food, Land, Impact, Population) has its own set of basic array manipulation functionality, a set of modelling methods to extract basic metrics from datasets, and interfaces with external modelling packages and code.

Agrifoodpy employs xarray accesors to provide additional functionality on top of the array manipulation provided by xarray.

Basic usage of the accesors depend on the type of array being manipulated. The following examples uses the food module with the importable UK data mentioned above:

# import the FoodBalanceSheet accessor and FAOSTAT from agrifoodpy_data
from agrifoodpy.food.food import FoodBalanceSheet
from agrifoodpy_data.food import FAOSTAT
import matplotlib.pyplot as plt

# Extract data for the UK (Region=229)
food_uk = FAOSTAT.sel(Region=229)

# Compute the Self-sufficiency ratio using the fbs accessor SSR function
SSR = food_uk.fbs.SSR(per_item=True)

# Plot the results using the fbs accessor plot_years function
SSR.fbs.plot_years()
plt.show()

To use the specific models and interfaces to external code, these need to be imported

# import the FoodBalanceSheet accessor and FAOSTAT from agrifoodpy_data
from agrifoodpy.food.food import FoodBalanceSheet
from agrifoodpy_data.food import FAOSTAT
import agrifoodpy.food.model as food_model
import matplotlib.pyplot as plt

# Extract data for the UK in 2020 (Region=229, Year=2020)
food_uk = FAOSTAT.sel(Region=229, Year=2020)

# Scale consumption of meat to 50%, 
food_uk_scaled = food_model.balanced_scaling(food_uk,
                                            items=2731,
                                            element="food",
                                            origin="production",
                                            scale=0.5,
                                            constant=True)

# Plot bar summary of resultant food quantities
food_uk_scaled.fbs.plot_bars(elements=["production","imports"],
                            inverted_elements=["exports","food"])
plt.show()

In he future, we plan to implement a pipeline manager to automatize certain aspects of the agrifood execution, and to simulate a comprehensive model where all aspects of the food system are considered simultaneously.

Examples and documentation

Examples demonstrating the functionality of AgriFoodPy can be the found in the package documentation. These include the use of accessors to manipulate data and access to basic models.

Contributing

AgriFoodPy is an open-source project which aims 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 to open a pull request to contribute new functionality

agrifoodpy's People

Contributors

jucordero avatar sarahbridle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.