Changeset 422


Ignore:
Timestamp:
Nov 24, 2011, 6:49:00 PM (13 years ago)
Author:
aslmd
Message:

GRAPHICS: operations were broken by introducing all_time, fixed. also added operations on two variables through keywords add_var sub_var mul_var div_var. can work on more variables but since this could be cumbersome I just left an exit message when more than two variables are asked.

Location:
trunk/UTIL/PYTHON
Files:
3 edited

Legend:

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

    r418 r422  
    7373    import numpy as np
    7474    from mymath import max,mean
    75     csmooth = 12 ## a fair amount of grid points
     75    csmooth = 12 ## a fair amount of grid points (too high results in high computation time)
    7676    dimension = np.array(input).ndim
    7777    shape = np.array(input).shape
  • trunk/UTIL/PYTHON/myscript.py

    r418 r422  
    5656
    5757    ### OPERATIONS BETWEEN FILES
    58     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.')
     58    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. "add_var" "sub_var" "mul_var" "div_var" acts on two variables.')
    5959    parser.add_option('--fref',         action='store',dest='fref',    type="string",  default=None,  help='reference namefile for the --operation option.')
    6060    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

    r419 r422  
    8181    if not isinstance(namefiles, np.ndarray): namefiles = [namefiles]
    8282    if not isinstance(var, np.ndarray):       var = [var]
    83     if ope is not None and len(var) > 1:      errormess("you are using an operation... please set only one var !")
    8483
    8584    ################################
     
    9796    print "********** FILES, SLICES, VARS, TOTAL PLOTS: ", len(namefiles), nslices, len(var), numplot
    9897    print "********** MAPMODE: ", mapmode
    99     if fileref is not None:       all_var  = [[]]*(zelen+2) ;  all_varname = [[]]*(zelen+2)  ;  all_namefile = [[]]*(zelen+2) ; all_time = [[]]*(zelen+2)
    100     else:                         all_var  = [[]]*zelen     ;  all_var2  = [[]]*zelen ;  all_title = [[]]*zelen ;  all_varname = [[]]*zelen ; all_namefile = [[]]*zelen ; all_time = [[]]*zelen
     98    if fileref is not None:       zelen = zelen + 2
     99    elif "var" in ope:            zelen = zelen + 1
     100    all_var  = [[]]*zelen ; all_var2  = [[]]*zelen ; all_title = [[]]*zelen ; all_varname = [[]]*zelen ; all_namefile = [[]]*zelen ; all_time = [[]]*zelen
    101101 
    102102    #################################################################################################
     
    194194    ##################################
    195195    ### Operation on files
    196     ### ... for the moment only OK when 1 var only
    197196    if ope is not None:
    198              print ope
     197        print ope
     198        if "var" not in ope:
     199             if len(var) > 1: errormess("for this operation... please set only one var !")
    199200             if ope in ["-","+"]:
    200                 if fileref is not None:   all_var[k] = getfield(Dataset(fileref),all_varname[k-1]) ; all_varname[k] = all_varname[k-1]
     201                if fileref is not None:   all_var[k] = getfield(Dataset(fileref),all_varname[k-1]) ; all_varname[k] = all_varname[k-1] ; all_time[k] = all_time[k-1] ; all_namefile[k] = all_namefile[k-1]
    201202                else:                     errormess("fileref is missing!")
    202203                if ope == "-":     all_var[k+1]= all_var[k-1] - all_var[k]
    203204                elif ope == "+":   all_var[k+1]= all_var[k-1] + all_var[k]
    204                 all_varname[k+1] = all_varname[k] ; numplot = numplot+2
     205                all_varname[k+1] = all_varname[k] ; all_time[k+1] = all_time[k] ; all_namefile[k+1] = all_namefile[k] ; numplot = numplot+2
    205206             elif ope in ["cat"]:
    206207                tab = all_var[0];k = 1
    207208                while k != len(namefiles)-1:
    208209                    tab = np.append(tab,all_var[k],axis=0) ; k += 1
    209                 time = np.arange(0,len(tab),1) ### AS: time reference is too simplistic, should be better
     210                all_time[0] = np.arange(0,len(tab),1) ### AS: time reference is too simplistic, should be better
    210211                all_var[0] = np.array(tab) ; numplot = 1
    211              elif ope is not None:
    212                 errormess(ope+" : non-implemented operation. Available op. are + and -.")
     212             else: errormess(ope+" : non-implemented operation. Check pp.py --help")
     213        else:
     214             if len(namefiles) > 1: errormess("for this operation... please set only one file !") 
     215             if len(var) > 2:       errormess("not sure this works for more than 2 vars... please check.")
     216             if   ope in ["div_var"]: all_var[k] = all_var[k-2] / all_var[k-1] ; insert = '_div_'
     217             elif ope in ["mul_var"]: all_var[k] = all_var[k-2] * all_var[k-1] ; insert = '_mul_'
     218             elif ope in ["add_var"]: all_var[k] = all_var[k-2] + all_var[k-1] ; insert = '_add_'
     219             elif ope in ["sub_var"]: all_var[k] = all_var[k-2] - all_var[k-1] ; insert = '_sub_'
     220             else:                    errormess(ope+" : non-implemented operation. Check pp.py --help")
     221             numplot = numplot + 1 ; all_time[k] = all_time[k-1] ; all_namefile[k] = all_namefile[k-1]
     222             all_varname[k] = all_varname[k-2] + insert + all_varname[k-1]
    213223
    214224    ##################################
     
    225235    while error is False:
    226236       print "********** nplot", nplot, "itime",itime,"error",error
    227        
    228 #       time = all_time[index_f]
    229 
     237     
    230238       ### Which local time ?
    231239       ltst = localtime ( interv[0]+itime*interv[1], 0.5*(wlon[0]+wlon[1]) )
     
    258266       indexvert = getsindex(svert,((nplot-1)//(nlon*nlat))%nvert,vert)
    259267
    260        if fileref is not None:      index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%(len(namefiles)+2)  ## OK only 1 var, see test in the beginning
     268       if fileref is not None:      index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%(len(namefiles)+2)  ## OK only 1 var,  see test in the beginning
     269       elif "var" in ope:           index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%(len(var)+1)        ## OK only 1 file, see test in the beginning
    261270       else:                        yeah = len(namefiles)*len(var) ; index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%yeah
    262271       time = all_time[index_f]
     
    268277           indextime = getsindex(stime,((nplot-1)//(nlon*nlat*nvert))%ntime,time)
    269278           if typefile in ['mesoapi','meso'] and indextime is not None:  ltst = localtime ( interv[0]+indextime*interv[1], 0.5*(wlon[0]+wlon[1]) ) 
    270 
    271279####################################################################
    272280
Note: See TracChangeset for help on using the changeset viewer.