source: LMDZ6/trunk/libf/phylmd/ecrad/test/ifs/plot_ifs.py @ 5423

Last change on this file since 5423 was 4773, checked in by idelkadi, 13 months ago
  • Update of Ecrad in LMDZ The same organization of the Ecrad offline version is retained in order to facilitate the updating of Ecrad in LMDZ and the comparison between online and offline results. version 1.6.1 of Ecrad (https://github.com/lguez/ecrad.git)
  • Implementation of the double call of Ecrad in LMDZ


File size: 4.5 KB
Line 
1from netCDF4 import Dataset
2import numpy as np
3import matplotlib.pyplot as plt
4
5#% This python scripts plots some of the inputs to the radiation scheme
6#% in Fig. 1 and the outputs in Fig. 2
7code = 'ecrad_meridian'
8in_file=Dataset(code+'.nc','r')
9pressure_hl=in_file.variables['pressure_hl'][:]
10temperature_hl=in_file.variables['temperature_hl'][:]
11lat=in_file.variables['lat'][:]
12cos_solar_zenith_angle=in_file.variables['cos_solar_zenith_angle'][:]
13skin_temperature=in_file.variables['skin_temperature'][:]
14cloud_fraction=in_file.variables['cloud_fraction'][:]
15aerosol_mmr=in_file.variables['aerosol_mmr'][:]
16cases = [code+'_noaer_out.nc',
17         code+'_default_out.nc',
18         code+'_expran_out.nc',
19         code+'_tc_out.nc',
20         code+'_spartacus_out.nc',
21         code+'_spartacus_maxentr_out.nc']
22
23
24f = [0]*6
25k=0
26for icase in cases:
27    f[k] = Dataset(icase,'r')
28    k=k+1
29
30
31
32case_list = [0,1,2,3,4,5]
33leg = ['McICA Exp-Exp no aerosols',
34       'McICA Exp-Exp',
35       'McICA Exp-Ran',
36       'Tripleclouds Exp-Ran',
37       'SPARTACUS Exp-Ran',
38       'Classic SPARTACUS Exp-Ran']
39
40styles = ['b','r','g','m','c','k']
41
42
43p = 0.01*0.5*np.median(pressure_hl[:,0:-1]+pressure_hl[:,1::],0)
44
45nplot=4
46plt.figure(1,figsize=(10,10))
47# set(gcf,'defaultlinelinewidth',1);
48# set(gcf,'units','inches','paperposition',[0.5 0.5 15 30]);
49# nplot = 4;
50#fig, (ax0, ax1) = plt.subplots(nrows=2)
51
52plt.subplot(nplot,1,1)
53plt.plot(lat,cos_solar_zenith_angle,color='k', linewidth=2.0)
54ax= plt.gca()
55ax.set_xlim([-90,90])
56plt.ylabel('Cos solar zenith ang.')
57
58
59plt.subplot(nplot,1,2)
60plt.plot(lat,skin_temperature-273.15,color='r',linewidth=2.0,label='Skin temperature')
61plt.plot(lat,temperature_hl[:,-1]-273.15,color='b', linewidth=2.0,label='Air between first two model levels')
62plt.gca().set_xlim([-90,90])
63plt.ylabel('Temperature ($^\circ$C)');
64plt.gca().set_ylim([-50,60]);
65plt.gca().legend(loc='best',fontsize='xx-small')
66
67plt.subplot(nplot,1,3)
68CS=plt.contourf(lat,p,cloud_fraction.T,10, vmin=0.05, vmax=0.95,cmap="viridis")
69plt.colorbar()
70plt.contour(CS,levels=CS.levels[::4],colors='k')
71plt.gca().set_ylim([0,1013])
72plt.gca().invert_yaxis()
73plt.gca().set_xlim([-90,90])
74plt.ylabel('Pressure (hPa)')
75textstyle = dict(size=10, color='white')
76plt.gca().text(-70,100,'Cloud fraction',**textstyle)
77# text(-90, 0, [' ' 10 '  Cloud fraction'],'verticalalignment','top')
78
79
80print(aerosol_mmr.shape)
81plt.subplot(nplot,1,4)
82sea_salt = 1e9*np.sum(aerosol_mmr[:,0:2,-1],1);
83dust = 1e9*np.sum(aerosol_mmr[:,3:5,-1],1);
84organics = 1e9*np.sum(aerosol_mmr[:,6:7,-1],1);
85black_carbon = 1e9*np.sum(aerosol_mmr[:,8:9,-1],1);
86sulphate = 1e9*np.sum(aerosol_mmr[:,10:11,-1],1);
87
88plt.semilogy(lat,sea_salt,'b',label='Sea salt')
89plt.semilogy(lat,dust,'r',label='Dust')
90plt.semilogy(lat,organics,'g',label='Organics')
91plt.semilogy(lat,black_carbon,'k',label='Black carbon')
92plt.semilogy(lat,sulphate,'m',label='Sulphate')
93plt.gca().legend(loc='best',fontsize='xx-small')
94plt.ylabel('Aerosol mass mixing ratio\n ($\mu$g/kg)')
95plt.xlabel('Latitude (deg N)')
96plt.gca().set_xlim([-90,90])
97
98plt.savefig('input.png')
99
100nplot=4
101plt.figure(2,figsize=(10,10))
102# set(gcf,'defaultlinelinewidth',1);
103# set(gcf,'units','inches','paperposition',[0.5 0.5 15 30]);
104
105plt.subplot(nplot,1,1)
106for icase in case_list:
107    print(leg[icase])
108    plt.plot(lat, f[icase].variables['flux_dn_sw'][:,-1],label=leg[icase])
109    plt.gca().set_xlim([-90, 90]);
110    plt.ylabel('Surface SW down \n(W m$^{-2}$)');
111    plt.gca().legend(loc='best',fontsize='xx-small')
112
113
114plt.subplot(nplot,1,2)
115for icase in case_list:
116    cre =  f[icase].variables['flux_dn_sw'][:,1]-f[icase].variables['flux_dn_sw_clear'][:,1]-f[icase].variables['flux_up_sw'][:,1]+f[icase].variables['flux_up_sw_clear'][:,1]
117    plt.plot(lat, cre,label=leg[icase])
118    plt.gca().set_xlim([-90, 90]);
119    plt.ylabel('SW cloud radiative effect \n(W m$^{-2}$)');
120    plt.gca().legend(loc='best',fontsize='xx-small')
121
122
123plt.subplot(nplot,1,3)
124for icase in case_list:
125    cre =  f[icase].variables['flux_dn_lw'][:,1]-f[icase].variables['flux_dn_lw_clear'][:,1]-f[icase].variables['flux_up_lw'][:,1]+f[icase].variables['flux_up_lw_clear'][:,1]
126    plt.plot(lat, cre,label=leg[icase])
127    plt.gca().set_xlim([-90, 90]);
128    plt.ylabel('LW cloud radiative effect \n(W m$^{-2}$)');
129    plt.gca().legend(loc='best',fontsize='xx-small')
130
131plt.subplot(nplot,1,4)
132for icase in case_list:
133    plt.plot(lat, f[icase].variables['cloud_cover_sw'],label=leg[icase]);
134    plt.gca().set_xlim([-90, 90]);
135    plt.ylabel('Cloud cover');
136    plt.gca().legend(loc='best',fontsize='xx-small')
137    plt.xlabel('Latitude (deg N)');
138
139
140plt.savefig('output.png')
141#plt.show()
Note: See TracBrowser for help on using the repository browser.