source: trunk/LMDZ.PLUTO/util/script_figures/ch4cloudsection.py @ 3831

Last change on this file since 3831 was 3823, checked in by afalco, 5 days ago

Pluto: added some python scripts for visualization.
AF

  • Property svn:executable set to *
File size: 3.0 KB
Line 
1#! /usr/bin/env python
2from ppclass import pp
3from    netCDF4               import    Dataset
4from    numpy                 import    *
5import  numpy                 as        np
6import  matplotlib.pyplot     as        mpl
7from matplotlib.cm import get_cmap
8import pylab
9import matplotlib.colors as mcolors
10
11############################
12filename1="diagfi2015_S.nc"
13var="ch4_ice" #variable
14
15xarea1="-180,-179"
16xarea2="0,1"
17
18tint1=["30.625","30.875","31.125","30.375"] #Time must be as written in the input file
19tintstr1=["03:00","09:00","15:00","21:00"] #Time must be as written in the input file
20
21tint2=["30.125","30.375","30.625","30.875"] #Time must be as written in the input file
22tintstr2=["03:00","09:00","15:00","21:00"] #Time must be as written in the input file
23nc1=Dataset(filename1)
24
25lat=nc1.variables["lat"][:]
26lon=nc1.variables["lon"][:]
27alt=nc1.variables["altitude"][:]
28print(('alt=',alt))
29############################
30
31def 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
36def 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
75nbfig=8
76nbrow=4
77nbcol=2
78
79mpl.figure(figsize=(20, 10))
80font=15
81
82pal=get_cmap(name="PuBu")
83
84xticks=[-90,-60,-30,0,30,60,90]
85#yticks=np.linspace(0,240,9)
86
87mymin=0.02
88mymax=100
89
90
91left  = None  # the left side of the subplots of the figure
92right = None   # the right side of the subplots of the figure
93bottom = None  # the bottom of the subplots of the figure
94top = None     # the top of the subplots of the figure
95wspace = None  # the amount of width reserved for blank space between subplots
96hspace = 0.7  # the amount of height reserved for white space between subplots
97mpl.subplots_adjust(left, bottom, right, top, wspace, hspace)
98
99for i in range(nbfig):
100    getfigvar(nbfig,nbrow,nbcol,i)
101
102
103mpl.savefig('sectionch4cloud.eps',dpi=200)
104mpl.savefig('sectionch4cloud.png',dpi=200)
105
106mpl.show()
107
108
109
110
Note: See TracBrowser for help on using the repository browser.