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