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

Last change on this file since 3823 was 3823, checked in by afalco, 4 days ago

Pluto: added some python scripts for visualization.
AF

  • Property svn:executable set to *
File size: 3.0 KB
Line 
1#! /usr/bin/env python
2from ppclass import pp
3from    netCDF4               import    Dataset
4from    numpy                 import    *
5import  numpy                 as        np
6import  matplotlib.pyplot     as        mpl
7from matplotlib.cm import get_cmap
8import pylab
9import matplotlib.colors as mcolors
10import colorsys
11
12############################
13filename1="diagfi2015_Av.nc"
14var="u" #variable
15tint=["30,32"] #Time must be as written in the input file
16xarea="-180,179"
17
18nc1=Dataset(filename1)
19
20lat=nc1.variables["lat"][:]
21lon=nc1.variables["lon"][:]
22alt=nc1.variables["altitude"][:]
23############################
24
25def getvar(filename,var,tint,xarea):
26    myvar = pp(file=filename,var=var,t=tint,x=xarea,compute="mean").getf()
27    print((shape(myvar)))
28    return myvar
29
30def make_colormap(seq):
31    """Return a LinearSegmentedColormap
32    seq: a sequence of floats and RGB-tuples. The floats should be increasing
33    and in the interval (0,1).
34    """
35
36    seq = [(None,) * 3, 0.0] + list(seq) + [1.0, (None,) * 3]
37    print(seq)
38    cdict = {'red': [], 'green': [], 'blue': []}
39    for i, item in enumerate(seq):
40        if isinstance(item, float):
41            r1, g1, b1 = seq[i - 1]
42            r2, g2, b2 = seq[i + 1]
43            cdict['red'].append([item, r1, r2])
44            cdict['green'].append([item, g1, g2])
45            cdict['blue'].append([item, b1, b2])
46    print(cdict)
47    return mcolors.LinearSegmentedColormap('CustomMap', cdict)
48
49def diverge_map(high, low):
50    '''
51    low and high are colors that will be used for the two
52    ends of the spectrum. they can be either color strings
53    or rgb color tuples
54    '''
55    c = mcolors.ColorConverter().to_rgb
56    if isinstance(low, str): low = c(low)      #si low=string (color)
57    if isinstance(high, str): high = c(high)
58    print(high)
59    return make_colormap([low, c('white'), 0.55, c('white'),0.65, c('white'), high])
60
61
62hh=(255,99,71)
63hh=(hh[0]/255,hh[1]/255,hh[2]/255)
64print(hh)
65h=hh #(0.565, 0.392, 0.173)
66l=(0.094, 0.310, 0.635)
67rvb1=diverge_map(h,l)
68
69myvar=getvar(filename1,var,tint,xarea)
70
71mpl.figure(figsize=(20, 10))
72
73font=26
74
75#pal=rvb1 #get_cmap(name="RdYlBu_r")
76#pal=get_cmap(name="Spectral_r")
77pal=get_cmap(name="rainbow")
78lev=np.linspace(-20,10,31)
79
80xticks=[-90,-60,-30,0,30,60,90]
81#yticks=np.linspace(0,240,9)
82alt=alt/1000.
83
84CF=mpl.contourf(lat,alt,myvar,lev,cmap=pal,extend='both')
85cbar=mpl.colorbar(CF,shrink=1, format="%1.2f")
86#cbar.ax.set_title("[K]",y=1.04,fontsize=font)
87for t in cbar.ax.get_yticklabels():
88      t.set_fontsize(font)
89
90vect=lev
91CS=mpl.contour(lat,alt,myvar,vect,colors='k',linewidths=0.5)
92#### inline=1 : values over the line
93mpl.clabel(CS, inline=1, fontsize=20, fmt='%1.0f',inline_spacing=1)
94
95#mpl.title('Latitude ='+str(tintstr[i]),fontsize=font)
96mpl.ylabel('Altitude (km)',labelpad=10,fontsize=font)
97mpl.xlabel('Latitude (deg)',labelpad=10, fontsize=font)
98mpl.xticks(xticks,fontsize=font)
99#mpl.xticks(fontsize=font)
100#mpl.yticks(yticks,fontsize=font)
101mpl.yticks(fontsize=font)
102pylab.ylim([-4,10])
103
104mpl.savefig('meanzonalwind_zoom.eps',dpi=200)
105mpl.savefig('meanzonalwind_zoom.png',dpi=200)
106mpl.show()
107
108
109
110
Note: See TracBrowser for help on using the repository browser.