Changeset 888 in lmdz_wrf for trunk


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

Renaming class to genericNCvariable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r887 r888  
    4949# gaddattr: Add a global attribute to a netCDF. Removes previous attribute if it exist
    5050# gaddattrk: Add a global attribute to a netCDF caring about the type. Removes previous attribute if it exist
    51 # generalNCvariable: Function fake netCDF varibale
     51# genericNCvariable: Class to fake a netCDF varibale
    5252# get_1str_nc: Function to get 1 string value in a netCDF variable as a chain of 1char values
    5353# get_attribute: Function to get an attribute from a netCDF file
     
    136136errormsg = 'ERROR -- error -- ERROR -- error'
    137137warnmsg = 'WARNING -- warning -- WARNING -- warning'
     138
     139class genericNCvariable(object):
     140    """ Class to fake a netCDF varibale
     141      d[x/y/z/t]: dimensions of the variable
     142      dn[x/y/z/t]: name of the dimensions of the variable
     143    """
     144    def __init__(self,dx,dy,dz,dt,dnx,dny,dnz,dnt):
     145        totshape = dt*dz*dy*dx
     146        dimensions = {}
     147       
     148        self.values = np.arange((totshape), dtype=np.float).reshape(dt,dz,dy,dx)
     149        self.dimensions = {dnx: dx, dny: dy, dnz: dz, dnt: dt}
     150        self.shape = (dt, dz, dy, dx)
     151        self.standard_name = 'general_var'
     152        self.long_name = 'generic netcdf variable'
     153        self.units = '-'
     154
     155    def __getitem__(self, val):
     156        return self.values[val]
     157
     158#variable = genericNCvariable(5,4,3,2,'lon','lat','pres','time')
    138159
    139160def varinfile(ncf, filen, emsg, vmsg, varn):
     
    87988819    return operedvals, opereddims
    87998820
    8800 class generalNCvariable(object):
    8801     """ Function fake netCDF varibale
    8802       d[x/y/z/t]: dimensions of the variable
    8803       dn[x/y/z/t]: name of the dimensions of the variable
    8804     """
    8805     def __init__(self,dx,dy,dz,dt,dnx,dny,dnz,dnt):
    8806         totshape = dt*dz*dy*dx
    8807         dimensions = {}
    8808        
    8809         self.values = np.arange((totshape), dtype=np.float).reshape(dt,dz,dy,dx)
    8810         self.dimensions = {dnx: dx, dny: dy, dnz: dz, dnt: dt}
    8811         self.shape = (dt, dz, dy, dx)
    8812         self.standard_name = 'general_var'
    8813         self.long_name = 'generic netcdf variable'
    8814         self.units = '-'
    8815 
    8816     def __getitem__(self, val):
    8817         return self.values[val]
    8818 
    8819 #variable = generalNCvariable(5,4,3,2,'lon','lat','pres','time')
     8821variable = genericNCvariable(5,4,3,2,'lon','lat','pres','time')
     8822vv = variable[:]
     8823vardims = variable.dimensions
     8824doper = 'time'
     8825oper = 'mean'
     8826
     8827operv, operd = operdim(varv, vardims, doper, oper)
     8828print operv
     8829print operd
     8830quit()
    88208831
    88218832def operation_alongdims(ovar,dimvals,dimsoper,opkind):
Note: See TracChangeset for help on using the changeset viewer.