Skip to content

Instantly share code, notes, and snippets.

@rplzzz
Created March 17, 2019 09:01
Show Gist options
  • Save rplzzz/a20094f5d8e48b629c7534da60532290 to your computer and use it in GitHub Desktop.
Save rplzzz/a20094f5d8e48b629c7534da60532290 to your computer and use it in GitHub Desktop.
Using Hector to show the difference between early vs. late emissions reductions
---
title: "R Notebook"
output: html_notebook
---
```{r setup}
library(hector)
library(assertthat)
library(ggplot2)
library(ggthemes)
```
```{r inithector}
infile <- system.file('input/hector_rcp60.ini', package='hector')
hcore <- newcore(infile, name='rcp60-base')
```
Run an RCP 6.0 scenario as a baseline.
```{r baserun}
run(hcore,2100)
emissyears <- 2020:2100
tempyears <- 2000:2100
baseemiss <- fetchvars(hcore, emissyears, FFI_EMISSIONS())
basetemp <- fetchvars(hcore, tempyears, GLOBAL_TEMP())
```
For the slow reduction scenario, use 20% cuts from `r min(emissyears)` through `r max(emissyears)`.
```{r slowcuts}
## 20% cuts from 2020 to 2100
slowcutemiss <- baseemiss$value * 0.8
setvar(hcore, emissyears, FFI_EMISSIONS(), slowcutemiss, 'Pg C/yr')
reset(hcore,min(tempyears))
run(hcore, 2100)
slowtemp <- fetchvars(hcore, tempyears, GLOBAL_TEMP(), 'late emissions cuts')
```
For the early reduction scenario, use the same total magnitude of cuts during the first 10 years.
```{r earlycuts}
fastcutemiss <- baseemiss$value
totalcuts <- sum(baseemiss$value - slowcutemiss)
nyrcut <- 10
cutspyr <- totalcuts / nyrcut
fastcutemiss[1:nyrcut] <- fastcutemiss[1:nyrcut] - cutspyr
assert_that(sum(slowcutemiss) == sum(fastcutemiss))
setvar(hcore, emissyears, FFI_EMISSIONS(), fastcutemiss, 'Pg C/yr')
reset(hcore, min(tempyears))
run(hcore, 2100)
fasttemp <- fetchvars(hcore, tempyears, GLOBAL_TEMP(), 'early emissions cuts')
```
Compare the three scenarios. The temperature in the early cut scenario is lower earlier.
In fact the cuts are large enough that when you cram them into just 10 years the emissions
are negative, so the temperature initially drops. However, by the end of the century the
early cut and late cut scenarios have reached the same place.
```{r plots}
pltdata <- rbind(basetemp, slowtemp, fasttemp)
ggplot(data=pltdata, aes(x=year, y=value, color=scenario)) + geom_line(size=1.2) +
theme_solarized_2(light=FALSE) + scale_color_solarized()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment