<jupyter_start><jupyter_text>Diagnosing MAGICC's TCR, ECS and TCRE<jupyter_code># NBVAL_IGNORE_OUTPUT
from datetime import datetime

from pymagicc.core import MAGICC6, MAGICC7
%matplotlib inline
from matplotlib import pyplot as plt

plt.style.use("ggplot")<jupyter_output><empty_output><jupyter_text>Basic usageThe simplest option is to simply call the `diagnose_tcr_ecs_tcre` method of the MAGICC instance and read out the results.<jupyter_code>with MAGICC6() as magicc:
    # you can tweak whatever parameters you want in
    # MAGICC6/run/MAGCFG_DEFAULTALL.CFG, here's a few
    # examples that might be of interest
    results = magicc.diagnose_tcr_ecs_tcre(
        CORE_CLIMATESENSITIVITY=2.75,
        CORE_DELQ2XCO2=3.65,
        CORE_HEATXCHANGE_LANDOCEAN=1.5,
    )
print(
    "TCR is {tcr:.4f}, ECS is {ecs:.4f} and TCRE is {tcre:.6f}".format(
        **results
    )
)<jupyter_output>TCR is 1.8517 kelvin, ECS is 2.7376 kelvin and TCRE is 0.002146 kelvin / C / gigametric_ton<jupyter_text>If we wish, we can alter the MAGICC instance's parameters before calling the `diagnose_tcr_ecs` method.<jupyter_code>with MAGICC6() as magicc:
    results_default = magicc.diagnose_tcr_ecs_tcre()
    results_low_ecs = magicc.diagnose_tcr_ecs_tcre(CORE_CLIMATESENSITIVITY=1.5)
    results_high_ecs = magicc.diagnose_tcr_ecs_tcre(
        CORE_CLIMATESENSITIVITY=4.5
    )

print(
    "Default TCR is {tcr:.4f}, ECS is {ecs:.4f} and TCRE is {tcre:.6f}".format(
        **results_default
    )
)
print(
    "Low TCR is {tcr:.4f}, ECS is {ecs:.4f} and TCRE is {tcre:.6f}".format(
        **results_low_ecs
    )
)
print(
    "High TCR is {tcr:.4f}, ECS is {ecs:.4f} and TCRE is {tcre:.6f}".format(
        **results_high_ecs
    )
)<jupyter_output>Default TCR is 1.9734 kelvin, ECS is 2.9833 kelvin and TCRE is 0.002287 kelvin / C / gigametric_ton
Low TCR is 1.1942 kelvin, ECS is 1.4985 kelvin and TCRE is 0.001384 kelvin / C / gigametric_ton
High TCR is 2.5229 kelvin, ECS is 4.4203 kelvin and TCRE is 0.002924 kelvin / C / gigametric_ton<jupyter_text>Making a plotThe output also includes the timeseries that were used in the diagnosis experiment. Hence we can use the output to make a plot.<jupyter_code># NBVAL_IGNORE_OUTPUT
join_year = 1900

pdf = (
    results["timeseries"]
    .filter(region="World")
    .to_iamdataframe()
    .swap_time_for_year()
    .data
)
for variable, df in pdf.groupby("variable"):
    fig, axes = plt.subplots(1, 2, sharey=True, figsize=(16, 4.5))
    unit = df["unit"].unique()[0]

    for scenario, scdf in df.groupby("scenario"):
        scdf.plot(x="year", y="value", ax=axes[0], label=scenario)
        scdf.plot(x="year", y="value", ax=axes[1], label=scenario)

    axes[0].set_xlim([1750, join_year])
    axes[0].set_ylabel("{} ({})".format(variable, unit))

    axes[1].set_xlim(left=join_year)
    axes[1].legend_.remove()

    fig.tight_layout()
# NBVAL_IGNORE_OUTPUT
results["timeseries"].filter(
    scenario="abrupt-2xCO2", region="World", year=range(1795, 1905)
).timeseries()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11893840104849279, 'fraction_numerical': 0.04259501965923984, 'mean_word_length': 4.079866888519135, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '243823', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1177, 'n_words': 283, 'path': 'notebooks/Diagnose-TCR-ECS-TCRE.ipynb', 'repo_name': 'gabriel-abrahao/pymagicc', 'size': '3052'}