Commit 23792d89 authored by Sebastian Milinski's avatar Sebastian Milinski
Browse files

Replace figure4.11.ipynb

parent 31e9b2f0
%% Cell type:markdown id:e4b66f47-59e9-4e60-bde1-5270f7ea2aac tags:
 
# figure 4.11 code
This notebook contains the code to produce figure 4.11 from the AR6 WGI report. A detailed description of the analysis, results, and implications can be found in Box 4.1 and section 4.3.4.
# Figure 4.11 and assessed GSAT code
This notebook contains the code to **produce figure 4.11** from the AR6 WGI report and **create time series for assessed GSAT change**. A detailed description of the analysis, results, and implications can be found in Box 4.1 and section 4.3.4.
 
The following input data is stored in the `input_data` directory:
- `ssp_erf` effective radiative forcing time series from the chapter 7 assessment
- `constrained_cmip6` unconstrained and constrained CMIP6 GSAT projections from 3 published manuscripts
 
To run this notebook, make sure to have the following python packages installed:
- matplotlib
- numpy
- XArray
- pandas
- tqdm
- cdo (python-cdo)
All packages can be found on conda-forge.
 
%% Cell type:markdown id:2bacfbd7-7f06-4b46-b035-7257e3751854 tags:
 
## setup
 
%% Cell type:code id:c6bfecb1-11a3-4bf7-863a-0353a2b28af1 tags:
 
``` python
# load required packages
 
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['figure.dpi'] = 300
 
import numpy as np
import xarray as xr
import pandas as pd
import os
from tqdm import tqdm
 
# Import Cdo-py
import cdo
cdo = cdo.Cdo() #
```
 
%% Cell type:code id:36d786cb-fe93-4498-8840-9f92cb9ca35c tags:
 
``` python
# set up directories
 
plotdir = './plots/'
if not os.path.exists(plotdir):
os.makedirs(plotdir)
 
basedir_data = 'input_data/'
```
 
%% Cell type:code id:d5727547-3e57-4176-9181-eea521b68104 tags:
 
``` python
# color settings and labels
 
# colors
opacity=0.2
 
color_119=[30/255,150/255,132/255]
color_119_shading = [opacity*rgb_value + (1-opacity) for rgb_value in color_119]
color_126=[29/255,51/255,84/255]
color_126_shading = [opacity*rgb_value + (1-opacity) for rgb_value in color_126]
color_245=[155/255,135/255,12/255]
color_245_shading = [opacity*rgb_value + (1-opacity) for rgb_value in color_245]
color_370=[242/255,17/255,17/255]
color_370_shading = [opacity*rgb_value + (1-opacity) for rgb_value in color_370]
color_585=[132/255,11/255,34/255]
color_585_shading = [opacity*rgb_value + (1-opacity) for rgb_value in color_585]
color_historical = [160/255,160/255,160/255]
color_historical_shading = [opacity*rgb_value + (1-opacity) for rgb_value in color_historical]
 
# scenario names
label_ssp119 = 'SSP1-1.9'
label_ssp126 = 'SSP1-2.6'
label_ssp245 = 'SSP2-4.5'
label_ssp370 = 'SSP3-7.0'
label_ssp585 = 'SSP5-8.5'
```
 
%% Cell type:code id:770bcf73-dbb6-4227-a7ed-a2b346eeca3b tags:
 
``` python
# settings for modern reference time period and proxy for pre-industrial time period
refperiod_start = 1995
refperiod_end = 2014
piperiod_start = 1850
piperiod_end = 1900
 
# historical warming estimate based on cross-chapter box 2.3
refperiod_conversion = 0.85
```
 
%% Cell type:code id:076add0c-a5ed-4ccd-ab50-98abcebe4c32 tags:
 
``` python
# settings for emulator based on chapter 7 assessment
 
# Forcing from a doubling of CO2:
f2x = 4.0
 
# central estimates for ECS and TCR
ECS = 3
TCR = 1.8
 
# very likely and likely range for ECS
ECS_vll = 2 # very likely low
ECS_ll = 2.5 # likely low
ECS_lh = 4 # likely high
ECS_vlh = 5 # very likely high
 
# very likely and likely range for TCR
TCR_vll = 1.2 # very likely low
TCR_ll = 1.4 # likely low
TCR_lh = 2.2 # likely high
TCR_vlh = 2.4 # very likely high
```
 
%% Cell type:markdown id:17151586-bd31-4e58-be23-ce4cf217998a tags:
 
