- Timestamp:
- Jun 18, 2016, 10:03:26 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r883 r887 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 # generalNCvariable: Function fake netCDF varibale 51 52 # get_1str_nc: Function to get 1 string value in a netCDF variable as a chain of 1char values 52 53 # get_attribute: Function to get an attribute from a netCDF file … … 8797 8798 return operedvals, opereddims 8798 8799 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') 8820 8799 8821 def operation_alongdims(ovar,dimvals,dimsoper,opkind): 8800 8822 """ Function to operate along different dimensions of a variable … … 8982 9004 end = int(dvv.slice(':')[1]) 8983 9005 dimslice[dnv] = [beg, end, 1] 8984 else 9006 else: 8985 9007 dimslice[dnv] = int(dvv) 8986 9008 … … 9034 9056 varinf = variable_inf(ov) 9035 9057 if varinf.FillValue is not None: 9036 newvar = objnewnc.createVariable(vn + oper, nctype(varinf.dtype),\9037 9058 newvar = objnewnc.createVariable(vn + oper, nctype(varinf.dtype), \ 9059 tuple(finaldims), fillValue=varinf.FillValue) 9038 9060 else: 9039 newvar = objnewnc.createVariable(vn + oper, nctype(varinf.dtype),\9040 9061 newvar = objnewnc.createVariable(vn + oper, nctype(varinf.dtype), \ 9062 tuple(finaldims)) 9041 9063 newNvar = newNvar + 1 9042 9064 … … 13019 13041 slicevals.append(slice(0,varshape[idim])) 13020 13042 slicefinaldims.append(dim) 13021 else 13043 else: 13022 13044 slicevals.append(dictv) 13023 13045 else:
Note: See TracChangeset
for help on using the changeset viewer.