-
Notifications
You must be signed in to change notification settings - Fork 0
/
ED_figure5.py
executable file
·222 lines (172 loc) · 6.32 KB
/
ED_figure5.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
#!/usr/bin/env python3
"""
Author: Victoria McDonald
email: [email protected]
website: http://torimcd.github.com
license: BSD
This script plots the surface energy balance for both CAM4 and CAM5 model output.
"""
import matplotlib
matplotlib.use("Agg")
import os
import sys
import numpy
import netCDF4
import operator
import matplotlib
import matplotlib.pyplot as plt
import processing_functions as pf
# ------------------------------------------------------------------------
# change this section to match where you downloaded the model output files
# ------------------------------------------------------------------------
download_path = '' # enter the path to the directory where you downloaded the archived data, eg '/home/user/Downloads'
filebase = download_path + 'FYSP_clouds_archive/CAM4/'
filebase_c5 = download_path + 'FYSP_clouds_archive/CAM5/'
outfileloc = download_path + 'temp_data/' # this is the location to save the processed netcdf files to
# ------------------------------------------
# field variables
fields = 'co2vmr,LHFLX,SHFLX,CLDLOW,CLDHGH,LWCF,SWCF,FSDS,FSDSC,FSNS,FSNSC,FLDS,FLDSC,FLNS,FLNSC'
pf.global_annual_average(filebase, outfileloc, fields, 'cam4')
pf.global_annual_average(filebase_c5, outfileloc, fields, 'cam5')
sw_dn = 'FSDS'
sw_net = 'FSNS'
lw_dn = 'FLDS'
lw_net = 'FLNS'
lhflx = 'LHFLX'
shflx = 'SHFLX'
outfilebase_c4 = 'c4_global_average_'
outfilebase_c5 = 'c5_global_average_'
casenames = ['07','0725','075','0775','08','0825','085','0875','09','0925','095','0975','10','1025','105','1075','11']
casenames_c5 = ['09','0925','095','0975','10','1025','105']
sc_all = [1.1, 1.075, 1.05, 1.025, 1.0, 0.975, 0.95, 0.925, 0.9, 0.875, 0.85, 0.825, 0.8, 0.775, 0.75, 0.725, 0.7]
sc_c5 = ['1.05','1.025','1.0', '0.975', '0.95','0.925','0.9']
#create plot
fig = plt.figure(figsize=(7.08661, 7.28346))
#fig = plt.figure(figsize=(10, 11))
ax = plt.subplot(211)
sw_dn_plot = []
sw_up_plot = []
sw_net_plot = []
lw_dn_plot = []
lw_up_plot = []
lw_net_plot = []
lhflx_plot = []
shflx_plot = []
sw_dn_plot_c5 = []
sw_up_plot_c5 = []
sw_net_plot_c5 = []
lw_dn_plot_c5 = []
lw_up_plot_c5 = []
lw_net_plot_c5 = []
lhflx_plot_c5 = []
shflx_plot_c5 = []
i=0
#plot the data
for CASE in casenames:
CASENAME = casenames[i]
dsloc = outfileloc + outfilebase_c4 + CASENAME + '.nc'
if os.path.isfile(dsloc):
swd = []
swdc = []
swn = []
swnc = []
lwd = []
lwdc = []
lwn = []
lwnc = []
lh = []
sh = []
# open the merged file and get out some variables
dsyear = netCDF4.Dataset(dsloc)
swd = dsyear.variables[sw_dn][:]
swn = dsyear.variables[sw_net][:]
lwd = dsyear.variables[lw_dn][:]
lwn = dsyear.variables[lw_net][:]
sh = dsyear.variables[shflx][:]
lh = dsyear.variables[lhflx][:]
dsyear.close() #close the file
swd = swd.flatten()
swn = swn.flatten()
lwd = lwd.flatten()
lwn = lwn.flatten()
sh = sh.flatten()
lh = lh.flatten()
sw_dn_plot.append(swd.item(0))
sw_net_plot.append(swn.item(0))
sw_up_plot.append((swn.item(0) - swd.item(0))*(-1))
lw_dn_plot.append(lwd.item(0))
lw_net_plot.append(lwn.item(0))
lw_up_plot.append((lwn.item(0) - lwd.item(0))*(-1))
lhflx_plot.append(lh.item(0))
shflx_plot.append(sh.item(0))
i+=1
i=0
for CASENAME in casenames_c5:
CASENAME = casenames_c5[i]
dsloc = outfileloc + outfilebase_c5 + CASENAME + '.nc'
if os.path.isfile(dsloc):
swd_c5 = []
swdc_c5 = []
swn_c5 = []
swnc_c5 = []
lwd_c5 = []
lwdc_c5 = []
lwn_c5 = []
lwnc_c5 = []
lh_c5 = []
sh_c5 = []
# open the merged file and get out some variables
dsyear = netCDF4.Dataset(dsloc)
swd_c5 = dsyear.variables[sw_dn][:]
swn_c5 = dsyear.variables[sw_net][:]
lwd_c5 = dsyear.variables[lw_dn][:]
lwn_c5 = dsyear.variables[lw_net][:]
sh_c5 = dsyear.variables[shflx][:]
lh_c5 = dsyear.variables[lhflx][:]
dsyear.close() #close the file
swd_c5 = swd_c5.flatten()
swn_c5 = swn_c5.flatten()
lwd_c5 = lwd_c5.flatten()
lwn_c5 = lwn_c5.flatten()
sh_c5 = sh_c5.flatten()
lh_c5 = lh_c5.flatten()
sw_dn_plot_c5.append(swd_c5.item(0))
sw_net_plot_c5.append(swn_c5.item(0))
sw_up_plot_c5.append((swn_c5.item(0) - swd_c5.item(0))*(-1))
lw_dn_plot_c5.append(lwd_c5.item(0))
lw_net_plot_c5.append(lwn_c5.item(0))
lw_up_plot_c5.append((lwn_c5.item(0) - lwd_c5.item(0))*(-1))
lhflx_plot_c5.append(lh_c5.item(0))
shflx_plot_c5.append(sh_c5.item(0))
i+=1
plt.plot(sc_all, sw_dn_plot, color='gold', marker='v', linestyle='-', label='Shortwave Down CAM4')
plt.plot(sc_all, sw_up_plot, color='olive', marker='^', linestyle='-', label='Shortwave Up CAM4')
plt.plot(sc_all, sw_net_plot, color='orange', marker='o', label='Shortwave Net CAM4')
plt.plot(sc_all, lw_dn_plot, color='dodgerblue', marker='v', linestyle='-', label='Longwave Down CAM4')
plt.plot(sc_all, lw_up_plot, color='skyblue', marker='^', linestyle='-', label='Longwave Up CAM4')
plt.plot(sc_all, lw_net_plot, color='blue', marker='o', label='Longwave Net CAM4')
plt.plot(sc_all, lhflx_plot, color='green', marker='s', linestyle='-', label='Latent Heat CAM4')
plt.plot(sc_all, shflx_plot, color='red', marker='s', linestyle='-', alpha=0.7, label='Sensible Heat CAM4')
plt.plot(sc_c5, sw_dn_plot_c5, color='black', marker='x', linestyle='--', label='CAM5')
plt.plot(sc_c5, sw_up_plot_c5, color='black', marker='x', linestyle='--')
plt.plot(sc_c5, sw_net_plot_c5, color='black', marker='x', linestyle='--')
plt.plot(sc_c5, lw_dn_plot_c5, color='black', marker='x', linestyle='--')
plt.plot(sc_c5, lw_up_plot_c5, color='black', marker='x', linestyle='--')
plt.plot(sc_c5, lw_net_plot_c5, color='black', marker='x', linestyle='--')
plt.plot(sc_c5, lhflx_plot_c5, color='black', marker='x', linestyle='--')
plt.plot(sc_c5, shflx_plot_c5, color='black', marker='x', linestyle='--')
#sort legend
handles, labels = ax.get_legend_handles_labels()
hl = sorted(zip(handles, labels), key=operator.itemgetter(1))
handles2, labels2 = zip(*hl)
# Display the legend below the plot
plt.legend(handles2, labels2, bbox_to_anchor=(0., -0.3, 1., .102), loc=3,ncol=3, mode="expand", borderaxespad=0., prop={"size":7})
plt.title('Global Average Surface Energy Budget', fontsize=7)
plt.xlabel(r'$\mathsf{S/S_0}$', fontsize=7)
plt.ylabel(r'$\mathsf{Flux}$' + ' ' +r'$\mathsf{(W/m^2)}$', fontsize=7)
plt.minorticks_on()
ax.tick_params(labelsize=7)
plt.axis([0.675,1.125,0,400])
plt.grid()
plt.show()
fig.savefig("figures_ED/ED_figure5.pdf", format='pdf', bbox_inches='tight')