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