1 | # Python script to draw trajectories |
---|
2 | # L. Fita, LMD. May 2014 |
---|
3 | ## e.g. # trajectories.py -m /home/lflmd/etudes/domains/WL_HyMeX/geo_em.d01.nc,XLONG_M,XLAT_M -s 'control:cu1:mp1:pblsfc1:rad1:shallow:wlmdza' -f /home/lflmd/etudes/WRF_LMDZ/WL_HyMeX/analysis/superstorm -w wss -M cyl,i -l -4.,33.,16.,44. |
---|
4 | |
---|
5 | from optparse import OptionParser |
---|
6 | import numpy as np |
---|
7 | from netCDF4 import Dataset as NetCDFFile |
---|
8 | import os |
---|
9 | import re |
---|
10 | import nc_var_tools as ncvar |
---|
11 | import drawing_tools as drwpy |
---|
12 | |
---|
13 | main='trajectories.py' |
---|
14 | |
---|
15 | errormsg='ERROR -- error -- ERROR -- error' |
---|
16 | warnmsg='WARNING -- warning -- WARNING -- warning' |
---|
17 | |
---|
18 | ####### ###### ##### #### ### ## # |
---|
19 | |
---|
20 | parser = OptionParser() |
---|
21 | parser.add_option("-f", "--folder", dest="infold", |
---|
22 | help="folder with the data", metavar="FOLD") |
---|
23 | parser.add_option("-l", "--lonlatlims", dest="Lllim", |
---|
24 | help="OPTIONAL: limits of the map [lonmin, latmin, lonmax, latmax]", metavar="FOLD") |
---|
25 | parser.add_option("-M", "--mapKind", dest="mapkind", |
---|
26 | help="""drawing coastaline ([proj],[res]) |
---|
27 | [proj]: projection |
---|
28 | * 'cyl', cilindric |
---|
29 | [res]: resolution: |
---|
30 | * 'c', crude |
---|
31 | * 'l', low |
---|
32 | * 'i', intermediate |
---|
33 | * 'h', high |
---|
34 | * 'f', full |
---|
35 | """, metavar="FILE") |
---|
36 | parser.add_option("-m", "--map", dest="map", |
---|
37 | help="[file],[lonname],[latname] ([file] with the [lon],[lat] matrices", metavar="FILE") |
---|
38 | parser.add_option("-s", "--Simulations", dest="sims", |
---|
39 | help="':' list separated of the labels of the simulations", metavar="LABEL") |
---|
40 | parser.add_option("-t", "--TimeInterval", dest="tint", |
---|
41 | help="OPTIONAL: dates interval to use [init],[endt]", metavar="FOLD") |
---|
42 | parser.add_option("-w", "--simulated_variable", dest="svarname", |
---|
43 | help="simulated variable to use", metavar="VAR") |
---|
44 | |
---|
45 | (opts, args) = parser.parse_args() |
---|
46 | |
---|
47 | ####### ####### |
---|
48 | ## MAIN |
---|
49 | ####### |
---|
50 | |
---|
51 | sims= opts.sims.split(':') |
---|
52 | leglabels = sims |
---|
53 | |
---|
54 | Nsims = len(sims) |
---|
55 | |
---|
56 | if opts.mapkind is not None: |
---|
57 | geofile = opts.map.split(',')[0] |
---|
58 | lonn = opts.map.split(',')[1] |
---|
59 | latn = opts.map.split(',')[2] |
---|
60 | |
---|
61 | if not os.path.isfile(geofile): |
---|
62 | print errormsg |
---|
63 | print ' ' + main + ' map file: "' + geofile + '" does not exist !!' |
---|
64 | quit(-1) |
---|
65 | |
---|
66 | geoobj = NetCDFFile(geofile, 'r') |
---|
67 | lonobj = geoobj.variables[lonn] |
---|
68 | latobj = geoobj.variables[latn] |
---|
69 | |
---|
70 | if opts.tint is not None: |
---|
71 | tini = np.float(opts.tint.split(',')[0]) |
---|
72 | tend = np.float(opts.tint.split(',')[0]) |
---|
73 | else: |
---|
74 | tini = -1 |
---|
75 | tend = -1 |
---|
76 | |
---|
77 | if opts.Lllim is not None: |
---|
78 | lonlatlims = np.zeros((4), dtype=np.float) |
---|
79 | lonlatlims[0] = np.float(opts.Lllim.split(',')[0]) |
---|
80 | lonlatlims[1] = np.float(opts.Lllim.split(',')[1]) |
---|
81 | lonlatlims[2] = np.float(opts.Lllim.split(',')[2]) |
---|
82 | lonlatlims[3] = np.float(opts.Lllim.split(',')[3]) |
---|
83 | ## lonlatlims = np.matrix(opts.Lllim.split(','), dtype=np.float) |
---|
84 | |
---|
85 | else: |
---|
86 | lonlatlims = None |
---|
87 | |
---|
88 | lontrjv = [] |
---|
89 | lattrjv = [] |
---|
90 | |
---|
91 | for sim in sims: |
---|
92 | trjfile=opts.infold + '/' + sim + '/tevolboxtraj_' + opts.svarname + '.nc' |
---|
93 | if not os.path.isfile(trjfile): |
---|
94 | print errormsg |
---|
95 | print ' ' + main + ' trajectory file: "' + trjfile + '" does not exist !!' |
---|
96 | quit(-1) |
---|
97 | |
---|
98 | trjobj = NetCDFFile(trjfile, 'r') |
---|
99 | lontr = trjobj.variables['trlon'] |
---|
100 | lattr = trjobj.variables['trlat'] |
---|
101 | |
---|
102 | lontrjv.append(lontr[:]) |
---|
103 | lattrjv.append(lattr[:]) |
---|
104 | trjobj.close() |
---|
105 | |
---|
106 | drwpy.plot_Trajectories(lontrjv, lattrjv, leglabels, tini, tend, lonobj, latobj, \ |
---|
107 | lonlatlims, 'trajectories', 'pdf', opts.mapkind) |
---|