1 | import numpy as np |
---|
2 | import netCDF4 as cdf |
---|
3 | # select non-interactive backend, cf http://stackoverflow.com/questions/4931376/generating-matplotlib-graphs-without-a-running-x-server |
---|
4 | import matplotlib |
---|
5 | matplotlib.use('Agg') |
---|
6 | import matplotlib.pyplot as plt |
---|
7 | |
---|
8 | def getdims(nc, *names): return [len(nc.dimensions[name]) for name in names] |
---|
9 | def getvars(nc, *names): return [nc.variables[name] for name in names] |
---|
10 | |
---|
11 | #--------------------------- MAIN ---------------------------- |
---|
12 | |
---|
13 | infile = 'diagflux.nc' |
---|
14 | nc = cdf.Dataset(infile, "r") |
---|
15 | print nc |
---|
16 | llm, nlat = getdims(nc, 'lev','lat_dom_out') |
---|
17 | Lv, 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 | |
---|
24 | lat,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 |
---|
25 | qflux,q = qflux[0,:,:], q[0,:,:] |
---|
26 | |
---|
27 | perim = 4e7*np.cos(lat*np.pi/180.) # geometric factor |
---|
28 | stream = mflux.cumsum(axis=0) |
---|
29 | for i in range(lat.size): |
---|
30 | stream[:,i]=stream[:,i]*perim[i] |
---|
31 | p=p.mean(axis=1) |
---|
32 | |
---|
33 | print qflux.shape, q.shape, stream.shape |
---|
34 | # cpT est en (J/m^2) |
---|
35 | # cpTflux est en (J/m^2)*(m/s) |
---|
36 | |
---|
37 | cpTflux = cpTflux - (cpT/mass)*mflux # flux "turbulents" |
---|
38 | qflux = qflux - (q/mass)*mflux # flux "turbulents" |
---|
39 | |
---|
40 | qflux,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 | |
---|
43 | print cpTflux.shape, p.shape |
---|
44 | |
---|
45 | cpTflux = cpTflux*perim |
---|
46 | qflux = qflux*perim |
---|
47 | # cpTflux est en W |
---|
48 | |
---|
49 | plt.figure() |
---|
50 | plt.plot(lat,cpTflux) |
---|
51 | plt.title('Meridional enthalpy flux (W)') |
---|
52 | plt.savefig('enthalpy_flux.png') |
---|
53 | plt.close() |
---|
54 | |
---|
55 | plt.figure() |
---|
56 | plt.plot(lat,Lv*qflux) |
---|
57 | plt.title('Meridional latent heat flux (W)') |
---|
58 | plt.savefig('latent_heat_flux.png') |
---|
59 | plt.close() |
---|
60 | |
---|
61 | plt.figure() |
---|
62 | plt.contourf(lat,p,stream,20) |
---|
63 | plt.ylim(1e5, 0) |
---|
64 | plt.title('Meridional stream function (kg/s)') |
---|
65 | plt.colorbar() |
---|
66 | plt.savefig('stream.png') |
---|
67 | plt.close() |
---|