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])) ; stralt = None |
---|
43 | if typefile in ["meso","mesoapi","mesoideal"]: |
---|
44 | [lschar,zehour,zehourin] = getlschar ( zefiles[0] ) |
---|
45 | if opt.var is None: opt.var = ["HGT"] ; opt.clb = "nobar" |
---|
46 | elif typefile in ["geo"]: |
---|
47 | [lschar,zehour,zehourin] = ["",0,0] |
---|
48 | if opt.var is None: opt.var = ["HGT_M"] ; opt.clb = "nobar" |
---|
49 | else: |
---|
50 | [lschar,zehour,zehourin] = ["",0,0] |
---|
51 | if opt.var is None: opt.var = ["phisinit"] ; opt.clb = "nobar" |
---|
52 | |
---|
53 | if opt.vmin is not None : zevmin = opt.vmin[min(i,len(opt.vmin)-1)] |
---|
54 | else: zevmin = None |
---|
55 | if opt.vmax is not None : zevmax = opt.vmax[min(i,len(opt.vmax)-1)] |
---|
56 | else: zevmax = None |
---|
57 | #print "vmin, zevmin", opt.vmin, zevmin ; print "vmax, zevmax", opt.vmax, zevmax |
---|
58 | |
---|
59 | ############################# |
---|
60 | ### 2. LOOP ON VAR LISTS TO BE PUT IN DIFFERENT FIGURES |
---|
61 | for j in range(len(opt.var)): |
---|
62 | |
---|
63 | zevars = separatenames(opt.var[j]) |
---|
64 | |
---|
65 | inputnvert = separatenames(opt.lvl) |
---|
66 | if np.array(inputnvert).size == 1: |
---|
67 | zelevel = float(inputnvert[0]) |
---|
68 | ze_interp_levels = [-9999.] |
---|
69 | else: |
---|
70 | zelevel = -99. |
---|
71 | ze_interp_levels = np.linspace(float(inputnvert[0]),float(inputnvert[1]),float(inputnvert[2])) |
---|
72 | |
---|
73 | ######################################################### |
---|
74 | ### Call Fortran routines for vertical interpolations ### |
---|
75 | ######################################################### |
---|
76 | if opt.itp is not None: |
---|
77 | ##### |
---|
78 | ##### MESOSCALE : written by AS |
---|
79 | ##### |
---|
80 | if typefile in ["meso","mesoideal"]: |
---|
81 | if zelevel == 0. and opt.itp == 4: zelevel = 0.010 |
---|
82 | ### winds or no winds |
---|
83 | if opt.winds : zefields = 'uvmet' |
---|
84 | else : zefields = '' |
---|
85 | ### var or no var |
---|
86 | if zefields == '' : zefields = opt.var[j] |
---|
87 | else : zefields = zefields + "," + opt.var[j] |
---|
88 | if opt.var2 is not None : zefields = zefields + "," + opt.var2 |
---|
89 | ### call fortran routines |
---|
90 | for fff in range(len(zefiles)): |
---|
91 | newname = api_onelevel ( path_to_input = '', \ |
---|
92 | input_name = zefiles[fff], \ |
---|
93 | fields = zefields, \ |
---|
94 | interp_method = opt.itp, \ |
---|
95 | interp_level = ze_interp_levels, \ |
---|
96 | onelevel = zelevel, \ |
---|
97 | nocall = opt.nocall ) |
---|
98 | if fff == 0: zetab = newname |
---|
99 | else: zetab = np.append(zetab,newname) |
---|
100 | zefiles = zetab #; print zefiles |
---|
101 | zelevel = 0 ## so that zelevel could play again the role of nvert |
---|
102 | ##### |
---|
103 | ##### GCM : written by AC |
---|
104 | ##### |
---|
105 | elif typefile == "gcm": |
---|
106 | interpolated_files="" |
---|
107 | interpolated_files=call_zrecast(interp_mode=opt.itp,\ |
---|
108 | input_name=zefiles,\ |
---|
109 | fields=zevars,\ |
---|
110 | predifined=opt.intas) |
---|
111 | |
---|
112 | zefiles=interpolated_files |
---|
113 | if interpref: |
---|
114 | interpolated_ref="" |
---|
115 | interpolated_ref=call_zrecast(interp_mode=opt.itp,\ |
---|
116 | input_name=[opt.fref],\ |
---|
117 | fields=zevars,\ |
---|
118 | predifined=opt.intas) |
---|
119 | |
---|
120 | reffile=interpolated_ref[0] |
---|
121 | else: |
---|
122 | print "type not supported" |
---|
123 | exit() |
---|
124 | |
---|
125 | ############# |
---|
126 | ### Main call |
---|
127 | name = planetoplot (zefiles,level=int(zelevel),vertmode=opt.itp,\ |
---|
128 | proj=opt.proj,back=opt.back,target=opt.tgt,stride=opt.ste,var=zevars,\ |
---|
129 | colorb=opt.clb,winds=opt.winds,\ |
---|
130 | addchar=lschar,interv=[zehour,zehourin],vmin=zevmin,vmax=zevmax,\ |
---|
131 | tile=opt.tile,zoom=opt.zoom,display=opt.display,\ |
---|
132 | hole=opt.hole,save=opt.save,\ |
---|
133 | anomaly=opt.anomaly,var2=opt.var2,ndiv=opt.ndiv,\ |
---|
134 | mult=opt.mult,zetitle=opt.zetitle,\ |
---|
135 | slon=zeslon,slat=zeslat,svert=zesvert,stime=zestime,\ |
---|
136 | outputname=opt.out,resolution=opt.res,\ |
---|
137 | ope=opt.operat,fileref=reffile,minop=opt.vminope,maxop=opt.vmaxope,titleref=opt.titref,\ |
---|
138 | invert_y=opt.inverty,xaxis=zexaxis,yaxis=zeyaxis,ylog=opt.logy,yintegral=opt.column,\ |
---|
139 | blat=opt.blat,tsat=opt.tsat,flagnolow=opt.nolow,mrate=opt.rate) |
---|
140 | print 'DONE: '+name |
---|
141 | system("rm -f to_be_erased") |
---|
142 | |
---|
143 | ######################################################### |
---|
144 | ### Generate a .sh file with the used command saved in it |
---|
145 | command = "" |
---|
146 | for arg in sys.argv: command = command + arg + ' ' |
---|
147 | #if typefile not in ["meso","mesoapi"]: name = 'pycommand' |
---|
148 | if opt.save is "gui": name = 'pycommand' |
---|
149 | f = open(name+'.sh', 'w') |
---|
150 | f.write(command) |
---|
151 | |
---|
152 | print "********** OPTIONS: ", opt |
---|
153 | print "********************************************************** END" |
---|