-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch03_fig2b_code.py
300 lines (247 loc) · 10.4 KB
/
ch03_fig2b_code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# ch03_fig2b.py
# Description
# Generates Figure 3.2 panel b in the IPCC Working Group I Contribution to the Sixth Assessment Report: Chapter 3
# Creator: Anni Zhao ([email protected])
# Creator: Chris Brierley ([email protected])
# Creation Date: 1 Mar 2021
# Import packages
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import matplotlib
# Define markers for CMIP indicidual models:
markers = {'CMIP6':['o'],
'CMIP5':['x'],
'nonCMIP':['+']}
# Define markers for CMIP multi-model means:
avemarkers = {'CMIP6':['s'],
'CMIP5':['X'],
'nonCMIP':['P']}
# Define colors for experiments:
colors = {'LGM':['blue'],
'LIG':['lightblue'],
'MH':['lightsalmon'],
'mPWP':['red'],
'EECO':['darkred'],
'1pctCO2':['limegreen'],
'abrupt4xCO2':['violet']}
# Define experiment names
expt_names = {'LGM':['Last Glacial Maximum'],
'LIG':['Last Inter Glacial'],
'MH':['mid-Holocene'],
'mPWP':['mid-Piacenzian Warm Period'],
'EECO':['Early Eocene Climatic Optimum'],
'1pctCO2':['1pctCO2'],
'abrupt4xCO2':['abrupt4xCO2']}
# Function that loads and plots land and ocean temperature contrasts simulated by CMIP6 individual models
# Syntax
# [output] = ch03_fig2b_function1(input)
# Input arguments
# input - experiment name
# Output argument
# output - Plots the right CMIP6 data points in right color and marker according to the experiment name
def ch03_fig2b_function1(expt):
# load data
# Define the filename according to the input exoeriment name
fname = 'fig3.2b_%s_CMIP6.csv' %expt
DATA = pd.read_csv(fname,header=18)
Tsea = np.array(DATA['1'][0:len(DATA['1'])-1]).astype(float)
Tland = np.array(DATA['2'][0:len(DATA['1'])-1]).astype(float)
fig = plt.scatter(Tsea,Tland,marker="o",s=30,color=colors[expt][0],linewidths=1,facecolors='none',edgecolors=colors[expt][0])
return fig
# Function that loads and plots land and ocean temperature contrasts simulated by CMIP5 individual models
# Syntax
# [output] = ch03_fig2b_function2(input)
# Input argument
# input - experiment name
# Output argument
# output - Plots the right CMIP5 data points in right color and marker according to the experiment name
def ch03_fig2b_function2(expt):
# load data
# Define the filename according to the input exoeriment name
fname = 'fig3.2b_%s_CMIP5.csv' %expt
DATA = pd.read_csv(fname,header=18)
Tsea = np.array(DATA['1'][0:len(DATA['1'])-1]).astype(float)
Tland = np.array(DATA['2'][0:len(DATA['1'])-1]).astype(float)
fig = plt.scatter(Tsea,Tland,marker="x",s=30,color=colors[expt][0],linewidths=1,edgecolors=colors[expt][0])
return fig
# Function that loads and plots land and ocean temperature contrasts simulated by nonCMIP individual models
# Syntax
# [output] = ch03_fig2b_function3(input)
# Input arguments
# input - experiment name
# Output argument
# output - Plots the right CMIP6 data points in right color and marker according to the experiment name
def ch03_fig2b_function3(expt):
# load data
# Define the filename according to the input exoeriment name
fname = 'fig3.2b_%s_nonCMIP.csv' %expt
DATA = pd.read_csv(fname,header=19)
Tsea = np.array(DATA['1'][0:len(DATA['1'])-1]).astype(float)
Tland = np.array(DATA['2'][0:len(DATA['1'])-1]).astype(float)
fig = plt.scatter(Tsea,Tland,marker="+",s=30,color=colors[expt][0],linewidths=1,edgecolors=colors[expt][0])
return fig
# Function that loads and plots the ensemble mean of land and ocean temperature contrast in the CMIP6
# Syntax
# [output] = ch03_fig2b_function4(input)
# Input argument
# input - experiment name
# Output argument
# output - Plots the right CMIP6 data point in right color and marker according to the experiment name
def ch03_fig2b_function4(expt):
# load data
# Define the filename according to the input exoeriment name
fname = 'fig3.2b_%s_CMIP6_ensemble_mean.csv' %expt
DATA = pd.read_csv(fname,header=18)
Tsea = np.array(DATA['1'][0:len(DATA['1'])-1]).astype(float)
Tland = np.array(DATA['2'][0:len(DATA['1'])-1]).astype(float)
fig = plt.scatter(Tsea,Tland,marker="s",s=75,color=colors[expt][0],linewidths=1,facecolors='none',edgecolors=colors[expt][0],label=expt)
return fig
# Function that loads and plots the ensemble mean of land and ocean temperature contrast in the CMIP5
# Syntax
# [output] = ch03_fig2b_function5(input)
# Input arguments
# input - experiment name
# Output argument
# output - Plots the right CMIP5 data point in right color and marker according to the experiment name
def ch03_fig2b_function5(expt):
# load data
# Define the filename according to the input exoeriment name
fname = 'fig3.2b_%s_CMIP5_ensemble_mean.csv' %expt
DATA = pd.read_csv(fname,header=18)
Tsea = np.array(DATA['1'][0:len(DATA['1'])-1]).astype(float)
Tland = np.array(DATA['2'][0:len(DATA['1'])-1]).astype(float)
fig = plt.scatter(Tsea,Tland,marker="X",s=75,color=colors[expt][0],linewidths=1,edgecolors=colors[expt][0])
return fig
# Function that loads and plots the ensemble mean of land and ocean temperature contrast in the nonCMIP
# Syntax
# [output] = ch03_fig2b_function6(input)
# Input arguments
# input - experiment name
# Output argument
# output - Plots the right nonCMIP data point in right color and marker according to the experiment name
def ch03_fig2b_function6(expt):
# load data
# Define the filename according to the input exoeriment name
fname = 'fig3.2b_%s_nonCMIP_ensemble_mean.csv' %expt
DATA = pd.read_csv(fname,header=19)
Tsea = np.array(DATA['1'][0:len(DATA['1'])-1]).astype(float)
Tland = np.array(DATA['2'][0:len(DATA['1'])-1]).astype(float)
fig = plt.scatter(Tsea,Tland,marker="P",s=75,color=colors[expt][0],linewidths=1,edgecolors=colors[expt][0])
return fig
# Function that loads and plots the Instrumental land and sea temperature contrast
# Syntax
# [output] = ch03_fig2b_function7(input)
# Input arguments
# input - experiment name
# Output argument
# output - Plots the instrumental data point in right color and marker according to the experiment name
def ch03_fig2b_function7():
# load data
# Define the filename according to the input exoeriment name
fname = 'fig3.2b_observation_instrumental.csv'
DATA = pd.read_csv(fname,header=18)
Tsea = np.array(DATA['1'][0:len(DATA['1'])-1]).astype(float)
Tland = np.array(DATA['2'][0:len(DATA['1'])-1]).astype(float)
fig = plt.scatter(Tsea, Tland,marker='D',s=60,color='k',linewidths=1,facecolors='none',label='Instrumental')
return fig
# Function that loads and plots the reconstructed land and sea temperature contrast
# Syntax
# [output] = ch03_fig2b_function8(input)
# Input arguments
# input - experiment name
# Output argument
# output - Plots the reconstruction data point in right color and marker according to the experiment name
def ch03_fig2b_function8():
# load data
# Define the filename according to the input exoeriment name
fname = 'fig3.2b_observation_reconstruction.csv'
DATA = pd.read_csv(fname,header=18)
Tsea = np.array(DATA['1'][0:len(DATA['1'])-1]).astype(float)
Tland = np.array(DATA['2'][0:len(DATA['1'])-1]).astype(float)
fig = plt.errorbar(Tsea, Tland, xerr=0.01,yerr=0.01,marker='*',ecolor='k',color='lightsalmon',ms=6,ls='none',label='Reconstruction')
return fig
# Plot the panel b in figure 2 in chapter 3
# Set figure size to 9cm x 12cm
# Change the size unit from cm to inch by deviding 2.54
plt.figure(figsize=(9/2.54,12/2.54))
ax = plt.subplot(111)
# Setups
# Set title
plt.title('b) Global temperature change over \nland and ocean for a range of climates',fontsize=9,pad=5,loc='left')
# Set labels and ticks of axes
plt.xlabel('Temperature change over sea (%sC)'%(chr(176)),fontsize=9)
plt.ylabel('Temperature change over land (%sC)'%(chr(176)),fontsize=9)
plt.xticks(fontsize=9)
plt.yticks(fontsize=9)
# Add grey dotted lines to indicate the zero levels
plt.axvline(x=0,color='grey',linestyle="dotted",linewidth=0.5)
plt.axhline(y=0,color='grey',linestyle="dotted",linewidth=0.5)
# Set axes limits
plt.xlim([-11,20])
plt.ylim([-15,25])
# Set boundary edges
for axis in ['top','bottom','left','right']:
ax.spines[axis].set_linewidth(0.5)
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
# Plotting individual models
# CMIP6
ch03_fig2b_function1('LGM')
ch03_fig2b_function1('LIG')
ch03_fig2b_function1('MH')
ch03_fig2b_function1('mPWP')
ch03_fig2b_function1('EECO')
ch03_fig2b_function1('1pctCO2')
ch03_fig2b_function1('abrupt4xCO2')
#CMIP5
ch03_fig2b_function2('MH')
ch03_fig2b_function2('LGM')
ch03_fig2b_function2('1pctCO2')
ch03_fig2b_function2('abrupt4xCO2')
# nonCMIP
ch03_fig2b_function3('LGM')
ch03_fig2b_function3('LIG')
ch03_fig2b_function3('MH')
ch03_fig2b_function3('mPWP')
ch03_fig2b_function3('EECO')
# Plotting multi-model means
# CMIP6
ch03_fig2b_function4('LGM')
ch03_fig2b_function4('MH')
ch03_fig2b_function4('LIG')
ch03_fig2b_function4('mPWP')
ch03_fig2b_function4('EECO')
ch03_fig2b_function4('1pctCO2')
ch03_fig2b_function4('abrupt4xCO2')
#CMIP5
ch03_fig2b_function5('MH')
ch03_fig2b_function5('LGM')
ch03_fig2b_function5('1pctCO2')
ch03_fig2b_function5('abrupt4xCO2')
# nonCMIP
ch03_fig2b_function6('LGM')
ch03_fig2b_function6('MH')
ch03_fig2b_function6('LIG')
ch03_fig2b_function6('mPWP')
ch03_fig2b_function6('EECO')
# Instrumental
ch03_fig2b_function7()
# Reconstruction
ch03_fig2b_function8()
# Regression line
XX = np.arange(-11,20,0.5)
X2 = XX*XX
Yall = X2*(-0.019470) + XX*(1.580454)
plt.plot(XX,Yall,'k',label='Fit to data:')
# Set legend names
# Individual models
plt.scatter(-50, -50,marker=markers['CMIP6'][0],s=30,color='k',linewidths=1,edgecolors='k',facecolors='none',label='CMIP6')
plt.scatter(-50, -50,marker=markers['CMIP5'][0],s=30,color='k',linewidths=1,edgecolors='k',label='CMIP5')
plt.scatter(-50, -50,marker=markers['nonCMIP'][0],s=30,color='k',linewidths=1,edgecolors='k',label='non-CMIP')
# Multi-model means
plt.scatter(-50, -50,marker=avemarkers['CMIP6'][0],s=75,color='k',linewidths=1,edgecolors='k',facecolors='none',label='CMIP6')
plt.scatter(-50, -50,marker=avemarkers['CMIP5'][0],s=75,color='k',linewidths=1,edgecolors='k',facecolors='none',label='CMIP5')
plt.scatter(-50, -50,marker=avemarkers['nonCMIP'][0],s=75,color='k',linewidths=1,edgecolors='k',facecolors='none',label='non-CMIP')
leg = plt.legend(edgecolor='None',facecolor='None',markerfirst=False,fontsize=9)
plt.show()