Changeset 887 in lmdz_wrf for trunk


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

adding `generalNCvariable': Function fake netCDF varibale

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r883 r887  
    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
    5152# get_1str_nc: Function to get 1 string value in a netCDF variable as a chain of 1char values
    5253# get_attribute: Function to get an attribute from a netCDF file
     
    87978798    return operedvals, opereddims
    87988799
     8800class 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')
     8820
    87998821def operation_alongdims(ovar,dimvals,dimsoper,opkind):
    88008822    """ Function to operate along different dimensions of a variable
     
    89829004            end = int(dvv.slice(':')[1])
    89839005            dimslice[dnv] = [beg, end, 1]
    8984         else
     9006        else:
    89859007            dimslice[dnv] = int(dvv)
    89869008
     
    90349056            varinf = variable_inf(ov)
    90359057            if varinf.FillValue is not None:
    9036                  newvar = objnewnc.createVariable(vn + oper, nctype(varinf.dtype),   \
    9037                    tuple(finaldims), fillValue=varinf.FillValue)
     9058                newvar = objnewnc.createVariable(vn + oper, nctype(varinf.dtype),    \
     9059                  tuple(finaldims), fillValue=varinf.FillValue)
    90389060            else:
    9039                  newvar = objnewnc.createVariable(vn + oper, nctype(varinf.dtype),   \
    9040                    tuple(finaldims))
     9061                newvar = objnewnc.createVariable(vn + oper, nctype(varinf.dtype),    \
     9062                  tuple(finaldims))
    90419063                newNvar = newNvar + 1
    90429064
     
    1301913041                    slicevals.append(slice(0,varshape[idim]))
    1302013042                    slicefinaldims.append(dim)
    13021                 else
     13043                else:
    1302213044                    slicevals.append(dictv)
    1302313045        else:
Note: See TracChangeset for help on using the changeset viewer.