<jupyter_start><jupyter_text>Pymagicc Usage Examples<jupyter_code># 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
%matplotlib inline
from matplotlib import pyplot as plt

plt.style.use("ggplot")
plt.rcParams["figure.figsize"] = 16, 9<jupyter_output><empty_output><jupyter_text>ScenariosThe four RCP scenarios are already preloaded in Pymagicc. They are loaded as `MAGICCData` objects with `metadata` attributes. `metadata` contains metadata<jupyter_code>type(rcp26)
pprint(rcp26.metadata)<jupyter_output>{'description': 'HARMONISED, EXTENDED FINAL RCP3-PD (Peak&Decline) NOV26; '
                'RCP3PD-Contact: IMAGE group, <NAME> '
                '(<EMAIL>)',
 'header': 'Final RCP3PD with constant emissions after 2100 using the default '
           'RCPtool MAGICC6.3 settings. Compiled by: '
           '<EMAIL>',
 'notes': 'DATE: 26/11/2009 11:29:06; MAGICC-VERSION: 6.3.09, 25 November 2009'}<jupyter_text>`MAGICCData` subclasses scmdata's `ScmRun` so we can access the `scmdata` helpers directly, e.g.<jupyter_code>rcp26.__class__.__bases__
rcp26.head()<jupyter_output><empty_output><jupyter_text>The rcp's contain the following emissions with the following units<jupyter_code>rcp26.meta[["variable", "unit"]].drop_duplicates()<jupyter_output><empty_output><jupyter_text>The regions included are<jupyter_code>rcp26["region"].unique()<jupyter_output><empty_output><jupyter_text>A plot of four categories in RCP3PD<jupyter_code>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))<jupyter_output><empty_output><jupyter_text>Fossil fuel emissions for the four RCP scenarios.<jupyter_code>rcps.filter(
    variable="Emissions|CO2|MAGICC Fossil and Industrial", region="World"
).lineplot(x="time");<jupyter_output><empty_output><jupyter_text>Running MAGICCA 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.<jupyter_code># NBVAL_IGNORE_OUTPUT
%time results = pymagicc.run(rcp26)
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()
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");<jupyter_output><empty_output><jupyter_text>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.<jupyter_code>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");<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12645631067961166, 'fraction_numerical': 0.02766990291262136, 'mean_word_length': 5.234493192133131, 'pattern_counts': {'":': 3, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '425477', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1434, 'n_words': 337, 'path': 'notebooks/Example.ipynb', 'repo_name': 'gabriel-abrahao/pymagicc', 'size': '4172'}