1 | #! /usr/bin/env python |
---|
2 | from ppclass import pp |
---|
3 | from netCDF4 import Dataset |
---|
4 | from numpy import * |
---|
5 | import numpy as np |
---|
6 | import matplotlib.pyplot as mpl |
---|
7 | from matplotlib.cm import get_cmap |
---|
8 | import pylab |
---|
9 | import matplotlib.colors as mcolors |
---|
10 | |
---|
11 | ############################ |
---|
12 | filename1="diagfi2015_S.nc" |
---|
13 | var="ch4_ice" #variable |
---|
14 | |
---|
15 | xarea1="-180,-179" |
---|
16 | xarea2="0,1" |
---|
17 | |
---|
18 | tint1=["30.625","30.875","31.125","30.375"] #Time must be as written in the input file |
---|
19 | tintstr1=["03:00","09:00","15:00","21:00"] #Time must be as written in the input file |
---|
20 | |
---|
21 | tint2=["30.125","30.375","30.625","30.875"] #Time must be as written in the input file |
---|
22 | tintstr2=["03:00","09:00","15:00","21:00"] #Time must be as written in the input file |
---|
23 | nc1=Dataset(filename1) |
---|
24 | |
---|
25 | lat=nc1.variables["lat"][:] |
---|
26 | lon=nc1.variables["lon"][:] |
---|
27 | alt=nc1.variables["altitude"][:] |
---|
28 | print(('alt=',alt)) |
---|
29 | ############################ |
---|
30 | |
---|
31 | def getvar(filename,var,tint,xarea): |
---|
32 | myvar = pp(file=filename,var=var,t=tint,x=xarea,compute="nothing").getf() |
---|
33 | print((shape(myvar))) |
---|
34 | return myvar |
---|
35 | |
---|
36 | def getfigvar(nbfig,nbrow,nbcol,i): |
---|
37 | mpl.subplot(nbrow,nbcol,i+1) |
---|
38 | if (i%2==0): |
---|
39 | tint=tint1 |
---|
40 | tintstr=tintstr1 |
---|
41 | xarea=xarea1 |
---|
42 | mytitle="Lon: 180E, LT= " |
---|
43 | else: |
---|
44 | tint=tint2 |
---|
45 | tintstr=tintstr2 |
---|
46 | xarea=xarea2 |
---|
47 | mytitle="Lon: 0E, LT= " |
---|
48 | |
---|
49 | print(("time numero :",int(i/2),' du fichier tint avec x=',xarea)) |
---|
50 | myvar=getvar(filename1,var,tint[int(i/2)],xarea)[0,:,:,0] |
---|
51 | myvar=myvar*1.e6 |
---|
52 | |
---|
53 | # log |
---|
54 | norm=mcolors.LogNorm() |
---|
55 | lvls=np.logspace(np.log10(mymin),np.log10(mymax),8) |
---|
56 | #titi=[1.e-14,1.e-13,1.e-12,1.e-11] |
---|
57 | CF=mpl.contourf(lat, alt, myvar,levels=lvls,norm=norm,cmap=pal) |
---|
58 | cbar=mpl.colorbar(CF, shrink=1, format="%.2f",extend='both') |
---|
59 | cbar.ax.set_title("1E-6 kg/m2",y=1.04,fontsize=font) |
---|
60 | |
---|
61 | for t in cbar.ax.get_yticklabels(): |
---|
62 | t.set_fontsize(font) |
---|
63 | |
---|
64 | mpl.title(mytitle+str(tintstr[int(i/2)]),fontsize=font) |
---|
65 | mpl.ylabel('Altitude (m)',labelpad=10,fontsize=font) |
---|
66 | mpl.xlabel('Latitude (deg)',labelpad=10, fontsize=font) |
---|
67 | mpl.xticks(xticks,fontsize=font) |
---|
68 | #mpl.xticks(fontsize=font) |
---|
69 | #mpl.yticks(yticks,fontsize=font) |
---|
70 | mpl.yticks(fontsize=font) |
---|
71 | pylab.ylim([0,3000]) |
---|
72 | |
---|
73 | #################" |
---|
74 | |
---|
75 | nbfig=8 |
---|
76 | nbrow=4 |
---|
77 | nbcol=2 |
---|
78 | |
---|
79 | mpl.figure(figsize=(20, 10)) |
---|
80 | font=15 |
---|
81 | |
---|
82 | pal=get_cmap(name="PuBu") |
---|
83 | |
---|
84 | xticks=[-90,-60,-30,0,30,60,90] |
---|
85 | #yticks=np.linspace(0,240,9) |
---|
86 | |
---|
87 | mymin=0.02 |
---|
88 | mymax=100 |
---|
89 | |
---|
90 | |
---|
91 | left = None # the left side of the subplots of the figure |
---|
92 | right = None # the right side of the subplots of the figure |
---|
93 | bottom = None # the bottom of the subplots of the figure |
---|
94 | top = None # the top of the subplots of the figure |
---|
95 | wspace = None # the amount of width reserved for blank space between subplots |
---|
96 | hspace = 0.7 # the amount of height reserved for white space between subplots |
---|
97 | mpl.subplots_adjust(left, bottom, right, top, wspace, hspace) |
---|
98 | |
---|
99 | for i in range(nbfig): |
---|
100 | getfigvar(nbfig,nbrow,nbcol,i) |
---|
101 | |
---|
102 | |
---|
103 | mpl.savefig('sectionch4cloud.eps',dpi=200) |
---|
104 | mpl.savefig('sectionch4cloud.png',dpi=200) |
---|
105 | |
---|
106 | mpl.show() |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | |
---|