[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 |
---|
[451] | 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 |
---|
[349] | 32 | |
---|
[392] | 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] |
---|
[349] | 38 | |
---|
[392] | 39 | ############################# |
---|
| 40 | ### 1. LOOP ON FILE LISTS TO BE PUT IN DIFFERENT FIGURES |
---|
| 41 | for i in range(len(opt.file)): |
---|
[349] | 42 | |
---|
[392] | 43 | zefiles = separatenames(opt.file[i]) |
---|
[380] | 44 | |
---|
[426] | 45 | typefile = whatkindfile(Dataset(zefiles[0])) ; stralt = None |
---|
[429] | 46 | if typefile in ["meso","mesoapi","mesoideal"]: |
---|
[392] | 47 | [lschar,zehour,zehourin] = getlschar ( zefiles[0] ) |
---|
[426] | 48 | if opt.var is None: opt.var = ["HGT"] ; opt.clb = "nobar" |
---|
[429] | 49 | elif typefile in ["geo"]: |
---|
[426] | 50 | [lschar,zehour,zehourin] = ["",0,0] |
---|
| 51 | if opt.var is None: opt.var = ["HGT_M"] ; opt.clb = "nobar" |
---|
[392] | 52 | else: |
---|
| 53 | [lschar,zehour,zehourin] = ["",0,0] |
---|
[426] | 54 | if opt.var is None: opt.var = ["phisinit"] ; opt.clb = "nobar" |
---|
[380] | 55 | |
---|
[392] | 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 |
---|
[380] | 61 | |
---|
[392] | 62 | ############################# |
---|
| 63 | ### 2. LOOP ON VAR LISTS TO BE PUT IN DIFFERENT FIGURES |
---|
| 64 | for j in range(len(opt.var)): |
---|
[380] | 65 | |
---|
[392] | 66 | zevars = separatenames(opt.var[j]) |
---|
[380] | 67 | |
---|
[377] | 68 | inputnvert = separatenames(opt.lvl) |
---|
[351] | 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 | |
---|
[392] | 76 | ######################################################### |
---|
| 77 | ### Call Fortran routines for vertical interpolations ### |
---|
| 78 | ######################################################### |
---|
[377] | 79 | if opt.itp is not None: |
---|
[392] | 80 | ##### |
---|
| 81 | ##### MESOSCALE : written by AS |
---|
| 82 | ##### |
---|
[429] | 83 | if typefile in ["meso","mesoideal"]: |
---|
[377] | 84 | if zelevel == 0. and opt.itp == 4: zelevel = 0.010 |
---|
[349] | 85 | ### winds or no winds |
---|
| 86 | if opt.winds : zefields = 'uvmet' |
---|
| 87 | else : zefields = '' |
---|
| 88 | ### var or no var |
---|
[392] | 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 |
---|
[349] | 104 | zelevel = 0 ## so that zelevel could play again the role of nvert |
---|
[392] | 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,\ |
---|
[409] | 112 | fields=zevars,\ |
---|
| 113 | predifined=opt.intas) |
---|
[349] | 114 | |
---|
[392] | 115 | zefiles=interpolated_files |
---|
| 116 | if interpref: |
---|
| 117 | interpolated_ref="" |
---|
| 118 | interpolated_ref=call_zrecast(interp_mode=opt.itp,\ |
---|
[380] | 119 | input_name=[opt.fref],\ |
---|
[409] | 120 | fields=zevars,\ |
---|
| 121 | predifined=opt.intas) |
---|
[380] | 122 | |
---|
[392] | 123 | reffile=interpolated_ref[0] |
---|
| 124 | else: |
---|
[429] | 125 | print "type not supported" |
---|
[392] | 126 | exit() |
---|
[377] | 127 | |
---|
[392] | 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,\ |
---|
[424] | 132 | colorb=opt.clb,winds=opt.winds,\ |
---|
[349] | 133 | addchar=lschar,interv=[zehour,zehourin],vmin=zevmin,vmax=zevmax,\ |
---|
| 134 | tile=opt.tile,zoom=opt.zoom,display=opt.display,\ |
---|
[424] | 135 | hole=opt.hole,save=opt.save,\ |
---|
| 136 | anomaly=opt.anomaly,var2=opt.var2,ndiv=opt.ndiv,\ |
---|
[349] | 137 | mult=opt.mult,zetitle=opt.zetitle,\ |
---|
[359] | 138 | slon=zeslon,slat=zeslat,svert=zesvert,stime=zestime,\ |
---|
[377] | 139 | outputname=opt.out,resolution=opt.res,\ |
---|
[380] | 140 | ope=opt.operat,fileref=reffile,minop=opt.vminope,maxop=opt.vmaxope,titleref=opt.titref,\ |
---|
[385] | 141 | invert_y=opt.inverty,xaxis=zexaxis,yaxis=zeyaxis,ylog=opt.logy,yintegral=opt.column,\ |
---|
[453] | 142 | blat=opt.blat,blon=opt.blon,tsat=opt.tsat,flagnolow=opt.nolow,\ |
---|
| 143 | mrate=opt.rate,mquality=opt.quality,trans=opt.trans) |
---|
[392] | 144 | print 'DONE: '+name |
---|
[349] | 145 | system("rm -f to_be_erased") |
---|
| 146 | |
---|
| 147 | ######################################################### |
---|
| 148 | ### Generate a .sh file with the used command saved in it |
---|
[392] | 149 | command = "" |
---|
[349] | 150 | for arg in sys.argv: command = command + arg + ' ' |
---|
[424] | 151 | #if typefile not in ["meso","mesoapi"]: name = 'pycommand' |
---|
[451] | 152 | if opt.save == "gui": name = 'pycommand' |
---|
| 153 | elif opt.save == "avi": system("mv -f movie*.avi "+name+".avi") |
---|
| 154 | 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) |
---|
[349] | 155 | f = open(name+'.sh', 'w') |
---|
| 156 | f.write(command) |
---|
[392] | 157 | |
---|
| 158 | print "********** OPTIONS: ", opt |
---|
| 159 | print "********************************************************** END" |
---|