[3823] | 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="restart_ref/diagfi2015_A.nc" |
---|
| 16 | var="temperature" #variable |
---|
| 17 | |
---|
| 18 | nc1=Dataset(filename1) |
---|
| 19 | lat=nc1.variables["lat"][:] |
---|
| 20 | lon=nc1.variables["lon"][:] |
---|
| 21 | alt=nc1.variables["altitude"][:] |
---|
| 22 | tim=nc1.variables["time_counter"][:] |
---|
| 23 | |
---|
| 24 | print(('Time = ',tim)) |
---|
| 25 | print(('Long = ',lon)) |
---|
| 26 | print(('Lat = ',lat)) |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | ############################ |
---|
| 30 | |
---|
| 31 | def 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 | |
---|
| 42 | def getvar(filename,var): |
---|
| 43 | myvar = pp(file=filename,var=var,compute="nothing").getf() |
---|
| 44 | return myvar |
---|
| 45 | |
---|
| 46 | def 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 | |
---|
| 52 | def 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 |
---|
| 60 | p1=[180, 25] # Entry |
---|
| 61 | p2=[180, 20] # low SP |
---|
| 62 | p3=[180, 15] # Burney |
---|
| 63 | p4=[180, 10] # SP |
---|
| 64 | p5=[180, 5] # BTD |
---|
| 65 | p6=[180, 0] # TR |
---|
| 66 | p7=[180, -5] # Lowell |
---|
| 67 | p8=[180, -10] # south pole |
---|
| 68 | |
---|
| 69 | tini=32 # choix du jour dans le diagfi |
---|
| 70 | lt0=0 # a t=0 et longitude=0 |
---|
| 71 | ltchoice=12 # local time choisi |
---|
| 72 | |
---|
| 73 | myvar1=main(tini,lt0,ltchoice,p1) |
---|
| 74 | #myvar2=main(tini,lt0,ltchoice,p2) |
---|
| 75 | myvar3=main(tini,lt0,ltchoice,p3) |
---|
| 76 | #myvar4=main(tini,lt0,ltchoice,p4) |
---|
| 77 | myvar5=main(tini,lt0,ltchoice,p5) |
---|
| 78 | myvar6=main(tini,lt0,ltchoice,p6) |
---|
| 79 | myvar7=main(tini,lt0,ltchoice,p7) |
---|
| 80 | #myvar8=main(tini,lt0,ltchoice,p8) |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | mpl.figure(figsize=(10, 10)) |
---|
| 84 | |
---|
| 85 | font=23 |
---|
| 86 | |
---|
| 87 | #xticks=[-90,-60,-30,0,30,60,90] |
---|
| 88 | #yticks=np.linspace(0,240,9) |
---|
| 89 | alt=alt/1000. |
---|
| 90 | |
---|
| 91 | mpl.plot(myvar1,alt,'r',label=r'lat=25 $^\circ$') |
---|
| 92 | mpl.plot(myvar3,alt,'k',label=r'lat=15 $^\circ$') |
---|
| 93 | mpl.plot(myvar5,alt,'c',label=r'lat=5 $^\circ$') |
---|
| 94 | mpl.plot(myvar6,alt,'b',label=r'lat= 0 $^\circ$') |
---|
| 95 | mpl.plot(myvar7,alt,'y',label=r'lat=-5 $^\circ$') |
---|
| 96 | |
---|
| 97 | mpl.legend(prop={'size':20},loc='upper left') |
---|
| 98 | #mpl.title('Latitude ='+str(tintstr[i]),fontsize=font) |
---|
| 99 | mpl.ylabel('Altitude (km)',labelpad=10,fontsize=font) |
---|
| 100 | mpl.xlabel('Temperature (K)',labelpad=10, fontsize=font) |
---|
| 101 | #mpl.xticks(xticks,fontsize=font) |
---|
| 102 | mpl.xticks(fontsize=font) |
---|
| 103 | #mpl.yticks(yticks,fontsize=font) |
---|
| 104 | mpl.yticks(fontsize=font) |
---|
| 105 | mpl.grid() |
---|
| 106 | #mpl.legend(["Ref","Alt"]) |
---|
| 107 | |
---|
| 108 | pylab.ylim([-3,0]) |
---|
| 109 | pylab.xlim([35,45]) |
---|
| 110 | |
---|
| 111 | mpl.savefig('proftempNH_SP180_'+str(ltchoice)+'h.eps',dpi=200) |
---|
| 112 | mpl.savefig('proftempNH_SP180_'+str(ltchoice)+'h.png',dpi=200) |
---|
| 113 | mpl.show() |
---|
| 114 | |
---|
| 115 | |
---|