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

Last change on this file since 3823 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.3 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############################
15filename1="restart_ref/diagfi2015_A.nc"
16var="temperature" #variable
17
18nc1=Dataset(filename1)
19lat=nc1.variables["lat"][:]
20lon=nc1.variables["lon"][:]
21alt=nc1.variables["altitude"][:]
22tim=nc1.variables["time_counter"][:]
23
24print(('Time = ',tim))
25print(('Long = ',lon))
26print(('Lat = ',lat))
27
28
29############################
30
31def findindextime(tini,lt0,lt1,p):
32    lt180=(lt0+12)%24   # a t=0 et longitude=180
33    lt0p1=lt180*((p[0]+360)%360)/180   # local time a t=0 a la longitude p1
34    diff=lt1-lt0p1                 # diff du local time a p1 a t=0 avec celui recherche
35    indp1=tini+diff/24.                 # on adapte lindice pour tomber sur le bon moment
36
37    # on cherche dans Time l'indice le plus proche :
38    indt1=np.where(abs(tim[:]-indp1)==min(abs(tim[:]-indp1)))[0][0]
39    print(('Point =',p,' Time=',tim[indt1]))
40    return indt1
41 
42def getvar(filename,var):
43    myvar = pp(file=filename,var=var,compute="nothing").getf()
44    return myvar
45
46def getindex(lat,lon,mylat,mylon):
47    indlat=np.where(abs(lat[:]-mylat)==min(abs(lat[:]-mylat)))[0][0]
48    indlon=np.where(abs(lon[:]-mylon)==min(abs(lon[:]-mylon)))[0][0]
49    print((lon[indlon],lat[indlat]))
50    return indlat,indlon
51
52def main(tini,lt0,ltchoice,p):
53    indt=findindextime(tini,lt0,ltchoice,p)
54    indlat,indlon=getindex(lat,lon,p[1],p[0])
55    myvar=getvar(filename1,var)[indt,:,indlat,indlon]
56    return myvar
57############################
58
59#points: entre -180 et 180
60p1=[180, 25] # Entry
61p2=[180, 20]    # low SP
62p3=[180, 15]    # Burney
63p4=[180, 10]    # SP
64p5=[180, 5]    # BTD
65p6=[180, 0]    # TR
66p7=[180, -5]    # Lowell
67p8=[180, -10]    # south pole
68
69tini=32 # choix du jour dans le diagfi
70lt0=0   # a t=0 et longitude=0
71ltchoice=12   # local time choisi
72
73myvar1=main(tini,lt0,ltchoice,p1)
74#myvar2=main(tini,lt0,ltchoice,p2)
75myvar3=main(tini,lt0,ltchoice,p3)
76#myvar4=main(tini,lt0,ltchoice,p4)
77myvar5=main(tini,lt0,ltchoice,p5)
78myvar6=main(tini,lt0,ltchoice,p6)
79myvar7=main(tini,lt0,ltchoice,p7)
80#myvar8=main(tini,lt0,ltchoice,p8)
81
82
83mpl.figure(figsize=(10, 10))
84
85font=23
86
87#xticks=[-90,-60,-30,0,30,60,90]
88#yticks=np.linspace(0,240,9)
89alt=alt/1000.
90
91mpl.plot(myvar1,alt,'r',label=r'lat=25 $^\circ$')
92mpl.plot(myvar3,alt,'k',label=r'lat=15 $^\circ$')
93mpl.plot(myvar5,alt,'c',label=r'lat=5 $^\circ$')
94mpl.plot(myvar6,alt,'b',label=r'lat= 0 $^\circ$')
95mpl.plot(myvar7,alt,'y',label=r'lat=-5 $^\circ$')
96
97mpl.legend(prop={'size':20},loc='upper left')
98#mpl.title('Latitude ='+str(tintstr[i]),fontsize=font)
99mpl.ylabel('Altitude (km)',labelpad=10,fontsize=font)
100mpl.xlabel('Temperature (K)',labelpad=10, fontsize=font)
101#mpl.xticks(xticks,fontsize=font)
102mpl.xticks(fontsize=font)
103#mpl.yticks(yticks,fontsize=font)
104mpl.yticks(fontsize=font)
105mpl.grid()
106#mpl.legend(["Ref","Alt"])
107
108pylab.ylim([-3,0])
109pylab.xlim([35,45])
110
111mpl.savefig('proftempNH_SP180_'+str(ltchoice)+'h.eps',dpi=200)
112mpl.savefig('proftempNH_SP180_'+str(ltchoice)+'h.png',dpi=200)
113mpl.show()
114
115
Note: See TracBrowser for help on using the repository browser.