[349] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
[392] | 3 | ### A. Spiga + T. Navarro + A. Colaitis |
---|
[349] | 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 |
---|
[392] | 12 | from zrecast_wrapper import call_zrecast |
---|
[349] | 13 | from netCDF4 import Dataset |
---|
[392] | 14 | from myplot import getlschar, separatenames, readslices, adjust_length, whatkindfile, errormess |
---|
[349] | 15 | from os import system |
---|
| 16 | from planetoplot import planetoplot |
---|
[377] | 17 | from myscript import getparseroptions |
---|
[349] | 18 | import numpy as np |
---|
| 19 | |
---|
| 20 | ############################# |
---|
| 21 | ### Get options and variables |
---|
[392] | 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 |
---|
[349] | 29 | |
---|
[392] | 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] |
---|
[349] | 35 | |
---|
[392] | 36 | ############################# |
---|
| 37 | ### 1. LOOP ON FILE LISTS TO BE PUT IN DIFFERENT FIGURES |
---|
| 38 | for i in range(len(opt.file)): |
---|
[349] | 39 | |
---|
[392] | 40 | zefiles = separatenames(opt.file[i]) |
---|
[380] | 41 | |
---|
[426] | 42 | typefile = whatkindfile(Dataset(zefiles[0])) ; stralt = None |
---|
[429] | 43 | if typefile in ["meso","mesoapi","mesoideal"]: |
---|
[392] | 44 | [lschar,zehour,zehourin] = getlschar ( zefiles[0] ) |
---|
[426] | 45 | if opt.var is None: opt.var = ["HGT"] ; opt.clb = "nobar" |
---|
[429] | 46 | elif typefile in ["geo"]: |
---|
[426] | 47 | [lschar,zehour,zehourin] = ["",0,0] |
---|
| 48 | if opt.var is None: opt.var = ["HGT_M"] ; opt.clb = "nobar" |
---|
[392] | 49 | else: |
---|
| 50 | [lschar,zehour,zehourin] = ["",0,0] |
---|
[426] | 51 | if opt.var is None: opt.var = ["phisinit"] ; opt.clb = "nobar" |
---|
[380] | 52 | |
---|
[392] | 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 |
---|
[380] | 58 | |
---|
[392] | 59 | ############################# |
---|
| 60 | ### 2. LOOP ON VAR LISTS TO BE PUT IN DIFFERENT FIGURES |
---|
| 61 | for j in range(len(opt.var)): |
---|
[380] | 62 | |
---|
[392] | 63 | zevars = separatenames(opt.var[j]) |
---|
[380] | 64 | |
---|
[377] | 65 | inputnvert = separatenames(opt.lvl) |
---|
[351] | 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 | |
---|
[392] | 73 | ######################################################### |
---|
| 74 | ### Call Fortran routines for vertical interpolations ### |
---|
| 75 | ######################################################### |
---|
[377] | 76 | if opt.itp is not None: |
---|
[392] | 77 | ##### |
---|
| 78 | ##### MESOSCALE : written by AS |
---|
| 79 | ##### |
---|
[429] | 80 | if typefile in ["meso","mesoideal"]: |
---|
[377] | 81 | if zelevel == 0. and opt.itp == 4: zelevel = 0.010 |
---|
[349] | 82 | ### winds or no winds |
---|
| 83 | if opt.winds : zefields = 'uvmet' |
---|
| 84 | else : zefields = '' |
---|
| 85 | ### var or no var |
---|
[392] | 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 |
---|
[349] | 101 | zelevel = 0 ## so that zelevel could play again the role of nvert |
---|
[392] | 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,\ |
---|
[409] | 109 | fields=zevars,\ |
---|
| 110 | predifined=opt.intas) |
---|
[349] | 111 | |
---|
[392] | 112 | zefiles=interpolated_files |
---|
| 113 | if interpref: |
---|
| 114 | interpolated_ref="" |
---|
| 115 | interpolated_ref=call_zrecast(interp_mode=opt.itp,\ |
---|
[380] | 116 | input_name=[opt.fref],\ |
---|
[409] | 117 | fields=zevars,\ |
---|
| 118 | predifined=opt.intas) |
---|
[380] | 119 | |
---|
[392] | 120 | reffile=interpolated_ref[0] |
---|
| 121 | else: |
---|
[429] | 122 | print "type not supported" |
---|
[392] | 123 | exit() |
---|
[377] | 124 | |
---|
[392] | 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,\ |
---|
[424] | 129 | colorb=opt.clb,winds=opt.winds,\ |
---|
[349] | 130 | addchar=lschar,interv=[zehour,zehourin],vmin=zevmin,vmax=zevmax,\ |
---|
| 131 | tile=opt.tile,zoom=opt.zoom,display=opt.display,\ |
---|
[424] | 132 | hole=opt.hole,save=opt.save,\ |
---|
| 133 | anomaly=opt.anomaly,var2=opt.var2,ndiv=opt.ndiv,\ |
---|
[349] | 134 | mult=opt.mult,zetitle=opt.zetitle,\ |
---|
[359] | 135 | slon=zeslon,slat=zeslat,svert=zesvert,stime=zestime,\ |
---|
[377] | 136 | outputname=opt.out,resolution=opt.res,\ |
---|
[380] | 137 | ope=opt.operat,fileref=reffile,minop=opt.vminope,maxop=opt.vmaxope,titleref=opt.titref,\ |
---|
[385] | 138 | invert_y=opt.inverty,xaxis=zexaxis,yaxis=zeyaxis,ylog=opt.logy,yintegral=opt.column,\ |
---|
[432] | 139 | blat=opt.blat,tsat=opt.tsat,flagnolow=opt.nolow,mrate=opt.rate) |
---|
[392] | 140 | print 'DONE: '+name |
---|
[349] | 141 | system("rm -f to_be_erased") |
---|
| 142 | |
---|
| 143 | ######################################################### |
---|
| 144 | ### Generate a .sh file with the used command saved in it |
---|
[392] | 145 | command = "" |
---|
[349] | 146 | for arg in sys.argv: command = command + arg + ' ' |
---|
[424] | 147 | #if typefile not in ["meso","mesoapi"]: name = 'pycommand' |
---|
| 148 | if opt.save is "gui": name = 'pycommand' |
---|
[349] | 149 | f = open(name+'.sh', 'w') |
---|
| 150 | f.write(command) |
---|
[392] | 151 | |
---|
| 152 | print "********** OPTIONS: ", opt |
---|
| 153 | print "********************************************************** END" |
---|