- Timestamp:
- Jun 18, 2016, 10:24:29 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r888 r889 144 144 def __init__(self,dx,dy,dz,dt,dnx,dny,dnz,dnt): 145 145 totshape = dt*dz*dy*dx 146 dimensions = {}147 146 148 147 self.values = np.arange((totshape), dtype=np.float).reshape(dt,dz,dy,dx) 149 self.dimensions = {dnx: dx, dny: dy, dnz: dz, dnt: dt} 148 self.dimensionsdict = {dnt: dt, dnz: dz, dny: dy, dnx: dx} 149 self.dimensions = [dnt, dnz, dny, dnx] 150 150 self.shape = (dt, dz, dy, dx) 151 151 self.standard_name = 'general_var' … … 8785 8785 doper: names of the dimensions to operate 8786 8786 oper: operation to perform 8787 >>> variable = genericNCvariable(5,4,3,2,'lon','lat','pres','time') 8788 >>> varv = variable[:] 8789 >>> vardims = variable.dimensions 8790 >>> doper = ['time', 'pres'] 8791 >>> oper = 'mean' 8792 >>> operv, operd = operdim(varv, vardims, doper, oper) 8793 [[ 50. 51. 52. 53. 54.] 8794 [ 55. 56. 57. 58. 59.] 8795 [ 60. 61. 62. 63. 64.] 8796 [ 65. 66. 67. 68. 69.]] 8797 ['lat', 'lon'] 8787 8798 """ 8788 8799 fname = 'operdim' … … 8795 8806 operslice.append(True) 8796 8807 8797 oper ddims = []8808 opereddims = [] 8798 8809 noper = 0 8810 varoper = varv.copy() 8799 8811 for idim in range(len(varv.shape)): 8812 print 'Lluis:', idim, vardims[idim], operslice[idim],':',varoper.shape 8800 8813 if operslice[idim]: 8801 8814 if oper == 'max': 8802 varoper = np.max(var v, axis=idim-noper)8815 varoper = np.max(varoper, axis=idim-noper) 8803 8816 elif oper == 'mean': 8804 varoper = np.mean(var v, axis=idim-noper)8817 varoper = np.mean(varoper, axis=idim-noper) 8805 8818 elif oper == 'mean2': 8806 varoper = np.mean(var v, axis=idim-noper)8819 varoper = np.mean(varoper, axis=idim-noper) 8807 8820 elif oper == 'min': 8808 varoper = np.min(var v, axis=idim-noper)8821 varoper = np.min(varoper, axis=idim-noper) 8809 8822 elif oper == 'sum': 8810 varoper = np.sum(var v, axis=idim-noper)8823 varoper = np.sum(varoper, axis=idim-noper) 8811 8824 else: 8812 8825 print errormsg … … 8815 8828 noper = noper + 1 8816 8829 else: 8817 operddims.append(vardims[idim]) 8830 opereddims.append(vardims[idim]) 8831 8832 operedvals = varoper 8818 8833 8819 8834 return operedvals, opereddims 8820 8821 variable = genericNCvariable(5,4,3,2,'lon','lat','pres','time')8822 vv = variable[:]8823 vardims = variable.dimensions8824 doper = 'time'8825 oper = 'mean'8826 8827 operv, operd = operdim(varv, vardims, doper, oper)8828 print operv8829 print operd8830 quit()8831 8835 8832 8836 def operation_alongdims(ovar,dimvals,dimsoper,opkind):
Note: See TracChangeset
for help on using the changeset viewer.