[3823] | 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 | # folder="../" |
---|
| 16 | filename1=name+"_A.nc" |
---|
| 17 | filename2=name+".nc" |
---|
| 18 | #filename3="../simu_pole/diagfi2015_S.nc" |
---|
| 19 | var="temperature" #variable |
---|
| 20 | tint=[30,35] #Time must be as written in the input file |
---|
| 21 | print("Reading ", filename1, filename2) |
---|
| 22 | |
---|
| 23 | nc1=Dataset(filename1) |
---|
| 24 | nc2=Dataset(filename2) |
---|
| 25 | #nc3=Dataset(filename3) |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | lat=getvar(nc1,"latitude") |
---|
| 29 | lon=getvar(nc1,"longitude") |
---|
| 30 | alt=getvar(nc1,"altitude") |
---|
| 31 | tim=getvar(nc1,"Time") |
---|
| 32 | #alt2=nc3.variables["altitude"][:] |
---|
| 33 | ############################ |
---|
| 34 | |
---|
| 35 | def zetotarea(dat): |
---|
| 36 | |
---|
| 37 | totarea=0. |
---|
| 38 | for i in range(size(dat[:,0])): |
---|
| 39 | for j in range(size(dat[0,:])): |
---|
| 40 | totarea=totarea+dat[i,j] |
---|
| 41 | return totarea |
---|
| 42 | |
---|
| 43 | def meanarea(dat1,dat2,totarea): |
---|
| 44 | meandat=np.zeros(dat1.shape[0]) |
---|
| 45 | for t in range(dat1.shape[0]): |
---|
| 46 | for i in range(dat1.shape[1]): |
---|
| 47 | for j in range(dat1.shape[2]): |
---|
| 48 | meandat[t]=meandat[t]+ma.getdata(dat1[t,i,j])*dat2[i,j]/totarea |
---|
| 49 | return meandat |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | mpl.figure(figsize=(8, 10)) |
---|
| 53 | |
---|
| 54 | myvar=getvar(nc1,var,tint,tim,t_mean=True) |
---|
| 55 | #myvar2=getvar(nc1,var,tint,tim) |
---|
| 56 | aire = getvar(nc2,"aire") |
---|
| 57 | totarea=zetotarea(aire) |
---|
| 58 | meantemp=meanarea(myvar,aire,totarea) |
---|
| 59 | #meantemp2=meanarea(myvar2,aire,totarea) |
---|
| 60 | |
---|
| 61 | font=23 |
---|
| 62 | |
---|
| 63 | lev=np.linspace(40,110,8) |
---|
| 64 | #xticks=[-90,-60,-30,0,30,60,90] |
---|
| 65 | #yticks=np.linspace(0,240,9) |
---|
| 66 | alt=alt/1000. |
---|
| 67 | #alt2=alt2/1000. |
---|
| 68 | |
---|
| 69 | mpl.plot(meantemp,alt,'r') |
---|
| 70 | #mpl.plot(meantemp2,alt2,'b--') |
---|
| 71 | |
---|
| 72 | #mpl.title('Latitude ='+str(tintstr[i]),fontsize=font) |
---|
| 73 | mpl.ylabel('Altitude (km)',labelpad=10,fontsize=font) |
---|
| 74 | mpl.xlabel('Temperature (K)',labelpad=10, fontsize=font) |
---|
| 75 | #mpl.xticks(xticks,fontsize=font) |
---|
| 76 | mpl.xticks(fontsize=font) |
---|
| 77 | #mpl.yticks(yticks,fontsize=font) |
---|
| 78 | mpl.yticks(fontsize=font) |
---|
| 79 | mpl.grid() |
---|
| 80 | mpl.legend(["Ref","Alt"],prop={'size':27},loc='upper left') |
---|
| 81 | |
---|
| 82 | left = 0.2 # the left side of the subplots of the figure |
---|
| 83 | right = None # the right side of the subplots of the figure |
---|
| 84 | bottom = None # the bottom of the subplots of the figure |
---|
| 85 | top = None # the top of the subplots of the figure |
---|
| 86 | wspace = None # the amount of width reserved for blank space between subplots |
---|
| 87 | hspace = None # the amount of height reserved for white space between subplots |
---|
| 88 | mpl.subplots_adjust(left, bottom, right, top, wspace, hspace) |
---|
| 89 | #mpl.subplots_adjust(hspace = .1) |
---|
| 90 | |
---|
| 91 | mpl.savefig('tempmean.eps',dpi=200) |
---|
| 92 | mpl.savefig('tempmean.png',dpi=200) |
---|
| 93 | mpl.show() |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | |
---|