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