- Timestamp:
- Jun 18, 2016, 10:07:34 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r887 r888 49 49 # gaddattr: Add a global attribute to a netCDF. Removes previous attribute if it exist 50 50 # gaddattrk: Add a global attribute to a netCDF caring about the type. Removes previous attribute if it exist 51 # gener alNCvariable: Function fakenetCDF varibale51 # genericNCvariable: Class to fake a netCDF varibale 52 52 # get_1str_nc: Function to get 1 string value in a netCDF variable as a chain of 1char values 53 53 # get_attribute: Function to get an attribute from a netCDF file … … 136 136 errormsg = 'ERROR -- error -- ERROR -- error' 137 137 warnmsg = 'WARNING -- warning -- WARNING -- warning' 138 139 class 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') 138 159 139 160 def varinfile(ncf, filen, emsg, vmsg, varn): … … 8798 8819 return operedvals, opereddims 8799 8820 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') 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() 8820 8831 8821 8832 def operation_alongdims(ovar,dimvals,dimsoper,opkind):
Note: See TracChangeset
for help on using the changeset viewer.