[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 | |
---|
[392] | 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"] |
---|
[380] | 50 | |
---|
[392] | 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 |
---|
[380] | 56 | |
---|
[392] | 57 | ############################# |
---|
| 58 | ### 2. LOOP ON VAR LISTS TO BE PUT IN DIFFERENT FIGURES |
---|
| 59 | for j in range(len(opt.var)): |
---|
[380] | 60 | |
---|
[392] | 61 | zevars = separatenames(opt.var[j]) |
---|
[380] | 62 | |
---|
[377] | 63 | inputnvert = separatenames(opt.lvl) |
---|
[351] | 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 | |
---|
[392] | 71 | ######################################################### |
---|
| 72 | ### Call Fortran routines for vertical interpolations ### |
---|
| 73 | ######################################################### |
---|
[377] | 74 | if opt.itp is not None: |
---|
[392] | 75 | ##### |
---|
| 76 | ##### MESOSCALE : written by AS |
---|
| 77 | ##### |
---|
| 78 | if typefile == "meso": |
---|
[377] | 79 | if zelevel == 0. and opt.itp == 4: zelevel = 0.010 |
---|
[349] | 80 | ### winds or no winds |
---|
| 81 | if opt.winds : zefields = 'uvmet' |
---|
| 82 | else : zefields = '' |
---|
| 83 | ### var or no var |
---|
[392] | 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 |
---|
[349] | 99 | zelevel = 0 ## so that zelevel could play again the role of nvert |
---|
[392] | 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,\ |
---|
[409] | 107 | fields=zevars,\ |
---|
| 108 | predifined=opt.intas) |
---|
[349] | 109 | |
---|
[392] | 110 | zefiles=interpolated_files |
---|
| 111 | if interpref: |
---|
| 112 | interpolated_ref="" |
---|
| 113 | interpolated_ref=call_zrecast(interp_mode=opt.itp,\ |
---|
[380] | 114 | input_name=[opt.fref],\ |
---|
[409] | 115 | fields=zevars,\ |
---|
| 116 | predifined=opt.intas) |
---|
[380] | 117 | |
---|
[392] | 118 | reffile=interpolated_ref[0] |
---|
| 119 | else: |
---|
| 120 | print "not supported" |
---|
| 121 | exit() |
---|
[377] | 122 | |
---|
[392] | 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,\ |
---|
[424] | 127 | colorb=opt.clb,winds=opt.winds,\ |
---|
[349] | 128 | addchar=lschar,interv=[zehour,zehourin],vmin=zevmin,vmax=zevmax,\ |
---|
| 129 | tile=opt.tile,zoom=opt.zoom,display=opt.display,\ |
---|
[424] | 130 | hole=opt.hole,save=opt.save,\ |
---|
| 131 | anomaly=opt.anomaly,var2=opt.var2,ndiv=opt.ndiv,\ |
---|
[349] | 132 | mult=opt.mult,zetitle=opt.zetitle,\ |
---|
[359] | 133 | slon=zeslon,slat=zeslat,svert=zesvert,stime=zestime,\ |
---|
[377] | 134 | outputname=opt.out,resolution=opt.res,\ |
---|
[380] | 135 | ope=opt.operat,fileref=reffile,minop=opt.vminope,maxop=opt.vmaxope,titleref=opt.titref,\ |
---|
[385] | 136 | invert_y=opt.inverty,xaxis=zexaxis,yaxis=zeyaxis,ylog=opt.logy,yintegral=opt.column,\ |
---|
[419] | 137 | blat=opt.blat,tsat=opt.tsat,flagnolow=opt.nolow) |
---|
[392] | 138 | print 'DONE: '+name |
---|
[349] | 139 | system("rm -f to_be_erased") |
---|
| 140 | |
---|
| 141 | ######################################################### |
---|
| 142 | ### Generate a .sh file with the used command saved in it |
---|
[392] | 143 | command = "" |
---|
[349] | 144 | for arg in sys.argv: command = command + arg + ' ' |
---|
[424] | 145 | #if typefile not in ["meso","mesoapi"]: name = 'pycommand' |
---|
| 146 | if opt.save is "gui": name = 'pycommand' |
---|
[349] | 147 | f = open(name+'.sh', 'w') |
---|
| 148 | f.write(command) |
---|
[392] | 149 | |
---|
| 150 | print "********** OPTIONS: ", opt |
---|
| 151 | print "********************************************************** END" |
---|