source: trunk/LMDZ.PLUTO/util/script_figures/temp_time_zoom_3.py @ 3823

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

Pluto: added some python scripts for visualization.
AF

  • Property svn:executable set to *
File size: 3.2 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
9from matplotlib import ticker
10import matplotlib.colors as colors
11import datetime
12from mpl_toolkits.basemap import Basemap, shiftgrid
13
14############################
15fi="diagfi2015_S.nc"
16d1="../restart_3/"
17
18f1=d1+fi
19
20var="temperature" #variable
21
22p1=[-148,16]
23
24nc1=Dataset(f1)
25lat=nc1.variables["lat"][:]
26lon=nc1.variables["lon"][:]
27alt=nc1.variables["altitude"][:]
28tim=nc1.variables["time_counter"][:]
29
30def 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
42def 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
48def getvar(filename,var):
49    myvar = pp(file=filename,var=var,compute="nothing").getf()
50    print(('shape myvar = ',shape(myvar)))
51    return myvar
52
53
54tini=32  # choix du jour dans le diagfi
55lt0=0   # local time a t=0 et longitude=0
56ltchoice0=0 # local time initial
57ltchoice1=25 # local time final
58
59indt0=findindextime(tini,lt0,ltchoice0,p1)
60indt1=findindextime(tini,lt0,ltchoice1,p1)
61
62print((indt0,indt1))
63
64indlat,indlon=getindex(lat,lon,p1[1],p1[0])
65
66mpl.figure(figsize=(18, 10))
67
68myvar=getvar(f1,var)[indt0:indt1+1,:,indlat,indlon]
69
70tim=tim[indt0:indt1+1]
71print(("time is : ",tim))
72
73font=26
74
75axtim=(tim-tim[0])*24
76print(("axtim=",axtim))
77print(('on prend les premiers indice, shape (tmps, alt, var) =',shape(axtim), shape(alt), shape(myvar)))
78
79pal=get_cmap(name="Spectral_r")
80lev=np.linspace(34,54,19)
81xticks=[0,2,4,6,8,10,12,14,16,18,20,22,24] 
82alt=alt/1000.
83
84
85CF=mpl.contourf(axtim,alt,np.transpose(myvar),lev,cmap=pal,extend='both')
86cbar=mpl.colorbar(CF,shrink=1, format="%1.0f")
87cbar.ax.set_title("Temp [K]",y=1.04,fontsize=font)
88for t in cbar.ax.get_yticklabels():
89      t.set_fontsize(font)
90
91vect=lev
92CS=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')
95lab=mpl.clabel(CS, inline=1, fontsize=15, fmt='%1.0f',inline_spacing=1)
96
97for l in lab:
98    l.set_rotation(0)
99
100
101
102
103#mpl.title('Latitude ='+str(tintstr[i]),fontsize=font)
104mpl.xlabel('Local Time (h)',labelpad=10,fontsize=font)
105mpl.ylabel('Altitude (km)',labelpad=10, fontsize=font)
106mpl.xticks(xticks,fontsize=font)
107#mpl.xticks(fontsize=font)
108#mpl.yticks(yticks,fontsize=font)
109mpl.yticks(fontsize=font)
110pylab.ylim([0,4])
111pylab.xlim([0,24])
112
113mpl.savefig('temploctime_3_'+str(p1[0])+'_'+str(p1[1])+'.eps',dpi=200)
114mpl.savefig('temploctime_3_'+str(p1[0])+'_'+str(p1[1])+'.png',dpi=200)
115#mpl.show()
116
117
Note: See TracBrowser for help on using the repository browser.