source: trunk/UTIL/PYTHON/pp.py @ 570

Last change on this file since 570 was 569, checked in by acolaitis, 13 years ago

PYTHON
######

=========
myplot.py
=========

  • Added missing value handling for API files (+1e36)
  • Added check_localtime function that re-order the time axis in localtime mode

=========
planetoplot.py
=========

  • Corrected a problem when trying to plot a contour or unidim plot in localtime along a cyclic time axis (i.e. when the day was changing).

    one day is now numbered from 0 to 24 and the rest is either negative (below 0) or greater than 24.

  • Localtimes are no longer integers, which was causing problems when using files with more than 1 localtime per hour.
  • Corrected a very wierd bug where the asked value for --lon and --lat was changing when plotting along different files. This was due to a spooky pointer problem where the value of a variable was changing when an other one was changed !!!
  • Corrected a bug with localtimes where there was a drift in initial localtimes when using different files and when not using the --operation cat option.
  • Added the possibility to ask for the variable 'UV' (or 'uv' or 'uvmet' if using API) which will automatically compute the norm of horizontal winds 'U' and 'V' (or 'u' and 'v' or 'Um' and 'Vm' if using API). This also work when using reference file. This will only compute the norm if no variable with this name already exists in the file.
  • Added the possibility to call overcontours in plot with a reference file (--fref option) using the usual -w ... syntax. The overcontour will also be displayed on the "operation" plot, without being processed.
  • Added the possibility of specifying manually labels for unidim curves (see below)

=========
myscript.py
=========

  • New option --labels "label 1","label 2",......,"label N" will label in this order each curve of a multi-file unidim plot, with "label N" corresponding to file N.

=========
pp.py
=========

  • Added calls to API for reference file when using --fref so that the reference file is also processed.
  • Property svn:executable set to *
