In [1]:
# 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
)
In [2]:
%matplotlib inline
from matplotlib import pyplot as plt
plt.style.use('ggplot')
plt.rcParams['figure.figsize'] = 16, 9
In [3]:
type(rcp26)
Out[3]:
In [4]:
pprint(rcp26.metadata)
MAGICCData
subclasses OpenSCM's ScmDataFrame
so we can access many of the dataframe's attributes directly, e.g.
In [5]:
rcp26.__class__.__bases__
Out[5]:
In [6]:
rcp26.head()
Out[6]:
The rcp's contain the following emissions with the following units
In [7]:
rcp26[["variable", "unit"]].drop_duplicates()
Out[7]:
The regions included are
In [8]:
rcp26["region"].unique()
Out[8]:
A plot of four categories in RCP3PD
In [9]:
categories_to_plot = [
"Emissions|" + v
for v in ["CO2|MAGICC Fossil and Industrial", "CO2|MAGICC AFOLU", "CH4", "N2O"]
]
rcp26.filter(
variable=categories_to_plot,
year=range(1000, 2150)
).pivot_table(
index="time",
columns=["variable", "unit", "region"],
aggfunc="sum"
).groupby(level="variable", axis=1).plot(figsize=(12, 7));
Fossil fuel emissions for the four RCP scenarios.
In [10]:
rcps.filter(
variable="Emissions|CO2|MAGICC Fossil and Industrial",
region="World"
).line_plot(x="time", figsize=(16, 9));
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.
In [11]:
# NBVAL_IGNORE_OUTPUT
%time results = pymagicc.run(rcp26)
In [12]:
def multiple_runs():
with MAGICC6() as magicc:
for name, sdf in rcps.timeseries().groupby(["scenario"]):
results = magicc.run(MAGICCData(sdf.copy()))
In [13]:
# NBVAL_IGNORE_OUTPUT
%time multiple_runs()
In [14]:
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"
).line_plot(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.
In [15]:
low = pymagicc.run(rcp45, core_climatesensitivity=1.5)
default = pymagicc.run(rcp45, core_climatesensitivity=3)
high = pymagicc.run(rcp45, core_climatesensitivity=4.5)
In [16]:
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");