Changeset 380


Ignore:
Timestamp:
Nov 14, 2011, 1:20:02 PM (13 years ago)
Author:
aslmd
Message:

PYTHON: added an operation cat (especially aimed at time series with multiple files, working well with wrfout files. updated meso.py with last gcm.py changes. added a tip in help to use regular expressions in option -f.

Location:
trunk/UTIL/PYTHON
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/meso.py

    r377 r380  
    4444        vmaxtab = adjust_length (opt.vmax, zelen)
    4545
     46
     47    ################################
     48    ### General check
     49 
     50    if opt.fref is not None:
     51       if opt.operat is None:
     52          print "you must specify an operation when using a reference file"
     53          exit()
     54    if opt.operat in ["+","-"]:
     55       if opt.fref is None:
     56          print "you must specifiy a reference file when using inter-file operations"
     57          exit()
     58
     59    interpref=False
     60    if opt.fref is not None:
     61       if opt.operat is not None:
     62          if opt.itp is not None:
     63             interpref=True
     64
     65    ################################
     66
     67
    4668    print "file, length", opt.file, len(opt.file)
    4769
     
    5779    for i in range(len(opt.file)):
    5880
    59         zefile = opt.file[i]
    60         print zefile   
     81        zefiles = separatenames(opt.file[i])
     82        print "zefiles", zefiles
     83
     84        #zefile = opt.file[i]
     85        #print zefile   
     86        zefile = zefiles[0]
     87             
    6188        #zelevel = opt.lvl   
    6289        stralt = None
     
    99126        else:               zerange = range(zelen)
    100127
     128
     129
     130
     131
     132
     133
     134
     135        if interpref:
     136           interpolated_ref=""
     137           interpolated_ref=call_zrecast(interp_mode=opt.itp,\
     138                    input_name=[opt.fref],\
     139                    fields=zevars)
     140
     141           reffile=interpolated_ref[0]
     142        else:
     143           reffile=opt.fref
     144# Divers ####################################################
     145   
    101146        zexaxis=[opt.xmin,opt.xmax]
    102147        zeyaxis=[opt.ymin,opt.ymax]
     
    116161            #############
    117162            ### Main call
    118             name = planetoplot (zefile,level=int(zelevel),vertmode=opt.itp,\
     163            name = planetoplot (zefiles,level=int(zelevel),vertmode=opt.itp,\
    119164                proj=opt.proj,back=opt.back,target=opt.tgt,stride=opt.ste,var=argvar,\
    120165                numplot=opt.num,colorb=opt.clb,winds=opt.winds,\
     
    126171                slon=zeslon,slat=zeslat,svert=zesvert,stime=zestime,\
    127172                outputname=opt.out,resolution=opt.res,\
     173                ope=opt.operat,fileref=reffile,minop=opt.vminope,maxop=opt.vmaxope,titleref=opt.titref,\
    128174                invert_y=opt.inverty,xaxis=zexaxis,yaxis=zeyaxis,ylog=opt.logy)
    129175        print 'Done: '+name
  • trunk/UTIL/PYTHON/myscript.py

    r377 r380  
    22
    33    ### I/O
    4     parser.add_option('-f', '--file',   action='append',dest='file',     type="string",  default=None,  help='[NEEDED] filename (append). Comma-separated: same fig')
     4    parser.add_option('-f', '--file',   action='append',dest='file',     type="string",  default=None,  help='[NEEDED] filename. Append: different figures. Comma-separated: same figure (+ possible --operation). Regex tip: -f `echo foo* | sed s+" "+","+g`')
    55    parser.add_option('-t', '--target', action='store',dest='tgt',       type="string",  default=None,  help='destination folder')
    66    parser.add_option('-S', '--save',   action='store',dest='save',      type="string",  default="gui", help='save mode (png,eps,svg,pdf or gui) [gui]')
     
    5252
    5353    ### OPERATIONS BETWEEN FILES
    54     parser.add_option('--operation',    action='store',dest='operat',  type="string",  default=None,  help='operation to perform between input file (ifile) and reference file (rfile) specified through --fref. Available: "+","-". Done as: ifile +or- rfile.')
     54    parser.add_option('--operation',    action='store',dest='operat',  type="string",  default=None,  help='operation to perform on input files given through -f. "+" or "-" acts on each input file by adding or substracting the ref file specified through --fref. "cat" acts on all input files in-a-row.')
    5555    parser.add_option('--fref',         action='store',dest='fref',    type="string",  default=None,  help='reference namefile for the --operation option.')
    5656    parser.add_option('--mope',         action='store',dest='vminope', type="float",   default=0.,  help='bounding minimum value for inter-file operation')
  • trunk/UTIL/PYTHON/planetoplot.py

    r372 r380  
    161161         basename = getname(var=var,winds=winds,anomaly=anomaly)
    162162         basename = basename + getstralt(nc,level)  ## can be moved elsewhere for a more generic routine
    163      
     163
    164164      print "var, var2: ", var, var2
    165165      if var: all_var[k] = getfield(nc,var)
     
    173173
    174174    ##################################
    175     ### Load reference file if there is one
    176     if fileref is not None:
    177        ncref  = Dataset(fileref)
    178        ### ... VAR
     175    ### Operation on files
     176    if ope is not None:
    179177       if var not in nc.variables: var = False
    180178       if var:
    181              all_var[k] = getfield(ncref,var)
    182              if ope is "-":
    183                 all_var[k+1]= all_var[k-1] - all_var[k]
    184              elif ope is "+":
    185                 all_var[k+1]= all_var[k-1] + all_var[k]
     179             print ope
     180             if ope in ["-","+"]:
     181                if fileref is not None:   all_var[k] = getfield(Dataset(fileref),var)
     182                else:                     errormess("fileref is missing!")
     183                if ope == "-":     all_var[k+1]= all_var[k-1] - all_var[k]
     184                elif ope == "+":   all_var[k+1]= all_var[k-1] + all_var[k]
     185                numplot = numplot+2
     186             elif ope in ["cat"]:
     187                tab = all_var[0];k = 0
     188                while k != len(namefiles)-1:
     189                    tab = np.append(tab,all_var[k],axis=0)
     190                    k += 1
     191                time = np.arange(0,len(tab),1) ### AS: time reference is simple, should be better
     192                all_var[0] = np.array(tab);numplot = 1
    186193             elif ope is not None:
    187                 print "non-implemented operation. Available op. are + and -."
    188              numplot = numplot+2
     194                errormess(ope+" : non-implemented operation. Available op. are + and -.")
    189195
    190196    ##################################
     
    195201    #################################
    196202    ### Time loop for plotting device
    197     found_lct = False
    198     nplot = 1
    199     itime = first
    200     error = False
     203    found_lct = False;nplot = 1;itime = first;error = False
    201204    if itstep is None and numplot > 0: itstep = int(24./numplot)
    202205    elif numplot <= 0:                 itstep = 1
Note: See TracChangeset for help on using the changeset viewer.