-
Notifications
You must be signed in to change notification settings - Fork 2
/
converting-time-regions.Rmd
96 lines (74 loc) · 2.42 KB
/
converting-time-regions.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
---
title: "Region and Time Conversion"
author: "L. Drouet"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Region and Time Conversion}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
<style type="text/css">
img, table, table th, table td {
border: none;
}
</style>
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
library(ggplot2)
```
## Region conversion
In this section, we convert a dataset containing the GDP of
all countries into a 17-region mapping of the WITCH model, then into the
5-region mapping used in the SSP database.
First, let's create the initial database, we will extract the GDP in 2005
from the default_weights. The column names have to be renamed.
By convention, column names must be "iso3" and "value"
```{r example, screenshot.force=FALSE}
library(data.table)
library(witchtools)
# Creation of the initial dataset
# Note the column names: iso3 and value
gdp_iso3 <- copy(default_weights[['gdp']])
setnames(gdp_iso3,'weight','value')
gdp_iso3
```
Now, using the function `convert_region`,
we will aggregate this dataset at country-level (ISO3) to the 17-region
mapping of the WITCH model, available as a default mapping.
```{r convert_witch17}
# Aggregate value at WITCH regional scale (17 regions)
gdp_witch17 <- convert_region(gdp_iso3, to_reg = 'witch17')
gdp_witch17
```
In a final step, we will convert the 17-region data into the 5-region of
the SSP database.
The dataset is first disaggregated at iso3 level then it is aggregated into
5 regions, automatically.
```{r convert_r5}
# Aggregate value at WITCH regional scale (17 regions)
gdp_r5 <- convert_region(gdp_witch17, to_reg = 'r5')
gdp_r5
```
## Time conversion
In this section, we convert a yearly time-serie into the default time period
of the WITCH model, 5 year-periods from 2005 to 2150, using the
function `convert_time_period`.
```{r convert_t30}
# Time-serie
dd <- data.table(tech = c("tech1","tech2"), year = 2005:2050, value = 1:46)
# Aggregate values to the default WITCH time period mapping
res <- convert_time_period(dd, 't30')
print(nrow(res))
print(res, nrows = 20)
```
The function `convert_time_period` can also extrapolate the missing periods.
```{r convert_t30_extrap}
# Aggregate values to the default WITCH time period mapping with extrapolation
res <- convert_time_period(dd, 't30', do_extrap = TRUE)
print(nrow(res))
print(tail(res))
```