<div class="alert alert-block alert-info"> <b>NOTE</b> Note that likely ranges are not used in figure 4, but included here for convenience. </div>
 
%% Cell type:markdown id:ff89cb0b-8606-4be8-8c0f-e0639dbe78ef tags:
 
## define functions
 
%% Cell type:code id:f034d23d-5724-44ad-a6c7-a3602615b865 tags:
 
``` python
```
 
%% Cell type:markdown id:f97cbbc7-13f3-4628-8a67-4ada59335e26 tags:
 
## define and run the emulator
A 2-layer energy balance model is tuned to the chapter 7 assessed ECS/TCR and forced with chapter 7 effective radiative forcing (ERF) time series.
 
%% Cell type:markdown id:daeea4e5-8752-4abb-b3ed-03c2c85708be tags:
 
### load ERF time series
 
%% Cell type:code id:467c9c1a-1ca9-4ff8-9c47-1844fd046dbe tags:
 
``` python
erf_dir = basedir_data + 'ssp_erf/'
erf_119_file = erf_dir + 'ERF_ssp119_1750-2500.csv'
erf_126_file = erf_dir + 'ERF_ssp126_1750-2500.csv'
erf_245_file = erf_dir + 'ERF_ssp245_1750-2500.csv'
erf_370_file = erf_dir + 'ERF_ssp370_1750-2500.csv'
erf_585_file = erf_dir + 'ERF_ssp585_1750-2500.csv'
```
 
%% Cell type:markdown id:82dc70d7-b380-49b3-8a88-c6b6918fd62b tags:
 
#### normalise ERF
- remove volcanic forcing from total
- normalise remaining for 1850
- add volcanic forcing to normalised time series
 
%% Cell type:code id:3b717d58-44ba-4a04-9d86-3a5e73a41650 tags:
 
``` python
# load ERF
 
collumn_titles = [ 'year', 'co2', 'ch4', 'n2o', 'other_wmghg', \
'o3', 'h2o_stratospheric', 'contrails', 'aerosol_radiation_interactions', \
'aerosol_cloud_interactions', 'bc_on_snow', 'land_use', 'volcanic', 'solar', \
'total_anthropogenic', 'total_natural', 'total' ]
 
# SSP1-1.9
erf_119 = np.genfromtxt(erf_119_file,delimiter=',', skip_header=1)
 
erf_119_year = erf_119[:,collumn_titles.index('year')]
erf_119_total_raw = erf_119[:,collumn_titles.index('total')]
erf_119_volcanic = erf_119[:,collumn_titles.index('volcanic')]
 
erf_119_novolcanic = erf_119_total_raw - erf_119_volcanic
erf_119_novolcanic_norm = erf_119_novolcanic - erf_119_novolcanic[np.where( erf_119_year == 1850)]
 
erf_119_total = erf_119_novolcanic_norm + erf_119_volcanic
 
 
# SSP1-2.6
erf_126 = np.genfromtxt(erf_126_file,delimiter=',', skip_header=1)
 
erf_126_year = erf_126[:,collumn_titles.index('year')]
erf_126_total_raw = erf_126[:,collumn_titles.index('total')]
erf_126_volcanic = erf_126[:,collumn_titles.index('volcanic')]
 
erf_126_novolcanic = erf_126_total_raw - erf_126_volcanic
erf_126_novolcanic_norm = erf_126_novolcanic - erf_126_novolcanic[np.where( erf_126_year == 1850)]
 
erf_126_total = erf_126_novolcanic_norm + erf_126_volcanic
 
# SSP2-4.5
erf_245 = np.genfromtxt(erf_245_file,delimiter=',', skip_header=1)
 
erf_245_year = erf_245[:,collumn_titles.index('year')]
erf_245_total_raw = erf_245[:,collumn_titles.index('total')]
erf_245_volcanic = erf_245[:,collumn_titles.index('volcanic')]
 
erf_245_novolcanic = erf_245_total_raw - erf_245_volcanic
erf_245_novolcanic_norm = erf_245_novolcanic - erf_245_novolcanic[np.where( erf_245_year == 1850)]
 
erf_245_total = erf_245_novolcanic_norm + erf_245_volcanic
 
# SSP3-7.0
erf_370 = np.genfromtxt(erf_370_file,delimiter=',', skip_header=1)
 
erf_370_year = erf_370[:,collumn_titles.index('year')]
erf_370_total_raw = erf_370[:,collumn_titles.index('total')]
erf_370_volcanic = erf_370[:,collumn_titles.index('volcanic')]
 
erf_370_novolcanic = erf_370_total_raw - erf_370_volcanic
erf_370_novolcanic_norm = erf_370_novolcanic - erf_370_novolcanic[np.where( erf_370_year == 1850)]
 
erf_370_total = erf_370_novolcanic_norm + erf_370_volcanic
 
# SSP5-8.5
erf_585 = np.genfromtxt(erf_585_file,delimiter=',', skip_header=1)
 
erf_585_year = erf_585[:,collumn_titles.index('year')]
erf_585_total_raw = erf_585[:,collumn_titles.index('total')]
erf_585_volcanic = erf_585[:,collumn_titles.index('volcanic')]
 
erf_585_novolcanic = erf_585_total_raw - erf_585_volcanic
erf_585_novolcanic_norm = erf_585_novolcanic - erf_585_novolcanic[np.where( erf_585_year == 1850)]
 
erf_585_total = erf_585_novolcanic_norm + erf_585_volcanic
```
 
