Changeset 890 in lmdz_wrf for trunk


Ignore:
Timestamp:
Jun 18, 2016, 11:22:06 PM (8 years ago)
Author:
lfita
Message:

Adding Oderdictionary for the dimensions in `genericNCvariable'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r889 r890  
    141141      d[x/y/z/t]: dimensions of the variable
    142142      dn[x/y/z/t]: name of the dimensions of the variable
     143    >>> variable = genericNCvariable(5,4,3,2,'lon','lat','pres','time')
    143144    """
    144145    def __init__(self,dx,dy,dz,dt,dnx,dny,dnz,dnt):
     146        from collections import OrderedDict
    145147        totshape = dt*dz*dy*dx
    146        
    147         self.values = np.arange((totshape), dtype=np.float).reshape(dt,dz,dy,dx)
    148         self.dimensionsdict = {dnt: dt, dnz: dz, dny: dy, dnx: dx}
    149         self.dimensions = [dnt, dnz, dny, dnx]
     148        dimdict = {dnt: dt, dnz: dz, dny: dy, dnx: dx}
     149
     150        self.values = np.arange((totshape), dtype=np.float).reshape(dt,dz,dy,dx)       
     151        self.dimensions = OrderedDict(sorted(dimdict.items(), key=lambda t: t[0]))
    150152        self.shape = (dt, dz, dy, dx)
    151153        self.standard_name = 'general_var'
     
    155157    def __getitem__(self, val):
    156158        return self.values[val]
    157 
    158 #variable = genericNCvariable(5,4,3,2,'lon','lat','pres','time')
    159159
    160160def varinfile(ncf, filen, emsg, vmsg, varn):
     
    88488848        mean2, min, sum
    88498849    """
    8850 
    88518850    fname = 'operation_alongdims'
    88528851
     
    89658964    file_oper_alongdims(values, ncfile, varn)
    89668965      values= [dimvals],[dimsoper],[opkind],[dimvn]
    8967         [dimvals]; [dimname1]:[val1]|[dimdname2]:[val2]|[...[dimnameN]:[valN]]
     8966        [dimvals]; [dimname1]@[val1]|[dimdname2]@[val2]|[...[dimnameN]@[valN]]
    89688967          [value];
    89698968            * [integer]: which value of the dimension
     
    89878986        quit()
    89888987
    8989     dimvals = values.split(',')[0]
     8988    dimvals = values.split(',')[0].split('@')
    89908989    dimsoper = values.split(',')[1]
    89918990    operkind = values.split(',')[2]
     
    90139012    dimslice = {}
    90149013    for dv in dimvals:
    9015         dnv = dv.slice('|')[0]
    9016         dvv = dv.slice('|')[1]
     9014        dnv = dv.split('|')[0]
     9015        dvv = dv.split('|')[1]
    90179016        if dvv.find(':') != -1:
    9018             beg = int(dvv.slice(':')[0])
    9019             end = int(dvv.slice(':')[1])
     9017            beg = int(dvv.split(':')[0])
     9018            end = int(dvv.split(':')[1])
    90209019            dimslice[dnv] = [beg, end, 1]
    90219020        else:
     
    90419040        tocompute = False
    90429041        for vd in ov.dimensions:
    9043             if searchInlist(dimsoper, vd): tocompute = True
     9042            if gen.searchInlist(dimsoper, vd): tocompute = True
    90449043
    90459044        if tocopmute:
     
    91169115# global attributes
    91179116    objnewnc.setncattr('author', 'L. Fita')
    9118     objnewnc.setncattr('institution', 'Laboratire de Meteorologie Dynamique')
     9117    newattr = set_attributek(newncobj, 'institution', unicode('Laboratoire de M' +   \
     9118      unichr(233) + 't' + unichr(233) + 'orologie Dynamique'), 'U')
    91199119    objnewnc.setncattr('university', 'Pierre Marie Curie - Jussieu')
    91209120    objnewnc.setncattr('center', 'Centre National de Recherches Scientifiques')
Note: See TracChangeset for help on using the changeset viewer.