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

Last change on this file since 3823 was 3823, checked in by afalco, 45 hours ago

Pluto: added some python scripts for visualization.
AF

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