Changeset 889 in lmdz_wrf for trunk


Ignore:
Timestamp:
Jun 18, 2016, 10:24:29 PM (8 years ago)
Author:
lfita
Message:

Working version of `operdim'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r888 r889  
    144144    def __init__(self,dx,dy,dz,dt,dnx,dny,dnz,dnt):
    145145        totshape = dt*dz*dy*dx
    146         dimensions = {}
    147146       
    148147        self.values = np.arange((totshape), dtype=np.float).reshape(dt,dz,dy,dx)
    149         self.dimensions = {dnx: dx, dny: dy, dnz: dz, dnt: dt}
     148        self.dimensionsdict = {dnt: dt, dnz: dz, dny: dy, dnx: dx}
     149        self.dimensions = [dnt, dnz, dny, dnx]
    150150        self.shape = (dt, dz, dy, dx)
    151151        self.standard_name = 'general_var'
     
    87858785      doper: names of the dimensions to operate
    87868786      oper: operation to perform
     8787    >>> variable = genericNCvariable(5,4,3,2,'lon','lat','pres','time')
     8788    >>> varv = variable[:]
     8789    >>> vardims = variable.dimensions
     8790    >>> doper = ['time', 'pres']
     8791    >>> oper = 'mean'
     8792    >>> operv, operd = operdim(varv, vardims, doper, oper)
     8793    [[ 50.  51.  52.  53.  54.]
     8794     [ 55.  56.  57.  58.  59.]
     8795     [ 60.  61.  62.  63.  64.]
     8796     [ 65.  66.  67.  68.  69.]]
     8797    ['lat', 'lon']
    87878798    """
    87888799    fname = 'operdim'
     
    87958806            operslice.append(True)
    87968807
    8797     operddims = []
     8808    opereddims = []
    87988809    noper = 0
     8810    varoper = varv.copy()
    87998811    for idim in range(len(varv.shape)):
     8812        print 'Lluis:', idim, vardims[idim], operslice[idim],':',varoper.shape
    88008813        if operslice[idim]:
    88018814            if oper == 'max':
    8802                 varoper = np.max(varv, axis=idim-noper)
     8815                varoper = np.max(varoper, axis=idim-noper)
    88038816            elif oper == 'mean':
    8804                 varoper = np.mean(varv, axis=idim-noper)
     8817                varoper = np.mean(varoper, axis=idim-noper)
    88058818            elif oper == 'mean2':
    8806                 varoper = np.mean(varv, axis=idim-noper)
     8819                varoper = np.mean(varoper, axis=idim-noper)
    88078820            elif oper == 'min':
    8808                 varoper = np.min(varv, axis=idim-noper)
     8821                varoper = np.min(varoper, axis=idim-noper)
    88098822            elif oper == 'sum':
    8810                 varoper = np.sum(varv, axis=idim-noper)
     8823                varoper = np.sum(varoper, axis=idim-noper)
    88118824            else:
    88128825                print errormsg
     
    88158828            noper = noper + 1
    88168829        else:
    8817             operddims.append(vardims[idim])
     8830            opereddims.append(vardims[idim])
     8831
     8832    operedvals = varoper
    88188833           
    88198834    return operedvals, opereddims
    8820 
    8821 variable = genericNCvariable(5,4,3,2,'lon','lat','pres','time')
    8822 vv = variable[:]
    8823 vardims = variable.dimensions
    8824 doper = 'time'
    8825 oper = 'mean'
    8826 
    8827 operv, operd = operdim(varv, vardims, doper, oper)
    8828 print operv
    8829 print operd
    8830 quit()
    88318835
    88328836def operation_alongdims(ovar,dimvals,dimsoper,opkind):
Note: See TracChangeset for help on using the changeset viewer.