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