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 | from matplotlib import ticker |
---|
10 | import matplotlib.colors as colors |
---|
11 | import datetime |
---|
12 | from mpl_toolkits.basemap import Basemap, shiftgrid |
---|
13 | |
---|
14 | ############################ |
---|
15 | filename1="diagfi2015_S.nc" |
---|
16 | var="temperature" #variable |
---|
17 | xarea="-169,-165" |
---|
18 | yarea="-19,-15" |
---|
19 | |
---|
20 | # local time de la longitude consideree a t=0 |
---|
21 | loct=12 |
---|
22 | sol0=30 |
---|
23 | t0=1./24*loct |
---|
24 | t1=t0+1 |
---|
25 | tint=[str(sol0+t0)+','+str(sol0+t1)] #Time must be as written in the input file |
---|
26 | print(tint) |
---|
27 | nc1=Dataset(filename1) |
---|
28 | |
---|
29 | lat=nc1.variables["lat"][:] |
---|
30 | lon=nc1.variables["lon"][:] |
---|
31 | alt=nc1.variables["altitude"][:] |
---|
32 | ############################ |
---|
33 | |
---|
34 | def getvar(filename,var,tint,xarea,yarea): |
---|
35 | myvar = pp(file=filename,var=var,t=tint,x=xarea,y=yarea,compute="nothing").getf() |
---|
36 | print(('shape myvar = ',shape(myvar))) |
---|
37 | return myvar |
---|
38 | |
---|
39 | |
---|
40 | mpl.figure(figsize=(18, 10)) |
---|
41 | |
---|
42 | |
---|
43 | myvar=getvar(filename1,var,tint,xarea,yarea)[:,:,0,0] |
---|
44 | font=23 |
---|
45 | tim=np.linspace(0,24,9) |
---|
46 | print(("tim=",tim)) |
---|
47 | print(('on prend les premiers indice, shape (tmps, alt, var) =',shape(tim), shape(alt), shape(myvar))) |
---|
48 | #pal=get_cmap(name="RdYlBu_r") |
---|
49 | pal=get_cmap(name="Spectral_r") |
---|
50 | lev=np.linspace(40,50,10) |
---|
51 | xticks=[0,2,4,6,8,10,12,14,16,18,20,22,24] |
---|
52 | print(('hello:',np.linspace(0,24,13))) |
---|
53 | #yticks=np.linspace(0,240,9) |
---|
54 | alt=alt/1000. |
---|
55 | |
---|
56 | |
---|
57 | CF=mpl.contourf(tim,alt,np.transpose(myvar),lev,cmap=pal,extend='both') |
---|
58 | cbar=mpl.colorbar(CF,shrink=1, format="%1.0f") |
---|
59 | cbar.ax.set_title("Temp [K]",y=1.04,fontsize=font) |
---|
60 | for t in cbar.ax.get_yticklabels(): |
---|
61 | t.set_fontsize(font) |
---|
62 | |
---|
63 | |
---|
64 | vect=lev |
---|
65 | CS=mpl.contour(tim,alt,np.transpose(myvar),vect,colors='k',linewidths=0.5) |
---|
66 | #inline=1 : values over the line |
---|
67 | #mpl.clabel(CS, inline=2, fontsize=10, fmt='%1.1e') |
---|
68 | mpl.clabel(CS, inline=1, fontsize=15, fmt='%1.0f',inline_spacing=1) |
---|
69 | |
---|
70 | |
---|
71 | #mpl.title('Latitude ='+str(tintstr[i]),fontsize=font) |
---|
72 | mpl.xlabel('Local Time (h)',labelpad=10,fontsize=font) |
---|
73 | mpl.ylabel('Altitude (km)',labelpad=10, fontsize=font) |
---|
74 | mpl.xticks(xticks,fontsize=font) |
---|
75 | #mpl.xticks(fontsize=font) |
---|
76 | #mpl.yticks(yticks,fontsize=font) |
---|
77 | mpl.yticks(fontsize=font) |
---|
78 | pylab.ylim([0,4]) |
---|
79 | |
---|
80 | mpl.savefig('temploctime.eps',dpi=200) |
---|
81 | mpl.savefig('temploctime.png',dpi=200) |
---|
82 | mpl.show() |
---|
83 | |
---|
84 | |
---|
85 | |
---|