1 | # Python script to plot lidar values from 'lidar.nc' from 'LIDAR_ASCII_netCDF.py' |
---|
2 | # L. Fita, LMD. Jussieu, November 2013 |
---|
3 | ## g.e. # plot_lidar.py -f lidar.nc -c 'BuPu' -v 'qv,0.0,0.001' -k pdf -r True |
---|
4 | ## g.e. # plot_lidar.py -f lidar.nc -c 'seismic' -v 'w,-0.5,0.5' -k pdf -r True |
---|
5 | |
---|
6 | # |
---|
7 | ## export PATH=/u/lflmd/bin/gcc_Python-2.7.5/bin:${PATH} |
---|
8 | |
---|
9 | import numpy as np |
---|
10 | from netCDF4 import Dataset as NetCDFFile |
---|
11 | import os |
---|
12 | import re |
---|
13 | import nc_var_tools as ncvar |
---|
14 | from optparse import OptionParser |
---|
15 | import drawing_tools as drawpy |
---|
16 | |
---|
17 | main = 'plot_lidar' |
---|
18 | errormsg = 'ERROR -- error -- ERROR -- error' |
---|
19 | |
---|
20 | ####### ###### ##### #### ### ## # |
---|
21 | |
---|
22 | |
---|
23 | parser = OptionParser() |
---|
24 | parser.add_option("-c", "--Color_Bar", dest="colorbar", |
---|
25 | help="""color bar to use in the plot: |
---|
26 | Sequential: 'binary', 'Blues', 'BuGn', 'BuPu', |
---|
27 | 'gist_yarg', 'GnBu', 'Greens', 'Greys', |
---|
28 | 'Oranges', 'OrRd', 'PuBu', 'PuBuGn', |
---|
29 | 'PuRd', 'Purples', 'RdPu', 'Reds', 'YlGn', |
---|
30 | 'YlGnBu', 'YlOrBr', 'YlOrRd' |
---|
31 | Sequential 2: 'afmhot', 'autumn', 'bone', 'cool', |
---|
32 | 'copper', 'gist_gray', 'gist_heat', 'gray', |
---|
33 | 'hot', 'pink', 'spring', 'summer', 'winter' |
---|
34 | Diverging: 'BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', |
---|
35 | 'PuOr', 'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', |
---|
36 | 'seismic' |
---|
37 | Qualitative: 'Accent', 'Dark2', 'hsv', 'Paired', |
---|
38 | 'Pastel1', 'Pastel2', 'Set1', 'Set2', |
---|
39 | 'Set3', 'spectral' |
---|
40 | Miscellaneous: 'gist_earth', 'gist_ncar', |
---|
41 | 'gist_rainbow', 'gist_stern', 'jet', 'brg', |
---|
42 | 'CMRmap', 'cubehelix', 'gnuplot', 'gnuplot2', |
---|
43 | 'ocean', 'rainbow', 'terrain', 'flag', |
---|
44 | 'prism' |
---|
45 | http://matplotlib.org/1.3.1/examples/color/colormaps_reference.html""", metavar="LABEL") |
---|
46 | parser.add_option("-f", "--file", dest="ifile", |
---|
47 | help="netCDF file to use", metavar="FILE") |
---|
48 | parser.add_option("-k", "--figure_kind", dest="kfig", |
---|
49 | help="kind of figure ('null', only show, 'png', 'pdf')", metavar="LABEL") |
---|
50 | parser.add_option("-r", "--reverseAxes", dest="reversea", |
---|
51 | help="indicate if axes have to be reversed (default False. True, x-->y, y-->x)", metavar="FILE") |
---|
52 | parser.add_option("-v", "--variable", dest="var", |
---|
53 | help="varn,minv,maxv (name of the variable, minimum and maximum values ['all', full range]", metavar="LABEL") |
---|
54 | |
---|
55 | (opts, args) = parser.parse_args() |
---|
56 | |
---|
57 | ####### ####### |
---|
58 | ## MAIN |
---|
59 | ####### |
---|
60 | |
---|
61 | if not os.path.isfile(opts.ifile): |
---|
62 | print errormsg |
---|
63 | print ' ' + main + ' file: "' + opts.ifile + '" does not exist !!' |
---|
64 | print errormsg |
---|
65 | quit(-1) |
---|
66 | |
---|
67 | objifile = NetCDFFile(opts.ifile, 'r') |
---|
68 | varobj = objifile.variables[opts.var.split(',')[0]] |
---|
69 | varvalues = varobj[:] |
---|
70 | |
---|
71 | oheights = objifile.variables['z'] |
---|
72 | otimes = objifile.variables['time'] |
---|
73 | heights = oheights[:] |
---|
74 | times = otimes[:] |
---|
75 | |
---|
76 | drawpy.check_colorBar(opts.colorbar) |
---|
77 | |
---|
78 | varname = opts.var.split(',')[0] |
---|
79 | varmin = opts.var.split(',')[1] |
---|
80 | if varmin == 'all': |
---|
81 | varn = np.min(varvalues) |
---|
82 | else: |
---|
83 | varn = np.float(opts.var.split(',')[1]) |
---|
84 | |
---|
85 | varmax = opts.var.split(',')[2] |
---|
86 | if varmax == 'all': |
---|
87 | varx = np.max(varvalues) |
---|
88 | else: |
---|
89 | varx = np.float(opts.var.split(',')[2]) |
---|
90 | |
---|
91 | if not opts.reversea is None: |
---|
92 | reversea = opts.reversea |
---|
93 | else: |
---|
94 | reversea = False |
---|
95 | |
---|
96 | drawpy.plot_2Dfield_easy(varvalues, heights, times, \ |
---|
97 | ['time (h since simulation start)','z'], opts.colorbar, varn, varx, \ |
---|
98 | drawpy.units_lunits(varobj.getncattr('units')), opts.ifile, varname, opts.kfig, \ |
---|
99 | reversea) |
---|
100 | |
---|