source: lmdz_wrf/trunk/tools/documentation/plotting/create_TopoValues.py @ 1489

Last change on this file since 1489 was 1465, checked in by lfita, 8 years ago

Adding:

  • `draw_2D_shad_2cont': plotting three fields, one with shading and the other two with contour lines
  • `draw_ptZvals': Function to plot a given list of points by their Z value and a colorbar
  • `draw_vectors': Function to plot wind vectors
File size: 3.0 KB
Line 
1# Python script to create a file with mountain peaks and their heights
2# L. Fita, LMD March 2017
3#
4# To be used as example for PyNCplot `draw_ptZvals'
5#
6import numpy as np
7from netCDF4 import Dataset as NetCDFFile
8import generic_tools as gen
9import nc_var_tools as ncvar
10
11# A series of mountain peaks, their heights and their coordinates
12#   [DEGlon, MINlon, SEClon, DEGlat, MINlat, SEClat] (from Wikipedia)
13peaks = {'Everest': [8848., 86., 55., 31., 27., 59., 17.],                           \
14  'Mont Blanc': [4808.73, 6., 51., 53., 45., 49., 57.],                              \
15  'Aneto': [3404., -0., -39., -28., 42., 37., 56.],                                  \
16  'Aconcagua': [6962., -70., -0, -40., -32., -39., -12.],                            \
17  'Denali': [6190., -151., -0., -27., 63., 04., 10.],                                \
18  'Kilimanjaro': [5895., 37., 21, 35., -3.,-4.,-0.],                                 \
19  'Ulrulu': [863., 131., 2., 11., -25., -20, -42.],                                  \
20  'Elbrus': [5642., 42., 26., 21., 43., 21., 18.],                                   \
21  'Vinson': [4892., -85., -32., -2., -78., -31., -31.],                              \
22  'Enduwa Kombuglu': [4509., 145., 2., 0., -5., -48., -0.],                          \
23  'Orizaba': [5636., -97., -16., -12., 19., 01., 48.] }
24
25# Length of the peaks name
26Lstring = 250
27
28ofile = 'MountainPeaks.nc'
29
30#######    ########
31## MAIN
32    #######
33
34# Sorting peaks' names (just to be fancy...)
35peaksnames = list(peaks.keys())
36peaksnames.sort()
37
38onc = NetCDFFile(ofile, 'w')
39
40Nmountains = len(peaks.keys())
41
42# Dimensions
43newdim = onc.createDimension('mountain', Nmountains)
44newdim = onc.createDimension('Lstring', Lstring)
45
46# Variables
47newvarname = onc.createVariable('name', 'c', ('mountain', 'Lstring'))
48ncvar.basicvardef(newvarname,'name','Name of the peak','-')
49newattr = ncvar.set_attribute(newvarname,'coordinates','lon lat')
50newvals = ncvar.writing_str_nc(newvarname, peaksnames, Lstring)
51
52newvarlon = onc.createVariable('lon', 'f8', ('mountain'))
53ncvar.basicvardef(newvarlon,'longitude','Longitude','degrees_East')
54newattr = ncvar.set_attribute(newvarlon,'axis','X')
55newattr = ncvar.set_attribute(newvarlon,'_CoordinateAxisType','Lon')
56
57newvarlat = onc.createVariable('lat', 'f8', ('mountain'))
58ncvar.basicvardef(newvarlat,'latitude','Latitude','degrees_Noth')
59newattr = ncvar.set_attribute(newvarlat,'axis','Y')
60newattr = ncvar.set_attribute(newvarlat,'_CoordinateAxisType','Lat')
61
62newvarhgt = onc.createVariable('height', 'f4', ('mountain'))
63ncvar.basicvardef(newvarhgt,'height','Height above sea level','m')
64
65for keyv in peaks.keys():
66    peakv = peaks[keyv]
67    ipeak = peaksnames.index(keyv)
68
69    newvarhgt[ipeak] = peakv[0]
70    newvarlon[ipeak] = peakv[1] + peakv[2]/60. + peakv[3]/3600.
71    newvarlat[ipeak] = peakv[4] + peakv[5]/60. + peakv[6]/3600.
72
73    onc.sync()
74
75# Global values
76addglob = ncvar.add_global_PyNCplot(onc, 'create_TopoValues.py', 'main', '0.1')
77
78onc.sync()
79onc.close()
80
81print "Successful written of '" + ofile + "' !!"
82
Note: See TracBrowser for help on using the repository browser.