# NBVAL_IGNORE_OUTPUT
from pprint import pprint
import pymagicc
from pymagicc import MAGICC6
from pymagicc.io import MAGICCData
from pymagicc.scenarios import rcp26, rcp45, rcps
pyam - INFO: Running in a notebook, setting `pyam` logging level to `logging.INFO` and adding stderr handler
%matplotlib inline
from matplotlib import pyplot as plt
plt.style.use("ggplot")
plt.rcParams["figure.figsize"] = 16, 9
The four RCP scenarios are already preloaded in Pymagicc. They are loaded as MAGICCData
objects with metadata
attributes. metadata
contains metadata
type(rcp26)
pymagicc.io.MAGICCData
pprint(rcp26.metadata)
{'description': 'HARMONISED, EXTENDED FINAL RCP3-PD (Peak&Decline) NOV26; ' 'RCP3PD-Contact: IMAGE group, Detlef van Vuuren ' '(Detlef.vanVuuren@pbl.nl)', 'header': 'Final RCP3PD with constant emissions after 2100 using the default ' 'RCPtool MAGICC6.3 settings. Compiled by: ' 'malte.meinshausen@pik-potsdam.de', 'notes': 'DATE: 26/11/2009 11:29:06; MAGICC-VERSION: 6.3.09, 25 November 2009'}
MAGICCData
subclasses scmdata's ScmRun
so we can access the scmdata
helpers directly, e.g.
rcp26.__class__.__bases__
(scmdata.run.ScmRun,)
rcp26.head()
time | 2000-01-01 00:00:00 | 2001-01-01 00:00:00 | 2002-01-01 00:00:00 | 2003-01-01 00:00:00 | 2004-01-01 00:00:00 | 2005-01-01 00:00:00 | 2006-01-01 00:00:00 | 2007-01-01 00:00:00 | 2010-01-01 00:00:00 | 2020-01-01 00:00:00 | 2030-01-01 00:00:00 | 2040-01-01 00:00:00 | 2050-01-01 00:00:00 | 2060-01-01 00:00:00 | 2070-01-01 00:00:00 | 2080-01-01 00:00:00 | 2090-01-01 00:00:00 | 2100-01-01 00:00:00 | 2125-01-01 00:00:00 | 2500-01-01 00:00:00 | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
climate_model | model | region | scenario | todo | unit | variable | ||||||||||||||||||||
unspecified | IMAGE | World|Bunkers | RCP26 | SET | Gt C / yr | Emissions|CO2|MAGICC Fossil and Industrial | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 |
Emissions|CO2|MAGICC AFOLU | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | ||||||
Mt CH4 / yr | Emissions|CH4 | 0.4325 | 0.4422 | 0.4520 | 0.4618 | 0.4717 | 0.4817 | 0.4812 | 0.4806 | 0.4790 | 0.5252 | 0.5252 | 0.3191 | 0.000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | |||||
Mt N2ON / yr | Emissions|N2O | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | 0.0000 | |||||
Mt S / yr | Emissions|SOx | 5.5390 | 5.5824 | 5.6207 | 5.6587 | 5.6964 | 5.7337 | 5.4434 | 5.1544 | 4.2947 | 1.5534 | 1.0918 | 0.7379 | 0.336 | 0.3209 | 0.2856 | 0.2356 | 0.2127 | 0.1887 | 0.1887 | 0.1887 |
The rcp's contain the following emissions with the following units
rcp26.meta[["variable", "unit"]].drop_duplicates()
variable | unit | |
---|---|---|
0 | Emissions|CO2|MAGICC Fossil and Industrial | Gt C / yr |
1 | Emissions|CO2|MAGICC AFOLU | Gt C / yr |
2 | Emissions|CH4 | Mt CH4 / yr |
3 | Emissions|N2O | Mt N2ON / yr |
4 | Emissions|SOx | Mt S / yr |
5 | Emissions|CO | Mt CO / yr |
6 | Emissions|NMVOC | Mt NMVOC / yr |
7 | Emissions|NOx | Mt N / yr |
8 | Emissions|BC | Mt BC / yr |
9 | Emissions|OC | Mt OC / yr |
10 | Emissions|NH3 | Mt N / yr |
11 | Emissions|CF4 | kt CF4 / yr |
12 | Emissions|C2F6 | kt C2F6 / yr |
13 | Emissions|C6F14 | kt C6F14 / yr |
14 | Emissions|HFC23 | kt HFC23 / yr |
15 | Emissions|HFC32 | kt HFC32 / yr |
16 | Emissions|HFC4310 | kt HFC4310 / yr |
17 | Emissions|HFC125 | kt HFC125 / yr |
18 | Emissions|HFC134a | kt HFC134a / yr |
19 | Emissions|HFC143a | kt HFC143a / yr |
20 | Emissions|HFC227ea | kt HFC227ea / yr |
21 | Emissions|HFC245fa | kt HFC245fa / yr |
22 | Emissions|SF6 | kt SF6 / yr |
The regions included are
rcp26["region"].unique()
array(['World|Bunkers', 'World|R5LAM', 'World|R5MAF', 'World|R5ASIA', 'World|R5REF', 'World|R5OECD', 'World'], dtype=object)
A plot of four categories in RCP3PD
categories_to_plot = [
"Emissions|" + v
for v in [
"CO2|MAGICC Fossil and Industrial",
"CO2|MAGICC AFOLU",
"CH4",
"N2O",
]
]
for g in rcp26.filter(
variable=categories_to_plot, year=range(1000, 2150)
).groupby("variable"):
plt.figure(figsize=(12, 7))
g.lineplot(hue="region").set_title(g.get_unique_meta("variable", True))
Fossil fuel emissions for the four RCP scenarios.
rcps.filter(
variable="Emissions|CO2|MAGICC Fossil and Industrial", region="World"
).lineplot(x="time");
A single pymagicc
run takes under a second and returns the same object as used above. If not on Windows, the very first run might be slower due to setting up Wine. Multiple runs can be faster as setup times are reduced and other options speed things up even further e.g. limiting output to the subset of interest, using binary output formats.
# NBVAL_IGNORE_OUTPUT
%time results = pymagicc.run(rcp26)
CPU times: user 503 ms, sys: 50.5 ms, total: 554 ms Wall time: 589 ms
def multiple_runs():
with MAGICC6() as magicc:
for name, sdf in rcps.timeseries().groupby(["scenario"]):
results = magicc.run(MAGICCData(sdf.copy()))
# NBVAL_IGNORE_OUTPUT
%time multiple_runs()
CPU times: user 266 ms, sys: 18.1 ms, total: 284 ms Wall time: 375 ms
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(16, 9))
with MAGICC6() as magicc:
for name, sdf in rcps.timeseries().groupby(["scenario"]):
results = magicc.run(MAGICCData(sdf.copy()))
results.filter(
variable="Surface Temperature", region="World"
).lineplot(ax=ax, x="time");
The default parameters are the ones that were used to produce the RCP GHG concentrations (see also http://live.magicc.org/). Of course it's easy to change them.
low = pymagicc.run(rcp45, core_climatesensitivity=1.5)
default = pymagicc.run(rcp45, core_climatesensitivity=3)
high = pymagicc.run(rcp45, core_climatesensitivity=4.5)
filtering = {
"variable": "Surface Temperature",
"region": "World",
"year": range(1850, 2101),
}
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(16, 9))
default.filter(**filtering).line_plot(x="time", ax=ax)
plt.fill_between(
low.filter(**filtering)["time"].values,
low.filter(**filtering).timeseries().values.squeeze(),
high.filter(**filtering).timeseries().values.squeeze(),
color="lightgray",
)
plt.title(
"RCP 4.5 with equilibrium climate sensitivity set to 1.5, 3, and 4.5"
)
plt.ylabel("°C");