1 | #! /usr/bin/env python |
---|
2 | from ppclass import pp |
---|
3 | from netCDF4 import Dataset |
---|
4 | from numpy import * |
---|
5 | import numpy as np |
---|
6 | import matplotlib.pyplot as mpl |
---|
7 | |
---|
8 | ## Author: Tanguy Bertrand |
---|
9 | |
---|
10 | ## Exemple d'histogramme |
---|
11 | # |
---|
12 | # INPUT : |
---|
13 | # |
---|
14 | # file |
---|
15 | # nb_dataset: number of dataset that is number of superposed histograms |
---|
16 | # Time range |
---|
17 | # altitude range |
---|
18 | # longitude range |
---|
19 | # latitude range |
---|
20 | # step: gap on xaxis between two ticks. Ex: step = 1 leads to one bar for each unit of the selected variable |
---|
21 | # variable : u, v, w, icetot, tsurf ... |
---|
22 | |
---|
23 | ############################ |
---|
24 | filename="diagfi1.nc" |
---|
25 | nb_dataset=3 |
---|
26 | tint=[["0.25,1.5"],["0.25,5.5"],["0.25,10.5"]] #Time must be as written in the input file |
---|
27 | zint=[["0.1,10"],["0.1,10"],["0.1,10"]] #alt in km |
---|
28 | xarea="-180,180" |
---|
29 | yarea="-90,90" |
---|
30 | step=5 |
---|
31 | var="u" #variable |
---|
32 | ############################ |
---|
33 | |
---|
34 | x=np.zeros(nb_dataset,dtype='object') #object of all datasets |
---|
35 | |
---|
36 | bornemax=0. # initialisation boundary values |
---|
37 | bornemin=0. |
---|
38 | |
---|
39 | for i in range(nb_dataset): |
---|
40 | |
---|
41 | myvar = pp(file=filename,var=var,t=tint[i],z=zint[i],x=xarea,y=yarea,compute="nothing").getf() # get data to be changed according to selected variable |
---|
42 | data=np.ravel(myvar) |
---|
43 | |
---|
44 | x[i]=np.array(data) |
---|
45 | |
---|
46 | #upper lower bounds: |
---|
47 | maxval=np.amax(myvar) |
---|
48 | romax=round(maxval,0) |
---|
49 | if abs(romax/maxval) < 1: romax=romax+1 |
---|
50 | |
---|
51 | minval=np.amin(myvar) |
---|
52 | romin=round(minval,0) |
---|
53 | if abs(romin/minval) < 1: romin=romin-1 |
---|
54 | |
---|
55 | bornemax=np.amax([romax,bornemax]) |
---|
56 | bornemin=np.amin([romin,bornemin]) |
---|
57 | # |
---|
58 | |
---|
59 | print 'minval,maxval=',minval,romax |
---|
60 | print 'romin,romax=',romin,romax |
---|
61 | print 'bornemin,bornemax=',bornemin,bornemax |
---|
62 | |
---|
63 | # bins definition: |
---|
64 | bins=np.arange(bornemin,bornemax+1,step) |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | vect=[x[0],x[1],x[2]] #vecteur of datasets to be changed according to the number of desired datasets |
---|
69 | |
---|
70 | ## PLOT |
---|
71 | # legend: |
---|
72 | zelab=['time: '+str(tint[0])+' - alt: '+str(zint[0])+' km','time: '+str(tint[1])+' - alt: '+str(zint[1])+' km','time: '+str(tint[2])+' - alt: '+str(zint[2])+' km'] |
---|
73 | # Histogram : normed, probability |
---|
74 | mpl.hist(vect,bins,normed=1,histtype='bar',align='mid',rwidth=0.8,label=zelab) |
---|
75 | mpl.legend(prop={'size':20}) |
---|
76 | mpl.title('U wind distribution',fontsize=20) |
---|
77 | mpl.xlabel('Horizontal Wind (m.s-1)',fontsize=20) |
---|
78 | mpl.ylabel('Probability',fontsize=20) |
---|
79 | mpl.xticks(bins,fontsize=16) |
---|
80 | mpl.yticks(fontsize=16) |
---|
81 | mpl.grid(True) |
---|
82 | |
---|
83 | mpl.show() |
---|
84 | |
---|
85 | |
---|
86 | mpl.figure(5) |
---|
87 | |
---|