1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | ### A. Spiga + T. Navarro + A. Colaitis |
---|
4 | |
---|
5 | ########################################################################################### |
---|
6 | ########################################################################################### |
---|
7 | ### What is below relate to running the file as a command line executable (very convenient) |
---|
8 | if __name__ == "__main__": |
---|
9 | import sys |
---|
10 | from optparse import OptionParser ### to be replaced by argparse |
---|
11 | from api_wrapper import api_onelevel |
---|
12 | from zrecast_wrapper import call_zrecast |
---|
13 | from netCDF4 import Dataset |
---|
14 | from myplot import getlschar, separatenames, readslices, adjust_length, whatkindfile, errormess |
---|
15 | from os import system |
---|
16 | from planetoplot import planetoplot |
---|
17 | from myscript import getparseroptions |
---|
18 | import numpy as np |
---|
19 | |
---|
20 | ############################# |
---|
21 | ### Get options and variables |
---|
22 | parser = OptionParser() ; getparseroptions(parser) ; (opt,args) = parser.parse_args() |
---|
23 | if opt.file is None: errormess("I want to eat one file at least ! Use winds.py -f name_of_my_file. Or type winds.py -h") |
---|
24 | if opt.var is None and opt.anomaly is True: errormess("Cannot ask to compute anomaly if no variable is set") |
---|
25 | if opt.fref is not None and opt.operat is None: errormess("you must specify an operation when using a reference file") |
---|
26 | if opt.operat in ["+","-"] and opt.fref is None: errormess("you must specifiy a reference file when using inter-file operations") |
---|
27 | if opt.fref is not None and opt.operat is not None and opt.itp is not None: interpref=True |
---|
28 | else: interpref=False |
---|
29 | |
---|
30 | ############################# |
---|
31 | ### Get infos about slices |
---|
32 | zeslat = readslices(opt.slat) ; zeslon = readslices(opt.slon) ; zesvert = readslices(opt.svert) ; zestime = readslices(opt.stime) |
---|
33 | reffile = opt.fref |
---|
34 | zexaxis = [opt.xmin,opt.xmax] ; zeyaxis=[opt.ymin,opt.ymax] |
---|
35 | |
---|
36 | ############################# |
---|
37 | ### 1. LOOP ON FILE LISTS TO BE PUT IN DIFFERENT FIGURES |
---|
38 | for i in range(len(opt.file)): |
---|
39 | |
---|
40 | zefiles = separatenames(opt.file[i]) |
---|
41 | |
---|
42 | typefile = whatkindfile(Dataset(zefiles[0])) |
---|
43 | stralt = None |
---|
44 | if typefile in ["meso","mesoapi"]: |
---|
45 | [lschar,zehour,zehourin] = getlschar ( zefiles[0] ) |
---|
46 | if opt.var is None: opt.var = ["HGT"] |
---|
47 | else: |
---|
48 | [lschar,zehour,zehourin] = ["",0,0] |
---|
49 | if opt.var is None: opt.var = ["phisinit"] |
---|
50 | |
---|
51 | if opt.vmin is not None : zevmin = opt.vmin[min(i,len(opt.vmin)-1)] |
---|
52 | else: zevmin = None |
---|
53 | if opt.vmax is not None : zevmax = opt.vmax[min(i,len(opt.vmax)-1)] |
---|
54 | else: zevmax = None |
---|
55 | #print "vmin, zevmin", opt.vmin, zevmin ; print "vmax, zevmax", opt.vmax, zevmax |
---|
56 | |
---|
57 | ############################# |
---|
58 | ### 2. LOOP ON VAR LISTS TO BE PUT IN DIFFERENT FIGURES |
---|
59 | for j in range(len(opt.var)): |
---|
60 | |
---|
61 | zevars = separatenames(opt.var[j]) |
---|
62 | |
---|
63 | inputnvert = separatenames(opt.lvl) |
---|
64 | if np.array(inputnvert).size == 1: |
---|
65 | zelevel = float(inputnvert[0]) |
---|
66 | ze_interp_levels = [-9999.] |
---|
67 | else: |
---|
68 | zelevel = -99. |
---|
69 | ze_interp_levels = np.linspace(float(inputnvert[0]),float(inputnvert[1]),float(inputnvert[2])) |
---|
70 | |
---|
71 | ######################################################### |
---|
72 | ### Call Fortran routines for vertical interpolations ### |
---|
73 | ######################################################### |
---|
74 | if opt.itp is not None: |
---|
75 | ##### |
---|
76 | ##### MESOSCALE : written by AS |
---|
77 | ##### |
---|
78 | if typefile == "meso": |
---|
79 | if zelevel == 0. and opt.itp == 4: zelevel = 0.010 |
---|
80 | ### winds or no winds |
---|
81 | if opt.winds : zefields = 'uvmet' |
---|
82 | else : zefields = '' |
---|
83 | ### var or no var |
---|
84 | if zefields == '' : zefields = opt.var[j] |
---|
85 | else : zefields = zefields + "," + opt.var[j] |
---|
86 | if opt.var2 is not None : zefields = zefields + "," + opt.var2 |
---|
87 | ### call fortran routines |
---|
88 | for fff in range(len(zefiles)): |
---|
89 | newname = api_onelevel ( path_to_input = '', \ |
---|
90 | input_name = zefiles[fff], \ |
---|
91 | fields = zefields, \ |
---|
92 | interp_method = opt.itp, \ |
---|
93 | interp_level = ze_interp_levels, \ |
---|
94 | onelevel = zelevel, \ |
---|
95 | nocall = opt.nocall ) |
---|
96 | if fff == 0: zetab = newname |
---|
97 | else: zetab = np.append(zetab,newname) |
---|
98 | zefiles = zetab #; print zefiles |
---|
99 | zelevel = 0 ## so that zelevel could play again the role of nvert |
---|
100 | ##### |
---|
101 | ##### GCM : written by AC |
---|
102 | ##### |
---|
103 | elif typefile == "gcm": |
---|
104 | interpolated_files="" |
---|
105 | interpolated_files=call_zrecast(interp_mode=opt.itp,\ |
---|
106 | input_name=zefiles,\ |
---|
107 | fields=zevars,\ |
---|
108 | predifined=opt.intas) |
---|
109 | |
---|
110 | zefiles=interpolated_files |
---|
111 | if interpref: |
---|
112 | interpolated_ref="" |
---|
113 | interpolated_ref=call_zrecast(interp_mode=opt.itp,\ |
---|
114 | input_name=[opt.fref],\ |
---|
115 | fields=zevars,\ |
---|
116 | predifined=opt.intas) |
---|
117 | |
---|
118 | reffile=interpolated_ref[0] |
---|
119 | else: |
---|
120 | print "not supported" |
---|
121 | exit() |
---|
122 | |
---|
123 | ############# |
---|
124 | ### Main call |
---|
125 | name = planetoplot (zefiles,level=int(zelevel),vertmode=opt.itp,\ |
---|
126 | proj=opt.proj,back=opt.back,target=opt.tgt,stride=opt.ste,var=zevars,\ |
---|
127 | numplot=opt.num,colorb=opt.clb,winds=opt.winds,\ |
---|
128 | addchar=lschar,interv=[zehour,zehourin],vmin=zevmin,vmax=zevmax,\ |
---|
129 | tile=opt.tile,zoom=opt.zoom,display=opt.display,\ |
---|
130 | itstep=opt.it,hole=opt.hole,save=opt.save,\ |
---|
131 | anomaly=opt.anomaly,var2=opt.var2,ndiv=opt.ndiv,first=opt.frt,\ |
---|
132 | mult=opt.mult,zetitle=opt.zetitle,\ |
---|
133 | slon=zeslon,slat=zeslat,svert=zesvert,stime=zestime,\ |
---|
134 | outputname=opt.out,resolution=opt.res,\ |
---|
135 | ope=opt.operat,fileref=reffile,minop=opt.vminope,maxop=opt.vmaxope,titleref=opt.titref,\ |
---|
136 | invert_y=opt.inverty,xaxis=zexaxis,yaxis=zeyaxis,ylog=opt.logy,yintegral=opt.column,\ |
---|
137 | blat=opt.blat,tsat=opt.tsat,flagnolow=opt.nolow) |
---|
138 | print 'DONE: '+name |
---|
139 | system("rm -f to_be_erased") |
---|
140 | |
---|
141 | ######################################################### |
---|
142 | ### Generate a .sh file with the used command saved in it |
---|
143 | command = "" |
---|
144 | for arg in sys.argv: command = command + arg + ' ' |
---|
145 | if typefile not in ["meso","mesoapi"]: name = 'pycommand' |
---|
146 | f = open(name+'.sh', 'w') |
---|
147 | f.write(command) |
---|
148 | |
---|
149 | print "********** OPTIONS: ", opt |
---|
150 | print "********************************************************** END" |
---|