[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 | zefile="diagfi2015_A.nc" |
---|
| 16 | d1="restart_ref/" |
---|
| 17 | |
---|
| 18 | f1=d1+zefile |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | var="temperature" #variable |
---|
| 22 | |
---|
| 23 | nc1=Dataset(f1) |
---|
| 24 | lat=nc1.variables["lat"][:] |
---|
| 25 | lon=nc1.variables["lon"][:] |
---|
| 26 | alt=nc1.variables["altitude"][:] |
---|
| 27 | tim=nc1.variables["time_counter"][:] |
---|
| 28 | |
---|
| 29 | print(('Time = ',tim)) |
---|
| 30 | print(('Long = ',lon)) |
---|
| 31 | print(('Lat = ',lat)) |
---|
| 32 | |
---|
| 33 | ############################ |
---|
| 34 | |
---|
| 35 | def findindextime(tini,lt0,lt1,p): |
---|
| 36 | lt180=(lt0+12)%24 # a t=0 et longitude=180 |
---|
| 37 | lt0p1=lt180*((p[0]+360)%360)/180 # local time a t=0 a la longitude p1 |
---|
| 38 | diff=lt1-lt0p1 # diff du local time a p1 a t=0 avec celui recherche |
---|
| 39 | indp1=tini+diff/24. # on adapte lindice pour tomber sur le bon moment |
---|
| 40 | |
---|
| 41 | # on cherche dans Time l'indice le plus proche : |
---|
| 42 | indt1=np.where(abs(tim[:]-indp1)==min(abs(tim[:]-indp1)))[0][0] |
---|
| 43 | print(('Point =',p,' Time=',tim[indt1])) |
---|
| 44 | return indt1 |
---|
| 45 | |
---|
| 46 | def getvar(filename,var): |
---|
| 47 | myvar = pp(file=filename,var=var,compute="nothing").getf() |
---|
| 48 | return myvar |
---|
| 49 | |
---|
| 50 | def getindex(lat,lon,mylat,mylon): |
---|
| 51 | indlat=np.where(abs(lat[:]-mylat)==min(abs(lat[:]-mylat)))[0][0] |
---|
| 52 | indlon=np.where(abs(lon[:]-mylon)==min(abs(lon[:]-mylon)))[0][0] |
---|
| 53 | print((lon[indlon],lat[indlat])) |
---|
| 54 | return indlat,indlon |
---|
| 55 | |
---|
| 56 | def main(tini,lt0,ltchoice,p): |
---|
| 57 | indt=findindextime(tini,lt0,ltchoice,p) |
---|
| 58 | indlat,indlon=getindex(lat,lon,p[1],p[0]) |
---|
| 59 | myvar=getvar(f1,var)[indt,:,indlat,indlon] |
---|
| 60 | return myvar |
---|
| 61 | ############################ |
---|
| 62 | |
---|
| 63 | #points: entre -180 et 180 |
---|
| 64 | p1=[-168.75, -18.75] # Entry |
---|
| 65 | p2=[-168.75, -30] # sud est SP |
---|
| 66 | p2=[-164., -18.75] # Entry un peu plus sur bord du bassin |
---|
| 67 | p3=[135, 45] # Burney crater |
---|
| 68 | p4=[180, 45] # SP |
---|
| 69 | p5=[-124, 2] # BTD au fond |
---|
| 70 | p6=[-148,16] # TR |
---|
| 71 | p7=[-5.625,86.25] # Lowell |
---|
| 72 | p8=[-5.625,-86.25] # south pole |
---|
| 73 | p7=[129.3,45] # pente Burney |
---|
| 74 | p8=[166,-18] # low SP west |
---|
| 75 | p9=[15,0] # Exit |
---|
| 76 | |
---|
| 77 | tini=32 # choix du jour dans le diagfi |
---|
| 78 | lt0=0 # local time a t=0 et longitude=0 |
---|
| 79 | ltchoice=16.5 # local time choisi |
---|
| 80 | ltchoice2=4 # local time choisi |
---|
| 81 | |
---|
| 82 | myvar1=main(tini,lt0,ltchoice,p1) |
---|
| 83 | #myvar2=main(tini,lt0,ltchoice,p2) |
---|
| 84 | #myvar3=main(tini,lt0,ltchoice,p3) |
---|
| 85 | myvar4=main(tini,lt0,ltchoice,p4) |
---|
| 86 | #myvar5=main(tini,lt0,ltchoice,p5) |
---|
| 87 | #myvar6=main(tini,lt0,ltchoice,p6) |
---|
| 88 | #myvar7=main(tini,lt0,ltchoice,p7) |
---|
| 89 | #myvar8=main(tini,lt0,ltchoice,p8) |
---|
| 90 | #myvar9=main(tini,lt0,ltchoice2,p9) |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | mpl.figure(figsize=(10, 10)) |
---|
| 94 | |
---|
| 95 | font=23 |
---|
| 96 | |
---|
| 97 | alt=alt/1000. |
---|
| 98 | |
---|
| 99 | mpl.plot(myvar1,alt,'r',label='Entry') |
---|
| 100 | #mpl.plot(myvar2,alt,'g',label='Entry-like on edge') |
---|
| 101 | #mpl.plot(myvar3,alt,'k',label='Burney crater') |
---|
| 102 | mpl.plot(myvar4,alt,'k',label='Sputnik Planitia') |
---|
| 103 | #mpl.plot(myvar5,alt,'c',label='BTD') |
---|
| 104 | #mpl.plot(myvar6,alt,'b',label='TR') |
---|
| 105 | #mpl.plot(myvar7,alt,'y',label='Lowell') |
---|
| 106 | #mpl.plot(myvar8,alt,'orange',label='southpole') |
---|
| 107 | #mpl.plot(myvar7,alt,'y',label='Slope Burney') |
---|
| 108 | #mpl.plot(myvar8,alt,'orange',label='South-West SP') |
---|
| 109 | #mpl.plot(myvar9,alt,'b',label='Exit') |
---|
| 110 | |
---|
| 111 | mpl.legend(prop={'size':20},loc='upper left') |
---|
| 112 | #mpl.title('Latitude ='+str(tintstr[i]),fontsize=font) |
---|
| 113 | mpl.ylabel('Altitude (km)',labelpad=10,fontsize=font) |
---|
| 114 | mpl.xlabel('Temperature (K)',labelpad=10, fontsize=font) |
---|
| 115 | #mpl.xticks(xticks,fontsize=font) |
---|
| 116 | mpl.xticks(fontsize=font) |
---|
| 117 | #mpl.yticks(yticks,fontsize=font) |
---|
| 118 | mpl.yticks(fontsize=font) |
---|
| 119 | mpl.grid() |
---|
| 120 | #mpl.legend(["Ref","Alt"]) |
---|
| 121 | |
---|
| 122 | pylab.ylim([-3,2]) |
---|
| 123 | pylab.xlim([35,50]) |
---|
| 124 | |
---|
| 125 | #mpl.savefig('proftempNH_'+str(ltchoice)+'h.eps',dpi=200) |
---|
| 126 | #mpl.savefig('proftempNH_'+str(ltchoice)+'h.png',dpi=200) |
---|
| 127 | mpl.show() |
---|
| 128 | |
---|
| 129 | |
---|