source: dynamico_lmdz/aquaplanet/CMIP5a/RUN_AQUAPLANET_DYNAMICO_LMDZ5/figs_fluxes.py @ 4100

Last change on this file since 4100 was 4100, checked in by dubos, 7 years ago

aquaplanet/CMIP5a : post-processing scripts

File size: 2.1 KB
Line 
1import numpy as np
2import netCDF4 as cdf
3# select non-interactive backend, cf http://stackoverflow.com/questions/4931376/generating-matplotlib-graphs-without-a-running-x-server
4import matplotlib
5matplotlib.use('Agg') 
6import matplotlib.pyplot as plt
7
8def getdims(nc, *names): return [len(nc.dimensions[name]) for name in names]
9def getvars(nc, *names): return [nc.variables[name] for name in names]
10
11#--------------------------- MAIN ----------------------------
12
13infile = 'diagflux.nc'
14nc = cdf.Dataset(infile, "r")
15print nc
16llm, nlat = getdims(nc, 'lev','lat_dom_out')
17Lv, Cpd, kappa, g, perim = 2.5e6, 1004.5, 0.2857143, 9.80616, 4e7
18
19(lat,p,qflux,q,epotflux,epot,
20 ekinflux,ekin,cpTflux,cpT,mass,mflux) = getvars(nc,
21                                                'lat_dom_out','p','qflux_lat','qmass_t','epotflux_lat','epot_t','ekinflux_lat','ekin_t',
22                                                'enthalpyflux_lat','enthalpy_t','mass_t','massflux_lat')
23
24lat,p,epotflux,epot,ekinflux,ekin,cpTflux,cpT,mass,mflux = [ x[:] for x in lat,p,epotflux,epot,ekinflux,ekin,cpTflux,cpT,mass,mflux ] # read data from file
25qflux,q = qflux[0,:,:], q[0,:,:]
26
27perim = 4e7*np.cos(lat*np.pi/180.) # geometric factor
28stream = mflux.cumsum(axis=0)
29for i in range(lat.size):
30    stream[:,i]=stream[:,i]*perim[i]
31p=p.mean(axis=1)
32
33print qflux.shape, q.shape, stream.shape
34# cpT est en (J/m^2)
35# cpTflux est en (J/m^2)*(m/s)
36
37cpTflux = cpTflux - (cpT/mass)*mflux # flux "turbulents"
38qflux = qflux - (q/mass)*mflux # flux "turbulents"
39
40qflux,cpTflux,mass = [ x.sum(axis=0) for x in qflux,cpTflux,mass ] # somme sur la verticale
41# cpTflux est en (J/m^2)*(m/s)=W/m
42
43print cpTflux.shape, p.shape
44
45cpTflux = cpTflux*perim
46qflux   = qflux*perim
47# cpTflux est en W
48
49plt.figure()
50plt.plot(lat,cpTflux)
51plt.title('Meridional enthalpy flux (W)')
52plt.savefig('enthalpy_flux.png')
53plt.close()
54
55plt.figure()
56plt.plot(lat,Lv*qflux)
57plt.title('Meridional latent heat flux (W)')
58plt.savefig('latent_heat_flux.png')
59plt.close()
60
61plt.figure()
62plt.contourf(lat,p,stream,20)
63plt.ylim(1e5, 0)
64plt.title('Meridional stream function (kg/s)')
65plt.colorbar()
66plt.savefig('stream.png')
67plt.close()
Note: See TracBrowser for help on using the repository browser.