-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy path7_advanced_changeCode.Rmd
59 lines (48 loc) · 2.34 KB
/
7_advanced_changeCode.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
title: "Advanced: Change MAgPIE GAMS Code"
subtitle: MAgPIE model development team ([email protected])
date: "`r format(Sys.time(), '%d %B, %Y')`"
author: Florian Humpenöder ([email protected])
output:
rmarkdown::github_document:
toc: yes
---
# Learning objectives
MAgPIE has a modular concept. Each module (e.g. cropland) can have several realization (e.g. dynamic and static).
This tutorial shows how to add a new realization to a module in 4 steps:
1. create new realization via copying existing one
2. include it properly via lucode::update_modules_embedding()
3. do simple modification in new realization
4. choose realization in cfg and run model
# Getting started
We want to add a new realization to the cropland module.
In the MAgPIE 4.0 release the cropland module (30_crop) has only one realization called "endo_jun13". In this realization irrigation of bioenergy crops is prohibited. We will add a new realization, based on "endo_jun13", which allows for irrigation of bioenergy crops. We will call the new new realization "bioen_irrig".
## Step 1
We first copy-paste the folder "endo_jun13" and the file "endo_jun13.gms" (both located in "modules/30_crop"), and rename them to "bioen_irrig" and "bioen_irrig.gms" respectivly.
## Step 2
To include the new realization "bioen_irrig" properly into the GAMS code we run a specific R command in the main folder. First navigate in your command line to the MAgPIE main folder, then open a new R session (type "R" followed by ENTER), and then copy-paste the following R command:
```{r comment=NA,eval=FALSE}
lucode::update_modules_embedding()
```
## Step 3
The prohibition of irrigated bioenergy is specified in the file "presolve.gms" within the "bioen_irrig" realization.
We just have to remove (or comment out) lines 7-9 from this file to allow for irrigation of bioenergy crops.
```{r comment=NA,eval=FALSE}
*vm_area.fx(j,"begr","irrigated")=0;
*vm_area.fx(j,"begr","irrigated")=0;
*vm_area.fx(j,"betr","irrigated")=0;
```
## Step 4
To test the new realization we have to make a change in the file "config/default.cfg" in line 218.
We change
```{r comment=NA,eval=FALSE}
cfg$gms$crop <- "endo_jun13"
```
to
```{r comment=NA,eval=FALSE}
cfg$gms$crop <- "bioen_irrig"
```
We can then start the model run with
```{r comment=NA,eval=FALSE}
Rscript start.R -> 1: default -> 1: Direct execution
```