1 | #! /usr/bin/env python |
---|
2 | from netCDF4 import Dataset |
---|
3 | from numpy import * |
---|
4 | import numpy as np |
---|
5 | import matplotlib.pyplot as mpl |
---|
6 | from matplotlib.cm import get_cmap |
---|
7 | import pylab |
---|
8 | from matplotlib import ticker |
---|
9 | import matplotlib.colors as colors |
---|
10 | import datetime |
---|
11 | from mpl_toolkits.basemap import Basemap, shiftgrid |
---|
12 | from FV3_utils import * |
---|
13 | |
---|
14 | ############################ |
---|
15 | step_begin = 2000 |
---|
16 | step_end = 2015 |
---|
17 | |
---|
18 | var="temperature" #variable |
---|
19 | # tint=["30,37"] #Time must be as written in the input file |
---|
20 | tint=None #Time must be as written in the input file |
---|
21 | xarea="0,1" |
---|
22 | yarea="0,1" |
---|
23 | |
---|
24 | prefix="Xhistins" |
---|
25 | suffix="_A.nc" |
---|
26 | filename=f"../../{prefix}{step_begin}{suffix}" |
---|
27 | nc1=Dataset(filename) |
---|
28 | |
---|
29 | lat=getvar(nc1,"latitude") |
---|
30 | lon=getvar(nc1,"longitude") |
---|
31 | alt=getvar(nc1,"altitude") |
---|
32 | # tim=getvar(nc1,"Time") |
---|
33 | |
---|
34 | myvar=getvar(nc1,var,tint,xarea,yarea) |
---|
35 | myvar=myvar[:,:,0,0] |
---|
36 | print((shape(myvar))) |
---|
37 | |
---|
38 | # nb of day |
---|
39 | nbday=3 |
---|
40 | |
---|
41 | # nb of time: |
---|
42 | nbtime=size(myvar[:,0]) |
---|
43 | print(nbtime) |
---|
44 | |
---|
45 | # nb time step /day |
---|
46 | nbstep=50 |
---|
47 | |
---|
48 | # nb alt |
---|
49 | nbalt=size(alt) |
---|
50 | print(nbalt) |
---|
51 | |
---|
52 | #meanvar=np.zeros((nbday,nbalt),dtype='f') |
---|
53 | meanvar=np.zeros((nbtime-2*nbstep,nbalt),dtype='f') |
---|
54 | anovar=np.zeros((nbtime-2*nbstep,nbalt),dtype='f') |
---|
55 | |
---|
56 | # pour chaque jour : calcul moyenne diurne |
---|
57 | for i in range(nbtime-2*nbstep): |
---|
58 | #i=i+nbstep/2 |
---|
59 | meanvar[i,:]=np.mean(myvar[nbstep//2+i:nbstep+nbstep//2+i,:],axis=0) |
---|
60 | #for i in range(nbday): |
---|
61 | # meanvar[i,:]=np.mean(myvar[0:8,:],axis=0) |
---|
62 | |
---|
63 | # pour chaque time : calcul anomaly le dernier time est pour autre jour |
---|
64 | for i in range(nbtime-2*nbstep): |
---|
65 | #index=int(i/nbstep) |
---|
66 | anovar[i,:]=myvar[nbstep+i,:]-meanvar[i,:] |
---|
67 | |
---|
68 | print((meanvar[:,:])) |
---|
69 | print((myvar[0,:])) |
---|
70 | # print((myvar[8,:])) |
---|
71 | |
---|
72 | |
---|
73 | mpl.figure(figsize=(20, 10)) |
---|
74 | |
---|
75 | font=26 |
---|
76 | |
---|
77 | #pal=get_cmap(name="RdYlBu_r") |
---|
78 | # pal=get_cmap(name="Spectral_r") |
---|
79 | lev=np.linspace(-0.1,0.1,10) |
---|
80 | |
---|
81 | #xticks=[-90,-60,-30,0,30,60,90] |
---|
82 | #yticks=np.linspace(0,240,9) |
---|
83 | tim=np.arange(nbtime-2*nbstep)/floor(nbstep) |
---|
84 | #tim=np.arange(nbtime)/nbstep |
---|
85 | |
---|
86 | print((shape(tim), shape(alt),shape(anovar))) |
---|
87 | |
---|
88 | CF=mpl.contourf(tim,alt,np.transpose(anovar),lev,cmap="coolwarm",extend='both') |
---|
89 | cbar=mpl.colorbar(CF,shrink=1, format="%1.2f") |
---|
90 | cbar.ax.set_title("[K]",y=1.04,fontsize=font) |
---|
91 | for t in cbar.ax.get_yticklabels(): |
---|
92 | t.set_fontsize(font) |
---|
93 | |
---|
94 | #vect=lev |
---|
95 | #CS=mpl.contour(lat,alt,myvar,vect,colors='k',linewidths=0.5) |
---|
96 | #### inline=1 : values over the line |
---|
97 | #mpl.clabel(CS, inline=1, fontsize=20, fmt='%1.0f',inline_spacing=1) |
---|
98 | |
---|
99 | #mpl.title('Latitude ='+str(tintstr[i]),fontsize=font) |
---|
100 | mpl.ylabel('Altitude (km)',labelpad=10,fontsize=font) |
---|
101 | mpl.xlabel('Time (Pluto days)',labelpad=10, fontsize=font) |
---|
102 | #mpl.xticks(xticks,fontsize=font) |
---|
103 | mpl.xticks(fontsize=font) |
---|
104 | #mpl.yticks(yticks,fontsize=font) |
---|
105 | mpl.yticks(fontsize=font) |
---|
106 | pylab.ylim([0,150000]) |
---|
107 | # pylab.ylim([0,np.max(alt)]) |
---|
108 | |
---|
109 | mpl.savefig('tempanom.eps',dpi=200) |
---|
110 | mpl.savefig('tempanom.png',dpi=200) |
---|
111 | mpl.show() |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | |
---|