Running scenariosΒΆ

Here we show how multiple scenarios can be run using the OpenSCM Two Layer Model package.

[1]:
# NBVAL_IGNORE_OUTPUT
import os.path

import numpy as np
import pandas as pd
from openscm_units import unit_registry as ur
import tqdm.autonotebook as tqdman
from scmdata import ScmRun, run_append

from openscm_twolayermodel import TwoLayerModel

import matplotlib.pyplot as plt
/home/docs/checkouts/readthedocs.org/user_builds/openscm-two-layer-model/envs/stable/lib/python3.7/site-packages/ipykernel_launcher.py:7: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)
  import sys

For this we use RCMIP effective radiative forcing data.

[2]:
DATA_PATH = os.path.join(
    "..",
    "..",
    "..",
    "tests",
    "test-data",
    "rcmip-radiative-forcing-annual-means-v4-0-0.csv",
)
DATA_PATH
[2]:
'../../../tests/test-data/rcmip-radiative-forcing-annual-means-v4-0-0.csv'
[3]:
# NBVAL_IGNORE_OUTPUT
scenarios = ScmRun(DATA_PATH, lowercase_cols=True).filter(
    scenario="historical", keep=False
)
scenarios
[3]:
<scmdata.ScmRun (timeseries: 480, timepoints: 751)>
Time:
        Start: 1750-01-01T00:00:00
        End: 2500-01-01T00:00:00
Meta:
                activity_id mip_era        model region          scenario   unit  \
        0    not_applicable   CMIP5          AIM  World             rcp60  W/m^2
        1    not_applicable   CMIP5          AIM  World             rcp60  W/m^2
        2    not_applicable   CMIP5          AIM  World             rcp60  W/m^2
        3    not_applicable   CMIP5          AIM  World             rcp60  W/m^2
        4    not_applicable   CMIP5          AIM  World             rcp60  W/m^2
        ..              ...     ...          ...    ...               ...    ...
        494  not_applicable   CMIP5  unspecified  World  historical-cmip5  W/m^2
        495  not_applicable   CMIP5  unspecified  World  historical-cmip5  W/m^2
        496  not_applicable   CMIP5  unspecified  World  historical-cmip5  W/m^2
        497  not_applicable   CMIP5  unspecified  World  historical-cmip5  W/m^2
        498  not_applicable   CMIP5  unspecified  World  historical-cmip5  W/m^2

                                                      variable
        0                                    Radiative Forcing
        1                      Radiative Forcing|Anthropogenic
        2             Radiative Forcing|Anthropogenic|Aerosols
        3    Radiative Forcing|Anthropogenic|Aerosols|Aeros...
        4    Radiative Forcing|Anthropogenic|Aerosols|Aeros...
        ..                                                 ...
        494  Radiative Forcing|Anthropogenic|Stratospheric ...
        495  Radiative Forcing|Anthropogenic|Tropospheric O...
        496                          Radiative Forcing|Natural
        497                    Radiative Forcing|Natural|Solar
        498                 Radiative Forcing|Natural|Volcanic

        [480 rows x 7 columns]

We can then run them, for a number of parameter settings, as shown.

[4]:
# NBVAL_IGNORE_OUTPUT
a_values = np.array([0, 0.01]) * ur("W/m^2/delta_degC^2")
a_values
[4]:
Magnitude
[0.0 0.01]
Unitswatt/(delta_degree_Celsius2 meter2)
[5]:
# NBVAL_IGNORE_OUTPUT
runner = TwoLayerModel()
output = []
for a in tqdman.tqdm(a_values, desc="Parameter settings"):
    runner.a = a
    output.append(runner.run_scenarios(scenarios))

output = run_append(output)
output
[5]:
<scmdata.ScmRun (timeseries: 80, timepoints: 751)>
Time:
        Start: 1750-01-01T00:00:00
        End: 2500-01-01T00:00:00
Meta:
            a (watt / delta_degree_Celsius ** 2 / meter ** 2)     activity_id  \
        0                                                0.00  not_applicable
        1                                                0.00  not_applicable
        2                                                0.00  not_applicable
        3                                                0.00  not_applicable
        4                                                0.00  not_applicable
        ..                                                ...             ...
        75                                               0.01  not_applicable
        76                                               0.01  not_applicable
        77                                               0.01  not_applicable
        78                                               0.01  not_applicable
        79                                               0.01  not_applicable

           climate_model  dl (meter)  du (meter)  efficacy (dimensionless)  \
        0      two_layer        1200          50                       1.0
        1      two_layer        1200          50                       1.0
        2      two_layer        1200          50                       1.0
        3      two_layer        1200          50                       1.0
        4      two_layer        1200          50                       1.0
        ..           ...         ...         ...                       ...
        75     two_layer        1200          50                       1.0
        76     two_layer        1200          50                       1.0
        77     two_layer        1200          50                       1.0
        78     two_layer        1200          50                       1.0
        79     two_layer        1200          50                       1.0

            eta (watt / delta_degree_Celsius / meter ** 2)  \
        0                                              0.8
        1                                              0.8
        2                                              0.8
        3                                              0.8
        4                                              0.8
        ..                                             ...
        75                                             0.8
        76                                             0.8
        77                                             0.8
        78                                             0.8
        79                                             0.8

            lambda0 (watt / delta_degree_Celsius / meter ** 2) mip_era          model  \
        0                                            1.246667    CMIP6        AIM/CGE
        1                                            1.246667    CMIP6        AIM/CGE
        2                                            1.246667    CMIP6        AIM/CGE
        3                                            1.246667    CMIP6        AIM/CGE
        4                                            1.246667    CMIP6        AIM/CGE
        ..                                                ...      ...            ...
        75                                           1.246667    CMIP6  REMIND-MAGPIE
        76                                           1.246667    CMIP6  REMIND-MAGPIE
        77                                           1.246667    CMIP6  REMIND-MAGPIE
        78                                           1.246667    CMIP6  REMIND-MAGPIE
        79                                           1.246667    CMIP6  REMIND-MAGPIE

           region  run_idx                   scenario        unit  \
        0   World        0                     ssp370       W/m^2
        1   World        0                     ssp370  delta_degC
        2   World        0                     ssp370  delta_degC
        3   World        0                     ssp370       W/m^2
        4   World        1  ssp370-lowNTCF-aerchemmip       W/m^2
        ..    ...      ...                        ...         ...
        75  World        8                ssp534-over       W/m^2
        76  World        9                     ssp585       W/m^2
        77  World        9                     ssp585  delta_degC
        78  World        9                     ssp585  delta_degC
        79  World        9                     ssp585       W/m^2

                               variable
        0   Effective Radiative Forcing
        1     Surface Temperature|Upper
        2     Surface Temperature|Lower
        3                   Heat Uptake
        4   Effective Radiative Forcing
        ..                          ...
        75                  Heat Uptake
        76  Effective Radiative Forcing
        77    Surface Temperature|Upper
        78    Surface Temperature|Lower
        79                  Heat Uptake

        [80 rows x 15 columns]
[6]:
# NBVAL_IGNORE_OUTPUT
pkwargs = dict(
    hue="scenario", style="a (watt / delta_degree_Celsius ** 2 / meter ** 2)",
)
fig = plt.figure(figsize=(12, 18))

ax = fig.add_subplot(211)
output.filter(variable="Surface Temperature|Upper").lineplot(**pkwargs, ax=ax)

ax = fig.add_subplot(212)
output.filter(variable="Heat Uptake").lineplot(**pkwargs, ax=ax)
[6]:
<AxesSubplot:xlabel='time', ylabel='W/m^2'>
../_images/usage_running-scenarios_8_1.png