MAgPIE
Model of Agricultural Production and its Impact on the Environment.
https://github.com/magpiemodel/magpie
Category: Consumption
Sub Category: Agriculture and Nutrition
Keywords
gams land magpie pik
Last synced: about 19 hours ago
JSON representation
Repository metadata
Model of Agricultural Production and its Impact on the Environment (MAgPIE) - model code
- Host: GitHub
- URL: https://github.com/magpiemodel/magpie
- Owner: magpiemodel
- License: other
- Created: 2018-05-30T11:00:09.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-10-23T09:44:38.000Z (10 days ago)
- Last Synced: 2025-10-26T18:48:14.146Z (7 days ago)
- Topics: gams, land, magpie, pik
- Language: GAMS
- Homepage:
- Size: 30.6 MB
- Stars: 114
- Watchers: 17
- Forks: 240
- Open Issues: 11
- Releases: 41
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Citation: CITATION.cff
- Zenodo: .zenodo.json
README.md
MAgPIE - Modular open source framework for modeling global land-systems
WHAT IS MAGPIE?
The Model of Agricultural Production and its Impact on the Environment (MAgPIE)
is a modular open-source framework for modeling global land-systems, which
explicitly accounts for both agriculture and forestry. It is coupled to the
grid-based dynamic vegetation model LPJmL, with a spatial resolution of 0.5°x0.5°.
MAgPIE takes regional economic conditions such as demand for agricultural commodities
and timber products, technological development, and production costs into account,
as well as spatially explicit data on potential crop yields, forest growth,
and land and water constraints (from LPJmL). Based on these, the model derives
specific land use patterns, crop yields, timber yields, and total costs of
agricultural and forestry production for each grid cell. The objective function of
the land use model is to minimize total cost of production for a given amount of
regional food, bioenergy, and timber demand. Regional food energy demand is defined
for an exogenously given population in 10 food energy categories, based on regional
diets. Future trends in food demand are derived from a cross-country regression analysis,
based on future scenarios on GDP and population growth.
https://www.pik-potsdam.de/research/projects/activities/land-use-modelling/magpie
DOCUMENTATION
A framework description paper has been published in
Geoscientific Model Development (GMD): https://doi.org/10.5194/gmd-12-1299-2019
The model documentation for version 4.13.0 can be found at
https://rse.pik-potsdam.de/doc/magpie/4.13.0/
A most recent version of the documentation can also be extracted from the
model source code via the R package goxygen
(https://github.com/pik-piam/goxygen). To extract the documentation, install the
package and run the main function (goxygen) in the main folder of the model.
The resulting documentation can be found in the folder "doc".
Please find a set of tutorials here https://magpiemodel.github.io/tutorials.
This guide will give you a brief technical introduction in how to install, run and use the model
and how to analyse the model output.
Please pay attention to the MAgPIE Coding Etiquette when you modify the code.
The Coding Etiquette you find at the beginning of the documentation mentioned above.
The Coding Etiquette explains also the naming conventions and other
structural characteristics.
COPYRIGHT
Copyright 2008-2025 Potsdam Institute for Climate Impact Research (PIK)
LICENSE
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License or later. You should
have received a copy of the GNU Affero General Public License along with this
program. See the LICENSE file in the root directory. If not, see
https://www.gnu.org/licenses/agpl.txt
Under Section 7 of AGPL-3.0, you are granted additional permissions described
in the MAgPIE License Exception, version 1.0 (see LICENSE file).
NOTES
Following the principles of good scientific practice it is recommended
to make the source code available in the events of model based publications
or model-based consulting.
When using a modified version of MAgPIE which is not identical to versions
in the official main repository at https://github.com/magpiemodel add a suffix
to the name to allow distinguishing versions (format MAgPIE-suffix).
HARDWARE REQUIREMENTS
The model is quite resource heavy and works best on machines with high CPU clock
and memory. Recommended is a machine with at least 16GB of memory and a Core i7 CPU or similar.
HOW TO INSTALL
Commands formatted as code should generally be run in a terminal (PowerShell on Windows).
List of Requirements
- license for gams incl. CONOPT solver
- gams >= 50.1.0
- git >= 2.23
- R >= 4.3 (+ matching Rtools on Windows)
- pandoc >= 2.14.2
- TeX >= 3.14159265
OS specific setup
Choose your operating system and follow the instructions there. You can also
install requirements differently (e.g. using only installers on Windows), in
the end it is only important that all requirements are installed in a suitable
version and added to the PATH environment variable, so MAgPIE can use them.
Ubuntu
- make sure you have a gams license incl. the CONOPT solver
- install gams
- install git, R, and pandoc with
sudo apt install git r-base pandoc - install TinyTeX with
Rscript -e 'install.packages("tinytex"); tinytex::install_tinytex()'
In case R package installations fail during compilation, install the following system packages:
sudo apt install build-essential cmake gdal-bin libcurl4-gnutls-dev libcurl4-openssl-dev libfontconfig1 libfreetype-dev libfribidi-dev libgdal-dev libgit2-dev libglpk-dev libharfbuzz-dev libjpeg-dev libnetcdf-dev libpng-dev libpoppler-cpp-dev libssl-dev libtiff5-dev libudunits2-dev libxml2-dev pari-gp qpdf
This list is highly system specific and most likely incomplete. Pay close attention to error messages, usually they state which system package needs to be installed.
macOS
We recommend to NOT have an active conda environment (if you're unsure what this means you likely don't have conda) when working with magpie (conda deactivate). We recommend installing system packages via brew.
Install R from https://cran.r-project.org/bin/macosx/
Choose the right version: arm for Apple Silicon (M1, M2, …), x86_64 for older Intel-based Macs.
Install gfortran from https://cran.r-project.org/bin/macosx/tools/
- make sure you have a gams license incl. the CONOPT solver
- install gams
- install git and pandoc with
brew install git pandoc - install TinyTeX with
Rscript -e 'install.packages("tinytex",repos="https://cloud.r-project.org"); tinytex::install_tinytex()'
Usually macOS users can download precompiled binary R packages, but in case R package installations fail during compilation, install the following system packages:
brew install abseil cmake fribidi gdal harfbuzz libgit2 libpng libtiff libxml2 pkg-config
This list is highly system specific and most likely incomplete. Pay close attention to error messages, usually they state which system package needs to be installed.
Windows
Most of the installation steps require administrator rights.
- make sure you have a gams license incl. the CONOPT solver
- install gams
- download .msi pandoc file and run installer (
choco install pandocdid not work in testing) - install chocolatey
- install git, rig (R installer), and tinytex with
choco install -y git rig tinytex - restart terminal
- install R and Rtools with
rig add release; rig add rtools
check setup is complete
- restart terminal (now without administrator privileges)
gamsshould print many lines including "The installed license is valid."git --versionRscript --versionpandoc --versiontex --version
If any of these are not found: Find the path to that executable
(gams/git/Rscript/pandoc/tex, on Windows ending in '.exe') and add it to your account's
PATH environment variable. Search for a tutorial online if you are unsure how to do that,
or take a look at the detailed Windows instructions and troubleshooting below.
download and run MAgPIE
- download MAgPIE with
git clone https://github.com/magpiemodel/magpie.git - go into the MAgPIE folder
cd magpie - start a MAgPIE run with
Rscript start.R, first time: installs all required R packages (takes a while) - choose "1" for a default run
- then select "1" for direct execution
troubleshooting
Please check this discussion for known problems and solutions and to report new problems you encounter while setting up MAgPIE.
HOW TO CONFIGURE
Model run settings are set in config/default.cfg (or another config file of
the same structure). New model scenarios can be created by adding a column to
config/scenario_config.csv
HOW TO RUN
To run the model execute Rscript start.R (or source("start.R") from within
R) in the main folder of the model.
This will give you a list of available run scripts you can choose from. You can
also add your own run scripts by saving them in the folder scripts/start. To run
a single model run with settings as stated in default.cfg you can choose start
script "default". Make sure that the config file has been set correctly before
starting the model.
HOW TO CONTRIBUTE
We are interested in working with you! Just contact us through GitHub
(https://github.com/magpiemodel) or by mail (magpie@pik-potsdam.de) if you have
found and/or fixed a bug, developed a new model feature, have ideas for further
model development, suggestions for improvements or anything else. We are open to
any kind of contribution. Our aim is to develop an open, transparent and
meaningful model of the agricultural land use sector to get a better
understanding of the underlying processes and possible futures. Join us doing
so!
DEPENDENCIES
Model dependencies must be publicly available and should be Open Source.
Development aim is to rather minimize than expand dependencies on non-free
and/or non open source software. That means that besides currently existing
dependencies on GAMS, the GDXRRW R package and the corresponding solvers there
should be no additional dependencies of this kind and that these existing
dependencies should be resolved in the future if possible.
If a new R package is added as dependency this package should fulfill the
following requirements:
- The package is published under an Open Source license
- The package is distributed through CRAN or PIK-CRAN (the PIK-based,
but publicly available package repository). - The package source code is available through a public, version controlled
repository such as GitHub
For other dependencies comparable measures should apply. When a dependency is
added this dependency should be added to the HOW TO INSTALL section in the
README file of the model framework (mentioning the dependency and explaining
how it can be installed). If not all requirements can be fulfilled by the new
dependency this case should be discussed with the model maintainer
(magpie@pik-potsdam.de) to find a good solution for it.
INPUT DATA
In order to allow other researchers to reproduce and use work done with MAgPIE
one needs to make sure that all components necessary to perform a run can be
shared. One of these components is the input data. As proprietary data usually
does not allow its free distribution it should generally be avoided.
When adding a new data source, make sure that it can be freely shared with
others. If this is not the case please consider using a different source or
solution.
Data preparation should ideally be performed with the madrat data processing
framework (https://github.com/pik-piam/madrat). This makes sure that the
processing is reproducible and links properly to the already existing data
processing for MAgPIE.
In case that these recommendations can not be followed we would be happy if you
could discuss that issue with the MAgPIE development team
(magpie@pik-potsdam.de).
MODEL OUTPUT
By default the results of a model run are written to an individual results folder within the "output/" folder of the model. The two most important output files are the fulldata.gdx and the report.mif. The fulldata.gdx is the technical output of the GAMS optimization and contains all quantities that were used during the optimization in unchanged form. The mif-file is a csv file of a specific format and is synthetized from the fulldata.gdx by post-processing scripts. It can be read in any text editor or spreadsheet program and is well suited for a quick look at the results and for further analysis.
CONTACT
KNOWN BUGS
TROUBLESHOOTING
Please contact magpie@pik-potsdam.de if you're having troubles installing or running a MAgPIE release version.
Common issues with installing MAgPIE under Windows
- To modify the
Pathenvironment variable, you can use the Windows search by pressing the Windows key, start typing "environment" and select the option "Edit environment variables for your account". Edit thePathvariable by adding the paths to executables which aren't yet found when testing them in the terminal (via theNewbutton). You can also display the currently used path variable in the terminal viaecho %PATH%(regular terminal) and$env:PATH(PowerShell) to check what is already included. - Check if
rtoolswas installed successfully: Open anRsession from a terminal, and runinstall.packages("pkgbuild")followed bypkgbuild::has_rtools(). This should reportTRUE. - Neither downloading nor running MAgPIE requires administrator privileges, and you'll likely run into issues when trying to run MAgPIE in a folder where
git clonehas been run from an administrator terminal. If you did this by accident, delete the MAgPIE folder and redo thegit clonefrom a terminal without administrator privileges. - Before running
git clonein the terminal, make sure that you're in a folder where you have write access and not in a Windows system path. If you're using Windows 11, you can access the terminal by right-clicking and starting a terminal from Windows explorer after navigating to the location where you want to download MAgPIE into. - If you're using PowerShell, starting an interactive R session with
Rdoesn't work, and you need to typeR.exe(orR.batifR.exeisn't found) instead. The reason behind this is thatris a reserved shortcut for repeating the previous command, which is why you'll be getting a crypticInvoke-History: Cannot locate most recent history.error message when trying to start R in a fresh PowerShell session.
CITATION
See file CITATION.cff or the How-to-Cite section in the model documentation for information how to cite the model.
AUTHORS
See list of authors in CITATION.cff
CHANGELOG
See log on GitHub (https://github.com/magpiemodel)
Citation (CITATION.cff)
cff-version: 1.0.3
message: If you use this model, please cite it as below.
type: software
authors:
- family-names: Dietrich
given-names: Jan Philipp
orcid: https://orcid.org/0000-0002-4309-6431
affiliation: "Potsdam Institute for Climate Impact Research"
email: dietrich@pik-potsdam.de
- family-names: Bodirsky
given-names: Benjamin Leon
orcid: https://orcid.org/0000-0002-8242-6712
affiliation: "Potsdam Institute for Climate Impact Research"
email: bodirsky@pik-potsdam.de
- family-names: Weindl
given-names: Isabelle
affiliation: "Potsdam Institute for Climate Impact Research"
email: weindl@pik-potsdam.de
- family-names: Humpenöder
given-names: Florian
orcid: https://orcid.org/0000-0003-2927-9407
affiliation: "Potsdam Institute for Climate Impact Research"
email: humpenoeder@pik-potsdam.de
- family-names: Stevanovic
given-names: Miodrag
affiliation: "Potsdam Institute for Climate Impact Research"
email: stevanovic@pik-potsdam.de
- family-names: Kreidenweis
given-names: Ulrich
affiliation: "Potsdam Institute for Climate Impact Research"
- family-names: Wang
given-names: Xiaoxi
affiliation: "Potsdam Institute for Climate Impact Research"
email: wang@pik-potsdam.de
- family-names: Karstens
given-names: Kristine
affiliation: "Potsdam Institute for Climate Impact Research"
email: karstens@pik-potsdam.de
- family-names: Mishra
given-names: Abhijeet
orcid: https://orcid.org/0000-0002-8287-9922
affiliation: "Potsdam Institute for Climate Impact Research"
email: mishra@pik-potsdam.de
- family-names: Beier
given-names: Felicitas Dorothea
affiliation: "Potsdam Institute for Climate Impact Research"
email: beier@pik-potsdam.de
- family-names: Molina Bacca
given-names: Edna Johanna
orcid: https://orcid.org/0000-0001-6530-1849
affiliation: "Potsdam Institute for Climate Impact Research"
email: mbacca@pik-potsdam.de
- family-names: von Jeetze
given-names: Patrick
orcid: https://orcid.org/0000-0002-1197-4412
affiliation: "Potsdam Institute for Climate Impact Research"
email: vjeetze@pik-potsdam.de
- family-names: Windisch
given-names: Michael
affiliation: "Potsdam Institute for Climate Impact Research"
email: windisch@pik-potsdam.de
- family-names: Crawford
given-names: Michael Scott
orcid: https://orcid.org/0000-0003-1282-400X
affiliation: "Potsdam Institute for Climate Impact Research"
email: crawford@pik-potsdam.de
- family-names: Leip
given-names: Debbora
affiliation: "Potsdam Institute for Climate Impact Research"
email: leip@pik-potsdam.de
- family-names: Klein
given-names: David
affiliation: "Potsdam Institute for Climate Impact Research"
email: dklein@pik-potsdam.de
- family-names: Singh
given-names: Vartika
affiliation: "Potsdam Institute for Climate Impact Research"
email: vasingh@pik-potsdam.de
- family-names: Ambrósio
given-names: Geanderson
affiliation: "Potsdam Institute for Climate Impact Research"
email: ambrosio@pik-potsdam.de
- family-names: Araujo
given-names: Ewerton
affiliation: "Potsdam Institute for Climate Impact Research"
email: araujo@pik-potsdam.de
- family-names: Biewald
given-names: Anne
affiliation: "Potsdam Institute for Climate Impact Research"
- family-names: Sauer
given-names: Pascal
orcid: https://orcid.org/0000-0002-6856-8239
affiliation: "Potsdam Institute for Climate Impact Research"
email: pascal.sauer@pik-potsdam.de
- family-names: Köberle
given-names: Alexandre
orcid: https://orcid.org/0000-0003-0328-4750
affiliation: "Potsdam Institute for Climate Impact Research"
email: alexkob@pik-potsdam.de
- family-names: Steinhauser
given-names: Jan
orcid: https://orcid.org/0000-0002-5989-6855
affiliation: "Potsdam Institute for Climate Impact Research"
email: janstein@pik-potsdam.de
- family-names: Hötten
given-names: David
affiliation: "Potsdam Institute for Climate Impact Research"
email: davidho@pik-potsdam.de
- family-names: Schröter
given-names: Georg
affiliation: "Potsdam Institute for Climate Impact Research"
email: georgsc@pik-potsdam.de
- family-names: Lotze-Campen
given-names: Hermann
orcid: https://orcid.org/0000-0002-0003-5508
affiliation: "Potsdam Institute for Climate Impact Research"
email: lotze-campen@pik-potsdam.de
- family-names: Popp
given-names: Alexander
orcid: https://orcid.org/0000-0001-9500-1986
affiliation: "Potsdam Institute for Climate Impact Research"
email: popp@pik-potsdam.de
title: MAgPIE - An Open Source land-use modeling framework
abstract: The *Model of Agricultural Production and its Impact on the Environment* (MAgPIE)
is a modular open source framework for modeling global land-systems, which is
coupled to the grid-based dynamic vegetation model LPJmL, with a spatial resolution
of 0.5degx0.5deg. It takes regional economic conditions such as demand for agricultural
commodities, technological development and production costs as well as spatially
explicit data on potential crop yields, land and water constraints (from LPJmL) into
account. Based on these, the model derives specific land use patterns, yields and
total costs of agricultural production for each grid cell. The objective function of
the land use model is to minimize total cost of production for a given amount of
regional food and bioenergy demand. Regional food energy demand is defined for an
exogenously given population in 10 food energy categories, based on regional diets.
Future trends in food demand are derived from a cross-country regression analysis,
based on future scenarios on GDP and population growth.
version: 4.13.0
date-released: 2025-10-23
repository-code: https://github.com/magpiemodel/magpie
keywords:
- landuse
- modeling
- model
- nlp
- partial equilibrium
doi: 10.5281/zenodo.1418752
license: AGPL-3.0-or-later
url: https://github.com/magpiemodel/magpie
Owner metadata
- Name: Model of Agricultural Production and its Impact on the Environment
- Login: magpiemodel
- Email:
- Kind: organization
- Description: A modular open source framework for modeling global land-systems
- Website: https://magpiemodel.github.io/
- Location: Potsdam Institute for Climate Impact Research (PIK), Germany
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/23235810?v=4
- Repositories: 3
- Last ynced at: 2023-03-05T01:34:00.946Z
- Profile URL: https://github.com/magpiemodel
GitHub Events
Total
- Create event: 13
- Issues event: 2
- Release event: 6
- Watch event: 19
- Delete event: 9
- Issue comment event: 58
- Push event: 83
- Pull request review comment event: 300
- Pull request event: 161
- Pull request review event: 394
- Fork event: 53
Last Year
- Create event: 13
- Issues event: 2
- Release event: 6
- Watch event: 19
- Delete event: 9
- Issue comment event: 50
- Push event: 79
- Pull request review comment event: 295
- Pull request review event: 377
- Pull request event: 151
- Fork event: 52
Committers metadata
Last synced: 4 days ago
Total Commits: 8,879
Total Committers: 47
Avg Commits per committer: 188.915
Development Distribution Score (DDS): 0.708
Commits in past year: 594
Committers in past year: 16
Avg Commits per committer in past year: 37.125
Development Distribution Score (DDS) in past year: 0.483
| Name | Commits | |
|---|---|---|
| florianh | h****r@p****e | 2596 |
| Abhijeet | m****a@p****e | 1490 |
| Jan Philipp Dietrich | d****h@p****e | 726 |
| Felicitas | b****r@p****e | 654 |
| Benjamin Leon Bodirsky | b****y@p****e | 539 |
| emolinab | m****a@p****e | 483 |
| pvjeetze | v****e@p****e | 356 |
| Kristine Karstens | k****s@p****e | 344 |
| Isabelle Weindl | w****l@p****e | 181 |
| mishko | s****c@p****e | 158 |
| Debbora Leip | l****p@p****e | 144 |
| Pascal Führlich | p****h@p****e | 135 |
| David Klein | d****n@p****e | 119 |
| Pascal Sauer | 1****r | 110 |
| Vartika Singh | 5****7 | 108 |
| Jan Steinhauser | j****r@m****g | 104 |
| caviddhen | d****n@p****e | 85 |
| Michael Crawford | m****r@g****m | 70 |
| Marcos Alves | m****s@g****m | 56 |
| David Chen | d****h@l****e | 49 |
| Xiaoxi Wang | w****g@p****e | 48 |
| David Hoetten | d****o@p****e | 36 |
| Abhijeet Mishra | m****a@l****e | 36 |
| Araujo | a****o@p****e | 32 |
| Georg Schroeter | G****r@p****e | 31 |
| Geanderson Ambrosio | a****o@p****e | 28 |
| david chen | c****n@g****m | 23 |
| PrantikaDas | 4****s | 19 |
| Amsalu | y****w@p****e | 17 |
| mikewin-climsci | m****h@g****m | 13 |
| and 17 more... | ||
Committer domains:
- pik-potsdam.de: 28
- foxmail.com: 1
- lt1283.pik-potsdam.de: 1
- lt543.pik-potsdam.de: 1
- cgiar.org: 1
- lt822.pik-potsdam.de: 1
- lt916.pik-potsdam.de: 1
- pik.potsdam.de: 1
- mailbox.org: 1
Issue and Pull Request metadata
Last synced: 6 days ago
Total issues: 21
Total pull requests: 925
Average time to close issues: about 1 month
Average time to close pull requests: 6 days
Total issue authors: 17
Total pull request authors: 37
Average comments per issue: 3.14
Average comments per pull request: 0.55
Merged pull request: 807
Bot issues: 0
Bot pull requests: 0
Past year issues: 1
Past year pull requests: 175
Past year average time to close issues: about 1 month
Past year average time to close pull requests: 4 days
Past year issue authors: 1
Past year pull request authors: 16
Past year average comments per issue: 0.0
Past year average comments per pull request: 0.59
Past year merged pull request: 139
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- k4rst3ns (2)
- orichters (2)
- bodirsky (2)
- FelicitasBeier (2)
- tscheypidi (1)
- alexkoberle (1)
- giannou (1)
- HealGea (1)
- DavidhoPIK (1)
- agohin (1)
- flohump (1)
- lolow (1)
- abhimishr (1)
- Apprisco (1)
- robbiemorrison (1)
Top Pull Request Authors
- flohump (248)
- tscheypidi (103)
- pascal-sauer (75)
- FelicitasBeier (65)
- pvjeetze (53)
- pfuehrlich-pik (51)
- abhimishr (36)
- bodirsky (33)
- k4rst3ns (31)
- dklein-pik (30)
- emolinab (24)
- weindl (21)
- caviddhen (21)
- mscrawford (21)
- deleip (18)
Top Issue Labels
- enhancement (3)
- bug (2)
- wontfix (1)
- Suggestion (1)
- Minor (1)
- question (1)
Top Pull Request Labels
- Low risk (290)
- Minor (196)
- bugfix (170)
- enhancement (122)
- High risk (99)
- Medium risk (95)
- Major (23)
- data update (12)
- bug (11)
- Release candidate (10)
- Suggestion (5)
- good first issue (4)
- help wanted (3)
Dependencies
- actions/checkout v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
- rocker/r-ver 4.2.1 build
- MagpieNCGains * imports
- callr * imports
- citation * imports
- curl * imports
- data.table * imports
- dplyr * imports
- gdx * imports
- gdxrrw * imports
- ggplot2 * imports
- ggrepel * imports
- gms >= 0.24.0 imports
- here * imports
- iamc * imports
- lucode2 >= 0.36.0 imports
- luplot * imports
- luscale >= 2.27.9 imports
- lusweave * imports
- m4fsdp * imports
- madrat * imports
- magclass * imports
- magpie4 * imports
- magpiesets * imports
- mip * imports
- mrcommons * imports
- patchwork * imports
- piamenv >= 0.3.4 imports
- quitte * imports
- raster * imports
- remulator * imports
- renv * imports
- stringr * imports
- txtplot * imports
- withr * imports
- goxygen * suggests
- languageserver * suggests
- qgraph * suggests
Score: 8.67846133901236