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 | fi="diagfi2015_S.nc" |
---|
16 | d1="../restart_3/" |
---|
17 | |
---|
18 | f1=d1+fi |
---|
19 | |
---|
20 | var="temperature" #variable |
---|
21 | |
---|
22 | p1=[-148,16] |
---|
23 | |
---|
24 | nc1=Dataset(f1) |
---|
25 | lat=nc1.variables["lat"][:] |
---|
26 | lon=nc1.variables["lon"][:] |
---|
27 | alt=nc1.variables["altitude"][:] |
---|
28 | tim=nc1.variables["time_counter"][:] |
---|
29 | |
---|
30 | def findindextime(tini,lt0,lt1,p): |
---|
31 | lt180=(lt0+12)%24 # a t=0 et longitude=180 |
---|
32 | lt0p1=lt180*((p[0]+360)%360)/180 # local time a t=0 a la longitude p1 |
---|
33 | diff=lt1-lt0p1 # diff du local time a p1 a t=0 avec celui recherche |
---|
34 | indp1=tini+diff/24. # on adapte lindice pour tomber sur le bon moment |
---|
35 | # on cherche dans Time l'indice le plus proche : |
---|
36 | indt1=np.where(abs(tim[:]-indp1)==min(abs(tim[:]-indp1)))[0][0] |
---|
37 | print(('Point =',p,' Time=',tim[indt1],' diff = ',diff)) |
---|
38 | return indt1 |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | def getindex(lat,lon,mylat,mylon): |
---|
43 | indlat=np.where(abs(lat[:]-mylat)==min(abs(lat[:]-mylat)))[0][0] |
---|
44 | indlon=np.where(abs(lon[:]-mylon)==min(abs(lon[:]-mylon)))[0][0] |
---|
45 | print((lon[indlon],lat[indlat])) |
---|
46 | return indlat,indlon |
---|
47 | |
---|
48 | def getvar(filename,var): |
---|
49 | myvar = pp(file=filename,var=var,compute="nothing").getf() |
---|
50 | print(('shape myvar = ',shape(myvar))) |
---|
51 | return myvar |
---|
52 | |
---|
53 | |
---|
54 | tini=32 # choix du jour dans le diagfi |
---|
55 | lt0=0 # local time a t=0 et longitude=0 |
---|
56 | ltchoice0=0 # local time initial |
---|
57 | ltchoice1=25 # local time final |
---|
58 | |
---|
59 | indt0=findindextime(tini,lt0,ltchoice0,p1) |
---|
60 | indt1=findindextime(tini,lt0,ltchoice1,p1) |
---|
61 | |
---|
62 | print((indt0,indt1)) |
---|
63 | |
---|
64 | indlat,indlon=getindex(lat,lon,p1[1],p1[0]) |
---|
65 | |
---|
66 | mpl.figure(figsize=(18, 10)) |
---|
67 | |
---|
68 | myvar=getvar(f1,var)[indt0:indt1+1,:,indlat,indlon] |
---|
69 | |
---|
70 | tim=tim[indt0:indt1+1] |
---|
71 | print(("time is : ",tim)) |
---|
72 | |
---|
73 | font=26 |
---|
74 | |
---|
75 | axtim=(tim-tim[0])*24 |
---|
76 | print(("axtim=",axtim)) |
---|
77 | print(('on prend les premiers indice, shape (tmps, alt, var) =',shape(axtim), shape(alt), shape(myvar))) |
---|
78 | |
---|
79 | pal=get_cmap(name="Spectral_r") |
---|
80 | lev=np.linspace(34,54,19) |
---|
81 | xticks=[0,2,4,6,8,10,12,14,16,18,20,22,24] |
---|
82 | alt=alt/1000. |
---|
83 | |
---|
84 | |
---|
85 | CF=mpl.contourf(axtim,alt,np.transpose(myvar),lev,cmap=pal,extend='both') |
---|
86 | cbar=mpl.colorbar(CF,shrink=1, format="%1.0f") |
---|
87 | cbar.ax.set_title("Temp [K]",y=1.04,fontsize=font) |
---|
88 | for t in cbar.ax.get_yticklabels(): |
---|
89 | t.set_fontsize(font) |
---|
90 | |
---|
91 | vect=lev |
---|
92 | CS=mpl.contour(axtim,alt,np.transpose(myvar),vect,colors='k',linewidths=0.5) |
---|
93 | #inline=1 : values over the line |
---|
94 | #mpl.clabel(CS, inline=2, fontsize=10, fmt='%1.1e') |
---|
95 | lab=mpl.clabel(CS, inline=1, fontsize=15, fmt='%1.0f',inline_spacing=1) |
---|
96 | |
---|
97 | for l in lab: |
---|
98 | l.set_rotation(0) |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | #mpl.title('Latitude ='+str(tintstr[i]),fontsize=font) |
---|
104 | mpl.xlabel('Local Time (h)',labelpad=10,fontsize=font) |
---|
105 | mpl.ylabel('Altitude (km)',labelpad=10, fontsize=font) |
---|
106 | mpl.xticks(xticks,fontsize=font) |
---|
107 | #mpl.xticks(fontsize=font) |
---|
108 | #mpl.yticks(yticks,fontsize=font) |
---|
109 | mpl.yticks(fontsize=font) |
---|
110 | pylab.ylim([0,4]) |
---|
111 | pylab.xlim([0,24]) |
---|
112 | |
---|
113 | mpl.savefig('temploctime_3_'+str(p1[0])+'_'+str(p1[1])+'.eps',dpi=200) |
---|
114 | mpl.savefig('temploctime_3_'+str(p1[0])+'_'+str(p1[1])+'.png',dpi=200) |
---|
115 | #mpl.show() |
---|
116 | |
---|
117 | |
---|