%% Cell type:markdown id:95903700-ada2-4960-af05-9c1ab69ca5ff tags:
 
#### visualize forcing normalization
 
%% Cell type:code id:ebefc0a3-cb9e-4df7-89c9-ab7b5fd1795e tags:
 
``` python
fig, axes = plt.subplots(1,1, figsize=(15,6))
 
 
axes.plot(erf_119_year,erf_119_total_raw,color='black',label="total raw")
axes.plot(erf_119_year,erf_119_novolcanic,color='darksalmon',label="total - volcanic")
axes.plot(erf_119_year,erf_119_volcanic,color='brown',label="volcanic")
axes.plot(erf_119_year,erf_119_novolcanic_norm,color='red',label="(total - volcanic) norm. 1850")
axes.plot(erf_119_year,erf_119_total,color=color_119,label="total")
# axes.plot(erf_119_year,erf_119_total_volc0,color=color_119,linestyle=':',label="total (volc. ERF = 0)")
 
legend = axes.legend(loc='upper left', shadow=False, fontsize='medium')
 
axes.plot([erf_119_year[0],erf_119_year[-1]],[0,0],color='black',linewidth=0.5,zorder=0)
 
 
axes.set_xlim([1750,2100])
axes.set_ylim([-4,4])
axes.set_xlabel('Time (years)')
axes.set_ylabel(r'ERF ($\frac{W}{m^2}$)')
axes.set_title('ERF for SSP1-1.9')
 
ax2 = axes.twinx()
mn, mx = axes.get_ylim()
ax2.set_ylim(mn, mx);
 
 
 
 
```
 
%% Output
 
 
%% Cell type:markdown id:03b8f0e5-8c85-4e1e-b061-7c795716f508 tags:
 
#### visualize forcing time series for all scenarios
 
%% Cell type:code id:bffe0ecf-c8e2-401a-a137-af76ef5552f6 tags:
 
``` python
fig, axes = plt.subplots(1,1, figsize=(15,6))
 
 
axes.plot(erf_119_year,erf_119_total,color=color_119,label="total "+label_ssp119)
 
 
axes.plot(erf_126_year,erf_126_total,color=color_126,label="total "+label_ssp126)
axes.plot(erf_245_year,erf_245_total,color=color_245,label="total "+label_ssp245)
axes.plot(erf_370_year,erf_370_total,color=color_370,label="total "+label_ssp370)
axes.plot(erf_585_year,erf_585_total,color=color_585,label="total "+label_ssp585)
 
 
legend = axes.legend(loc='upper left', shadow=False, fontsize='medium')
 
 
 
axes.set_xlim([1850,2100])
axes.set_ylim([-1.5,10])
axes.set_xlabel('Time (years)')
axes.set_ylabel(r'ERF ($\frac{W}{m^2}$)')
axes.set_title('ERF for different scenarios')
 
ax2 = axes.twinx()
mn, mx = axes.get_ylim()
ax2.set_ylim(mn, mx);
 
 
 
 
 
```
 
%% Output
 
 
%% Cell type:markdown id:87e5cbf2-e00e-4598-9940-d851be9884f5 tags:
 
### define the emulator
 
%% Cell type:code id:697feb63-72b4-46e2-b206-2a2d15df5e24 tags:
 
``` python
#--------------------------------------------------------------------------