Doc/Tools/External: plotting_topo.py

File plotting_topo.py, 1.1 KB (added by acosce, 8 years ago)

fichier TP python plotting_topo Bootcamp 24 mars 2016

Line 
1import numpy as np
2from netCDF4 import Dataset as NetCDFFile
3import matplotlib as mpl
4mpl.use('Agg')
5import matplotlib.pyplot as plt
6from mpl_toolkits.basemap import Basemap
7
8filename = '/media/ExtDiskC_ext4/bkup/foudre/feinetes/BootCamp/files/Relief.nc'
9toponame = 'RELIEF'
10ncobj = NetCDFFile(filename, 'r')
11
12objtopo = ncobj.variables[toponame]
13olon = ncobj.variables['longitude']
14olat = ncobj.variables['latitude']
15topovals = objtopo[:] 
16utopo = objtopo.getncattr('units')
17
18plt.rc('text', usetex=True)
19
20dx = olon.shape[0]
21dy = olat.shape[0]
22nlon = np.min(olon)
23xlon = np.max(olon)
24nlat = np.min(olat)
25xlat = np.max(olat)
26plt.xlim(nlon, xlon)
27plt.ylim(nlat, xlat)
28m = Basemap(projection='cyl', \
29  llcrnrlon=nlon, llcrnrlat=nlat, \
30  urcrnrlon=xlon, urcrnrlat= xlat, \
31  resolution='l')
32
33lons = olon[:]
34lats = olat[:]
35x,y = m(lons,lats)
36
37plt.pcolormesh(x,y,topovals, \
38  cmap=plt.get_cmap('terrain'), \
39  vmin=0., vmax=7000.)
40cbar = plt.colorbar()
41m.drawcoastlines()
42cbar.set_label(utopo)
43
44plt.xlabel('W-E')
45plt.ylabel('S-N')
46plt.title('Topography from a ' + \
47  'LMDZ domain at 1/' + \
48  str(olon.shape[0]/360) + ' deg')
49
50plt.savefig("topo.png")
51plt.close()