-
Notifications
You must be signed in to change notification settings - Fork 0
/
figure5.py
executable file
·135 lines (98 loc) · 3.36 KB
/
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
#!/usr/bin/env python3
"""
Author: Victoria McDonald
email: vmcd@atmos.washington.edu
website: http://torimcd.github.com
license: BSD
"""
import matplotlib
matplotlib.use("Agg")
import os
import sys
import numpy as np
import netCDF4
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from matplotlib import ticker
from mpl_toolkits.basemap import Basemap
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/'
outfileloc = download_path + 'temp_data/' # this is the location to save the processed netcdf files to
# ------------------------------------
fields = 'LWCF,SWCF'
pf.cloud_forcing_all(filebase, outfileloc, fields, 'cam4')
outfilebase = 'c4_cloudforcing'
outer_grid = gridspec.GridSpec(2, 1, wspace=0.1, hspace=0.1)
#create plot
fig = plt.figure(figsize=(7.08661, 8))
i=0
n=0
l=0
swcf = 'SWCF'
lwcf = 'LWCF'
present = '_10'
casenames = ['_11','_105','_10','_095','_09','_085','_08','_075','_07' ]
while i<2:
inner_grid = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=outer_grid[i], wspace=0.0, hspace=0.3)
if i==0:
field = swcf
outfilebase=outfilebase
else:
field = lwcf
outfilebase=outfilebase
n=0
l=1
for y in casenames:
CASENAME = casenames[n]
ax = fig.add_subplot(inner_grid[n])
n=n+1
#plot the data
presentcase = outfileloc + outfilebase + present +'.nc'
currentcase = outfileloc + outfilebase + CASENAME +'.nc'
ds = netCDF4.Dataset(presentcase)
presfld = ds.variables[field][:]
lats = ds.variables['lat'][:]
lons = ds.variables['lon'][:]
ds = netCDF4.Dataset(currentcase)
cfld = ds.variables[field][:]
lats = ds.variables['lat'][:]
lons = ds.variables['lon'][:]
# setup the map
m = Basemap(lat_0=0,lon_0=0,ax=ax)
m.drawcoastlines()
m.drawcountries()
parallels = [-45, 0, 45]
meridians = [-90., 0., 90.]
if n==1 or n==4 or n==7:
m.drawparallels(parallels, labels=[True ,False,False, False], fontsize=6)
else:
m.drawparallels(parallels, labels=[False ,False,False, False], fontsize=6)
m.drawmeridians(meridians,labels=[False,False,False,True], fontsize=6)
# Create 2D lat/lon arrays for Basemap
lon2d, lat2d = np.meshgrid(lons, lats)
# Plot
cs = m.pcolormesh(lon2d,lat2d,np.squeeze(cfld) - np.squeeze(presfld), cmap='RdBu_r', latlon='True', vmin=-60, vmax=60, rasterized=True)
fig.add_subplot(ax)
# This is the fix for the white lines between contour levels
cs.set_edgecolor("face")
# add letter annotation
if l==0:
plt.text(-0.10, 1.0, "a", fontsize=6, fontweight="bold", transform=ax.transAxes)
elif l==1:
plt.text(-0.10, 1.0, "b", fontsize=6, fontweight="bold", transform=ax.transAxes)
l=l+2
ax.set_title(CASENAME[1]+'.'+CASENAME[-1], fontsize=7)
i=i+1
# Add Colorbar
fig.subplots_adjust(right=0.8)
cbar_ax = fig.add_axes([0.85, 0.15, 0.02, 0.7])
cb = fig.colorbar(cs, cax=cbar_ax)
cb.set_label(label=r'$\mathsf{W/m^2}$', fontsize=6)
cb.ax.tick_params(labelsize=6)
cb.update_ticks()
plt.show()
fig.savefig("figures_main/figure5.pdf", format='pdf',bbox_inches='tight')