[3823] | 1 | #! /usr/bin/env python |
---|
[3833] | 2 | import os |
---|
[3823] | 3 | from netCDF4 import Dataset |
---|
| 4 | from numpy import * |
---|
| 5 | import numpy as np |
---|
| 6 | import matplotlib.pyplot as mpl |
---|
| 7 | from matplotlib.cm import get_cmap |
---|
| 8 | import pylab |
---|
| 9 | from matplotlib import ticker |
---|
| 10 | import matplotlib.colors as colors |
---|
| 11 | import datetime |
---|
| 12 | from mpl_toolkits.basemap import Basemap, shiftgrid |
---|
| 13 | from matplotlib.cm import get_cmap |
---|
[3833] | 14 | from FV3_utils import * |
---|
| 15 | from input import * # import name |
---|
| 16 | print("Running "+os.path.basename(__file__)) |
---|
[3823] | 17 | |
---|
| 18 | ############################ |
---|
| 19 | fa='sans-serif' |
---|
| 20 | hfont = {'fontname':'Arial'} |
---|
| 21 | mpl.rc('font',family=fa) |
---|
| 22 | mpl.rc('pdf',fonttype=42) |
---|
| 23 | font=30 |
---|
| 24 | cc=['k'] |
---|
| 25 | pal=get_cmap(name="rainbow") |
---|
| 26 | norm=colors.LogNorm() |
---|
| 27 | lvls=np.logspace(-6,-4,21) |
---|
| 28 | norm=None #colors.LogNorm() |
---|
| 29 | |
---|
| 30 | ### Data |
---|
| 31 | try: |
---|
[3833] | 32 | print("Plotting "+name+"_A.nc") |
---|
[3823] | 33 | nc1=Dataset(name+"_A.nc") |
---|
| 34 | except: |
---|
[3833] | 35 | print("Plotting "+name+".nc") |
---|
[3823] | 36 | nc1=Dataset(name+".nc") |
---|
[3833] | 37 | alt=getvar(nc1,"altitude") |
---|
| 38 | lat=getvar(nc1,"latitude") |
---|
| 39 | lon=getvar(nc1,"longitude") |
---|
[3823] | 40 | # temp=switchlon(temp) |
---|
| 41 | |
---|
[3833] | 42 | if lon[0]<0: |
---|
| 43 | lon=lon+180. |
---|
| 44 | |
---|
| 45 | def plot_alt(altitude = 1): |
---|
[3823] | 46 | temp=nc1.variables["temperature"][:,:,:,:] |
---|
| 47 | numalt=getind(altitude,alt) |
---|
| 48 | temp=temp[:,numalt,:,:] |
---|
| 49 | temp=np.mean(temp,axis=0) |
---|
| 50 | |
---|
| 51 | min_t=temp.min() |
---|
| 52 | max_t=temp.max() |
---|
| 53 | lvls=np.linspace(min_t,max_t,21) |
---|
| 54 | |
---|
| 55 | ### Figure |
---|
| 56 | fig=mpl.figure(figsize=(15, 10)) |
---|
| 57 | CF=mpl.contourf(lon, lat, temp,lvls,cmap=pal,norm=norm) |
---|
| 58 | cbar=mpl.colorbar(CF, shrink=1, ticks=lvls[::2],format="%1.1f") |
---|
| 59 | cbar.ax.set_title("[kg m$^{-2}$]",y=1.04,fontsize=font) |
---|
| 60 | for t in cbar.ax.get_yticklabels(): |
---|
| 61 | t.set_fontsize(font) |
---|
| 62 | |
---|
| 63 | vect=lvls |
---|
| 64 | CS=mpl.contour(lon,lat,temp,lvls[:],colors='k',linewidths=0.5) |
---|
| 65 | lab=mpl.clabel(CS, inline=1, fontsize=20, fmt='%1.1f',inline_spacing=1) |
---|
| 66 | for l in lab: |
---|
| 67 | l.set_rotation(0) |
---|
| 68 | |
---|
| 69 | mpl.grid() |
---|
[3833] | 70 | mpl.title(f"Temperatures @ z={altitude}km",fontsize=font) |
---|
[3823] | 71 | mpl.ylabel(r'Latitude',labelpad=10,fontsize=font) |
---|
| 72 | mpl.xlabel('Longitude',labelpad=10, fontsize=font) |
---|
| 73 | pylab.ylim([-90,90]) |
---|
| 74 | yticks=np.linspace(-90,90,13) |
---|
| 75 | pylab.xlim([0,360]) |
---|
| 76 | xticks=np.linspace(0,360,7) |
---|
| 77 | mpl.yticks(yticks,fontsize=font) |
---|
| 78 | mpl.xticks(xticks,fontsize=font) |
---|
[3833] | 79 | output=f"maptemp{altitude}" |
---|
| 80 | mpl.savefig(output,bbox_inches='tight',dpi=70) |
---|
| 81 | print(f"Saved {output}") |
---|
[3823] | 82 | #mpl.show() |
---|
| 83 | |
---|
| 84 | |
---|
[3833] | 85 | plot_alt(1) |
---|
| 86 | plot_alt(5) |
---|
| 87 | plot_alt(20) |
---|
| 88 | plot_alt(50) |
---|
| 89 | plot_alt(100) |
---|