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