source: trunk/LMDZ.PLUTO/util/script_figures/meanzonalwind.py @ 4102

Last change on this file since 4102 was 3868, checked in by afalco, 8 months ago

Pluto: update figure scripts.
AF

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