[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 |
---|
[876] | 10 | import myplot |
---|
| 11 | import os |
---|
| 12 | import numpy as np |
---|
| 13 | import netCDF4 |
---|
| 14 | import glob |
---|
| 15 | |
---|
[349] | 16 | from optparse import OptionParser ### to be replaced by argparse |
---|
| 17 | from api_wrapper import api_onelevel |
---|
[464] | 18 | from gcm_transformations import call_zrecast |
---|
[349] | 19 | from planetoplot import planetoplot |
---|
[377] | 20 | from myscript import getparseroptions |
---|
[349] | 21 | |
---|
[478] | 22 | |
---|
[349] | 23 | ############################# |
---|
| 24 | ### Get options and variables |
---|
[392] | 25 | parser = OptionParser() ; getparseroptions(parser) ; (opt,args) = parser.parse_args() |
---|
[876] | 26 | if opt.file is None: myplot.errormess("I want to eat one file at least ! Use pp.py -f name_of_my_file. Or type pp.py -h") |
---|
| 27 | if opt.var is None and opt.anomaly is True: myplot.errormess("Cannot ask to compute anomaly if no variable is set") |
---|
| 28 | if opt.fref is not None and opt.operat is None: myplot.errormess("you must specify an operation when using a reference file") |
---|
| 29 | if opt.operat in ["+","-"] and opt.fref is None: myplot.errormess("you must specifiy a reference file when using inter-file operations") |
---|
[392] | 30 | if opt.fref is not None and opt.operat is not None and opt.itp is not None: interpref=True |
---|
| 31 | else: interpref=False |
---|
[451] | 32 | if opt.rate is not None: opt.save = "avi" |
---|
| 33 | elif opt.save == "avi": opt.rate = 8 ## this is a default value for -S avi |
---|
| 34 | if opt.save == "html": opt.rate = -1 ## this is convenient because everything is done in planetoplot with mrate |
---|
[349] | 35 | |
---|
[392] | 36 | ############################# |
---|
| 37 | ### Get infos about slices |
---|
[876] | 38 | zeslat = myplot.readslices(opt.slat) ; zeslon = myplot.readslices(opt.slon) ; zesvert = myplot.readslices(opt.svert) ; zestime = myplot.readslices(opt.stime) |
---|
[818] | 39 | |
---|
[392] | 40 | reffile = opt.fref |
---|
| 41 | zexaxis = [opt.xmin,opt.xmax] ; zeyaxis=[opt.ymin,opt.ymax] |
---|
[349] | 42 | |
---|
[392] | 43 | ############################# |
---|
[478] | 44 | ### Catch multiple files |
---|
[479] | 45 | if "*" in opt.file[0] or "?" in opt.file[0]: |
---|
| 46 | yeah = glob.glob(opt.file[0]) ; yeah.sort() |
---|
| 47 | opt.file[0] = yeah[0] |
---|
[489] | 48 | for file in yeah[1:]: opt.file[0] = opt.file[0] + "," + file |
---|
[478] | 49 | |
---|
| 50 | ############################# |
---|
[392] | 51 | ### 1. LOOP ON FILE LISTS TO BE PUT IN DIFFERENT FIGURES |
---|
| 52 | for i in range(len(opt.file)): |
---|
[349] | 53 | |
---|
[876] | 54 | zefiles = myplot.separatenames(opt.file[i]) |
---|
[380] | 55 | |
---|
[876] | 56 | typefile = myplot.whatkindfile(netCDF4.Dataset(zefiles[0])) ; stralt = None |
---|
[562] | 57 | if typefile in ["meso"]: |
---|
[876] | 58 | [lschar,zehour,zehourin] = myplot.getlschar ( zefiles[0] ) |
---|
[818] | 59 | if opt.var is None: opt.var = ["HGT"] ; opt.nocolorb = True |
---|
[429] | 60 | elif typefile in ["geo"]: |
---|
[763] | 61 | lschar="" |
---|
[818] | 62 | if opt.var is None: opt.var = ["HGT_M"] ; opt.nocolorb = True |
---|
[763] | 63 | else: |
---|
| 64 | lschar="" |
---|
[721] | 65 | if opt.var is None: |
---|
| 66 | opt.var = ["phisinit"] ; opt.clb = "nobar" |
---|
| 67 | ### temporaire... en attendant mieux. |
---|
[818] | 68 | if opt.back == "titan": opt.var = ["phis"] ; opt.nocolorb = True |
---|
[380] | 69 | |
---|
[392] | 70 | if opt.vmin is not None : zevmin = opt.vmin[min(i,len(opt.vmin)-1)] |
---|
| 71 | else: zevmin = None |
---|
| 72 | if opt.vmax is not None : zevmax = opt.vmax[min(i,len(opt.vmax)-1)] |
---|
| 73 | else: zevmax = None |
---|
| 74 | #print "vmin, zevmin", opt.vmin, zevmin ; print "vmax, zevmax", opt.vmax, zevmax |
---|
[380] | 75 | |
---|
[392] | 76 | ############################# |
---|
| 77 | ### 2. LOOP ON VAR LISTS TO BE PUT IN DIFFERENT FIGURES |
---|
| 78 | for j in range(len(opt.var)): |
---|
[380] | 79 | |
---|
[876] | 80 | zevars = myplot.separatenames(opt.var[j]) |
---|
[380] | 81 | |
---|
[876] | 82 | inputnvert = myplot.separatenames(opt.lvl) |
---|
[351] | 83 | if np.array(inputnvert).size == 1: |
---|
| 84 | zelevel = float(inputnvert[0]) |
---|
| 85 | ze_interp_levels = [-9999.] |
---|
[610] | 86 | elif np.array(inputnvert).size > 2: |
---|
[489] | 87 | zelevel = -99. |
---|
[610] | 88 | start = float(inputnvert[0]) |
---|
| 89 | stop = float(inputnvert[1]) |
---|
| 90 | if np.array(inputnvert).size == 2: numsample = 20 |
---|
| 91 | else: numsample = float(inputnvert[2]) |
---|
| 92 | if stop > start: |
---|
| 93 | ## altitude coordinates |
---|
| 94 | ze_interp_levels = np.linspace(start,stop,numsample) |
---|
| 95 | else: |
---|
| 96 | ## pressure coordinates |
---|
| 97 | ze_interp_levels = np.logspace(np.log10(start),np.log10(stop),numsample) |
---|
[351] | 98 | |
---|
[392] | 99 | ######################################################### |
---|
[377] | 100 | if opt.itp is not None: |
---|
[562] | 101 | if opt.itp > 0: |
---|
[392] | 102 | ##### |
---|
| 103 | ##### MESOSCALE : written by AS |
---|
| 104 | ##### |
---|
[562] | 105 | if typefile in ["meso"]: |
---|
[377] | 106 | if zelevel == 0. and opt.itp == 4: zelevel = 0.010 |
---|
[876] | 107 | if np.array(inputnvert).size == 1: zesvert = myplot.readslices([str(zelevel)]) |
---|
[349] | 108 | ### winds or no winds |
---|
| 109 | if opt.winds : zefields = 'uvmet' |
---|
[612] | 110 | elif opt.var[j] in ['deltat','DELTAT'] : zefields = 'tk,TSURF' |
---|
[763] | 111 | elif opt.var[j] in ['uv','UV','hodograph','hodograph_2'] : zefields = 'U,V' |
---|
[349] | 112 | else : zefields = '' |
---|
| 113 | ### var or no var |
---|
[392] | 114 | if zefields == '' : zefields = opt.var[j] |
---|
| 115 | else : zefields = zefields + "," + opt.var[j] |
---|
| 116 | if opt.var2 is not None : zefields = zefields + "," + opt.var2 |
---|
| 117 | ### call fortran routines |
---|
| 118 | for fff in range(len(zefiles)): |
---|
| 119 | newname = api_onelevel ( path_to_input = '', \ |
---|
| 120 | input_name = zefiles[fff], \ |
---|
| 121 | fields = zefields, \ |
---|
| 122 | interp_method = opt.itp, \ |
---|
| 123 | interp_level = ze_interp_levels, \ |
---|
| 124 | onelevel = zelevel, \ |
---|
| 125 | nocall = opt.nocall ) |
---|
| 126 | if fff == 0: zetab = newname |
---|
| 127 | else: zetab = np.append(zetab,newname) |
---|
[569] | 128 | if interpref: |
---|
| 129 | reffile = api_onelevel ( path_to_input = '', \ |
---|
| 130 | input_name = opt.fref, \ |
---|
| 131 | fields = zefields, \ |
---|
| 132 | interp_method = opt.itp, \ |
---|
| 133 | interp_level = ze_interp_levels, \ |
---|
| 134 | onelevel = zelevel, \ |
---|
| 135 | nocall = opt.nocall ) |
---|
[392] | 136 | zefiles = zetab #; print zefiles |
---|
[349] | 137 | zelevel = 0 ## so that zelevel could play again the role of nvert |
---|
[392] | 138 | ##### |
---|
| 139 | ##### GCM : written by AC |
---|
| 140 | ##### |
---|
| 141 | elif typefile == "gcm": |
---|
[475] | 142 | inputvar = zevars |
---|
| 143 | if opt.var2 is not None : inputvar = np.append(inputvar,opt.var2) |
---|
[392] | 144 | interpolated_files="" |
---|
| 145 | interpolated_files=call_zrecast(interp_mode=opt.itp,\ |
---|
| 146 | input_name=zefiles,\ |
---|
[475] | 147 | fields=inputvar,\ |
---|
[489] | 148 | limites = ze_interp_levels,\ |
---|
[464] | 149 | predefined=opt.intas) |
---|
[349] | 150 | |
---|
[392] | 151 | zefiles=interpolated_files |
---|
| 152 | if interpref: |
---|
| 153 | interpolated_ref="" |
---|
| 154 | interpolated_ref=call_zrecast(interp_mode=opt.itp,\ |
---|
[380] | 155 | input_name=[opt.fref],\ |
---|
[409] | 156 | fields=zevars,\ |
---|
[464] | 157 | predefined=opt.intas) |
---|
[380] | 158 | |
---|
[392] | 159 | reffile=interpolated_ref[0] |
---|
| 160 | else: |
---|
[429] | 161 | print "type not supported" |
---|
[392] | 162 | exit() |
---|
[377] | 163 | |
---|
[392] | 164 | ############# |
---|
| 165 | ### Main call |
---|
| 166 | name = planetoplot (zefiles,level=int(zelevel),vertmode=opt.itp,\ |
---|
| 167 | proj=opt.proj,back=opt.back,target=opt.tgt,stride=opt.ste,var=zevars,\ |
---|
[876] | 168 | clb=myplot.separatenames(opt.clb),winds=opt.winds,\ |
---|
[763] | 169 | addchar=lschar,vmin=zevmin,vmax=zevmax,\ |
---|
[349] | 170 | tile=opt.tile,zoom=opt.zoom,display=opt.display,\ |
---|
[424] | 171 | hole=opt.hole,save=opt.save,\ |
---|
| 172 | anomaly=opt.anomaly,var2=opt.var2,ndiv=opt.ndiv,\ |
---|
[876] | 173 | mult=opt.mult,add=opt.add,zetitle=myplot.separatenames(opt.zetitle),\ |
---|
[359] | 174 | slon=zeslon,slat=zeslat,svert=zesvert,stime=zestime,\ |
---|
[377] | 175 | outputname=opt.out,resolution=opt.res,\ |
---|
[380] | 176 | ope=opt.operat,fileref=reffile,minop=opt.vminope,maxop=opt.vmaxope,titleref=opt.titref,\ |
---|
[763] | 177 | invert_y=opt.inverty,xaxis=zexaxis,yaxis=zeyaxis,ylog=opt.logy,xlog=opt.logx,yintegral=opt.column,\ |
---|
[453] | 178 | blat=opt.blat,blon=opt.blon,tsat=opt.tsat,flagnolow=opt.nolow,\ |
---|
[483] | 179 | mrate=opt.rate,mquality=opt.quality,trans=opt.trans,zarea=opt.area,axtime=opt.axtime,\ |
---|
[876] | 180 | redope=opt.redope,seevar=opt.seevar,xlab=opt.xlab,ylab=opt.ylab,lbls=myplot.separatenames(opt.labels),\ |
---|
| 181 | lstyle=myplot.separatenames(opt.linestyle),cross=myplot.readslices(opt.mark),markdevil=opt.mdevil,facwind=opt.facwind,\ |
---|
| 182 | trycol=opt.trycol,streamflag=opt.stream,nocolorb=opt.nocolorb,analysis=opt.analysis,monster=opt.monster) |
---|
[392] | 183 | print 'DONE: '+name |
---|
[876] | 184 | os.system("rm -f to_be_erased") |
---|
[349] | 185 | |
---|
| 186 | ######################################################### |
---|
| 187 | ### Generate a .sh file with the used command saved in it |
---|
[392] | 188 | command = "" |
---|
[349] | 189 | for arg in sys.argv: command = command + arg + ' ' |
---|
[424] | 190 | #if typefile not in ["meso","mesoapi"]: name = 'pycommand' |
---|
[451] | 191 | if opt.save == "gui": name = 'pycommand' |
---|
[876] | 192 | elif opt.save == "html": os.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] | 193 | f = open(name+'.sh', 'w') |
---|
| 194 | f.write(command) |
---|
[392] | 195 | |
---|
[468] | 196 | #print "********** OPTIONS: ", opt |
---|
[392] | 197 | print "********************************************************** END" |
---|