File size: 9.0 KB
Line 
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)
8if __name__ == "__main__":
9    import sys
10    from optparse import OptionParser    ### to be replaced by argparse
11    from api_wrapper import api_onelevel
12    from gcm_transformations 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 glob
19    import numpy as np
20
21
22    #############################
23    ### Get options and variables
24    parser = OptionParser() ; getparseroptions(parser) ; (opt,args) = parser.parse_args()
25    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")
26    if opt.var is None and opt.anomaly is True:         errormess("Cannot ask to compute anomaly if no variable is set")
27    if opt.fref is not None and opt.operat is None:     errormess("you must specify an operation when using a reference file")
28    if opt.operat in ["+","-"] and opt.fref is None:    errormess("you must specifiy a reference file when using inter-file operations")
29    if opt.fref is not None and opt.operat is not None and opt.itp is not None: interpref=True
30    else:   interpref=False
31    if opt.rate is not None:      opt.save = "avi"
32    elif opt.save == "avi":       opt.rate = 8   ## this is a default value for -S avi
33    if opt.save == "html":        opt.rate = -1  ## this is convenient because everything is done in planetoplot with mrate
34
35    #############################
36    ### Get infos about slices
37    zeslat  = readslices(opt.slat) ; zeslon  = readslices(opt.slon) ; zesvert = readslices(opt.svert) ; zestime = readslices(opt.stime)
38    reffile = opt.fref
39    zexaxis = [opt.xmin,opt.xmax] ; zeyaxis=[opt.ymin,opt.ymax]
40
41    #############################
42    ### Catch multiple files
43    if "*" in opt.file[0] or "?" in opt.file[0]: 
44        yeah = glob.glob(opt.file[0]) ; yeah.sort()
45        opt.file[0] = yeah[0] 
46        for file in yeah[1:]: opt.file[0] = opt.file[0] + "," + file
47
48    #############################
49    ### 1. LOOP ON FILE LISTS TO BE PUT IN DIFFERENT FIGURES
50    for i in range(len(opt.file)):
51
52      zefiles = separatenames(opt.file[i])
53
54      typefile = whatkindfile(Dataset(zefiles[0])) ; stralt = None
55      if typefile in ["meso"]:         
56          [lschar,zehour,zehourin] = getlschar ( zefiles[0] )
57          if opt.var is None:  opt.var = ["HGT"] ; opt.clb = "nobar"
58      elif typefile in ["geo"]:
59          [lschar,zehour,zehourin] = ["",0,0]
60          if opt.var is None:  opt.var = ["HGT_M"] ; opt.clb = "nobar"
61      else:                                       
62          [lschar,zehour,zehourin] = ["",0,0]
63          if opt.var is None:  opt.var = ["phisinit"] ; opt.clb = "nobar"
64
65      if opt.vmin is not None : zevmin  = opt.vmin[min(i,len(opt.vmin)-1)]
66      else:                     zevmin = None
67      if opt.vmax is not None : zevmax  = opt.vmax[min(i,len(opt.vmax)-1)]
68      else:                     zevmax = None
69      #print "vmin, zevmin", opt.vmin, zevmin ; print "vmax, zevmax", opt.vmax, zevmax
70
71      #############################
72      ### 2. LOOP ON VAR LISTS TO BE PUT IN DIFFERENT FIGURES
73      for j in range(len(opt.var)):
74
75        zevars = separatenames(opt.var[j])
76
77        inputnvert = separatenames(opt.lvl)
78        if np.array(inputnvert).size == 1:
79            zelevel = float(inputnvert[0])
80            ze_interp_levels = [-9999.]
81        elif np.array(inputnvert).size == 2:
82            zelevel = -99.
83            ze_interp_levels = np.linspace(float(inputnvert[0]),float(inputnvert[1]),20)
84        else:
85            zelevel = -99.
86            ze_interp_levels = np.linspace(float(inputnvert[0]),float(inputnvert[1]),float(inputnvert[2]))
87
88        #########################################################
89        if opt.itp is not None:
90         if opt.itp > 0:
91          #####
92          ##### MESOSCALE : written by AS
93          #####
94          if typefile in ["meso"]:
95            if zelevel == 0. and opt.itp == 4:  zelevel = 0.010
96            ### winds or no winds
97            if opt.winds            :  zefields = 'uvmet'
98            else                    :  zefields = ''
99            ### var or no var
100            if zefields == ''       :  zefields = opt.var[j] 
101            else                    :  zefields = zefields + "," + opt.var[j]
102            if opt.var2 is not None :  zefields = zefields + "," + opt.var2 
103            ### call fortran routines
104            for fff in range(len(zefiles)):
105                newname = api_onelevel (  path_to_input   = '', \
106                                               input_name      = zefiles[fff], \
107                                               fields          = zefields, \
108                                               interp_method   = opt.itp, \
109                                               interp_level    = ze_interp_levels, \
110                                               onelevel        = zelevel, \
111                                               nocall          = opt.nocall )
112                if fff == 0: zetab = newname
113                else:        zetab = np.append(zetab,newname)
114            if interpref:
115                reffile = api_onelevel (  path_to_input   = '', \
116                                               input_name      = opt.fref, \
117                                               fields          = zefields, \
118                                               interp_method   = opt.itp, \
119                                               interp_level    = ze_interp_levels, \
120                                               onelevel        = zelevel, \
121                                               nocall          = opt.nocall )
122            zefiles = zetab #; print zefiles
123            zelevel = 0 ## so that zelevel could play again the role of nvert
124          #####
125          ##### GCM : written by AC
126          #####
127          elif typefile == "gcm":
128            inputvar = zevars
129            if opt.var2 is not None : inputvar = np.append(inputvar,opt.var2)
130            interpolated_files=""
131            interpolated_files=call_zrecast(interp_mode=opt.itp,\
132                    input_name=zefiles,\
133                    fields=inputvar,\
134                    limites = ze_interp_levels,\
135                    predefined=opt.intas)
136
137            zefiles=interpolated_files
138            if interpref:
139               interpolated_ref=""
140               interpolated_ref=call_zrecast(interp_mode=opt.itp,\
141                    input_name=[opt.fref],\
142                    fields=zevars,\
143                    predefined=opt.intas)
144
145               reffile=interpolated_ref[0]
146          else:
147            print "type not supported"
148            exit()
149
150        #############
151        ### Main call
152        name = planetoplot (zefiles,level=int(zelevel),vertmode=opt.itp,\
153                proj=opt.proj,back=opt.back,target=opt.tgt,stride=opt.ste,var=zevars,\
154                colorb=opt.clb,winds=opt.winds,\
155                addchar=lschar,interv=[zehour,zehourin],vmin=zevmin,vmax=zevmax,\
156                tile=opt.tile,zoom=opt.zoom,display=opt.display,\
157                hole=opt.hole,save=opt.save,\
158                anomaly=opt.anomaly,var2=opt.var2,ndiv=opt.ndiv,\
159                mult=opt.mult,zetitle=opt.zetitle,\
160                slon=zeslon,slat=zeslat,svert=zesvert,stime=zestime,\
161                outputname=opt.out,resolution=opt.res,\
162                ope=opt.operat,fileref=reffile,minop=opt.vminope,maxop=opt.vmaxope,titleref=opt.titref,\
163                invert_y=opt.inverty,xaxis=zexaxis,yaxis=zeyaxis,ylog=opt.logy,yintegral=opt.column,\
164                blat=opt.blat,blon=opt.blon,tsat=opt.tsat,flagnolow=opt.nolow,\
165                mrate=opt.rate,mquality=opt.quality,trans=opt.trans,zarea=opt.area,axtime=opt.axtime,\
166                redope=opt.redope,seevar=opt.seevar,xlab=opt.xlab,ylab=opt.ylab,lbls=separatenames(opt.labels))
167        print 'DONE: '+name
168        system("rm -f to_be_erased")
169 
170    #########################################################
171    ### Generate a .sh file with the used command saved in it
172    command = "" 
173    for arg in sys.argv: command = command + arg + ' '
174    #if typefile not in ["meso","mesoapi"]: name = 'pycommand'
175    if opt.save == "gui":    name = 'pycommand'
176    elif opt.save == "avi":  system("mv -f movie*.avi "+name+".avi")
177    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) 
178    f = open(name+'.sh', 'w')
179    f.write(command)
180
181    #print "********** OPTIONS: ", opt
182    print "********************************************************** END"
Note: See TracBrowser for help on using the repository browser.