source: trunk/LMDZ.PLUTO/util/script_figures/tempglobmean.py @ 3833

Last change on this file since 3833 was 3833, checked in by afalco, 2 days ago

Pluto: updated plots scripts.
Fixed some issues with reading XIOS, etc.
Included display_netcdf.py tool from Mars PCM.
AF

  • Property svn:executable set to *
File size: 2.7 KB
RevLine 
[3823]1#! /usr/bin/env python
2from    netCDF4               import    Dataset
3from    numpy                 import    *
4import  numpy                 as        np
5import  matplotlib.pyplot     as        mpl
6from matplotlib.cm import get_cmap
7import pylab
8from matplotlib import ticker
9import matplotlib.colors as colors
10import datetime
11from mpl_toolkits.basemap import Basemap, shiftgrid
12from FV3_utils import *
[3833]13from input import *
[3823]14
15############################
16# folder="../"
17filename1=name+"_A.nc"
18filename2=name+".nc"
19#filename3="../simu_pole/diagfi2015_S.nc"
20var="temperature" #variable
21tint=[30,35] #Time must be as written in the input file
22print("Reading ", filename1, filename2)
23
24nc1=Dataset(filename1)
25nc2=Dataset(filename2)
26#nc3=Dataset(filename3)
27
28
29lat=getvar(nc1,"latitude")
30lon=getvar(nc1,"longitude")
31alt=getvar(nc1,"altitude")
32tim=getvar(nc1,"Time")
33#alt2=nc3.variables["altitude"][:]
34############################
35
36def 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
44def 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
53mpl.figure(figsize=(8, 10))
54
[3833]55myvar=getvar(nc1,var,tint,t_mean=True)
56#myvar2=getvar(nc1,var,tint)
[3823]57aire = getvar(nc2,"aire")
58totarea=zetotarea(aire)
59meantemp=meanarea(myvar,aire,totarea)
60#meantemp2=meanarea(myvar2,aire,totarea)
61
62font=23
63
64lev=np.linspace(40,110,8)
65#xticks=[-90,-60,-30,0,30,60,90]
66#yticks=np.linspace(0,240,9)
67alt=alt/1000.
68#alt2=alt2/1000.
69
70mpl.plot(meantemp,alt,'r')
71#mpl.plot(meantemp2,alt2,'b--')
72
[3833]73mpl.title('Global mean temperature',fontsize=font)
[3823]74mpl.ylabel('Altitude (km)',labelpad=10,fontsize=font)
75mpl.xlabel('Temperature (K)',labelpad=10, fontsize=font)
76#mpl.xticks(xticks,fontsize=font)
77mpl.xticks(fontsize=font)
78#mpl.yticks(yticks,fontsize=font)
79mpl.yticks(fontsize=font)
80mpl.grid()
[3833]81# mpl.legend(["Ref","Alt"],prop={'size':27},loc='upper left')
[3823]82
83left  = 0.2  # the left side of the subplots of the figure
84right = None   # the right side of the subplots of the figure
85bottom = None  # the bottom of the subplots of the figure
86top = None     # the top of the subplots of the figure
87wspace = None  # the amount of width reserved for blank space between subplots
88hspace = None  # the amount of height reserved for white space between subplots
89mpl.subplots_adjust(left, bottom, right, top, wspace, hspace)
90#mpl.subplots_adjust(hspace = .1)
91
92mpl.savefig('tempmean.eps',dpi=200)
93mpl.savefig('tempmean.png',dpi=200)
94mpl.show()
95
96
97
Note: See TracBrowser for help on using the repository browser.