Changeset 917 in lmdz_wrf for trunk/tools
- Timestamp:
- Jun 20, 2016, 9:21:43 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r916 r917 8795 8795 """ 8796 8796 fname = 'operdim' 8797 readyop = ['max', 'mean', 'mean2', 'min', 'std', 'sum'] 8797 8798 8798 8799 operslice = [] … … 8813 8814 varoper = np.mean(varoper, axis=idim-noper) 8814 8815 elif oper == 'mean2': 8815 varoper = np.mean(varoper, axis=idim-noper) 8816 varoper1 = np.mean(varoper, axis=idim-noper) 8817 varoper = varoper1*varoper1 8816 8818 elif oper == 'min': 8817 8819 varoper = np.min(varoper, axis=idim-noper) 8820 elif oper == 'std': 8821 varoper = np.std(varoper, axis=idim-noper) 8818 8822 elif oper == 'sum': 8819 8823 varoper = np.sum(varoper, axis=idim-noper) … … 8821 8825 print errormsg 8822 8826 print ' ' + fname + ': operation "' + oper + '" not ready!!' 8827 print ' operations available:', readyop 8823 8828 quit(-1) 8824 8829 noper = noper + 1 … … 8917 8922 elif opkind == 'sum': 8918 8923 varoper = np.sum(origvar, axis=ids-noper) 8924 elif opkind == 'std': 8925 varoper = np.std(origvar, axis=ids-noper) 8919 8926 else: 8920 8927 print errormsg … … 8990 8997 # Operations with which when the variable dimensions will be ajusted to the file 8991 8998 # the zero value along the operated dimensions will be taken 8992 zerodimops = ['max', 'mean', 'mean2', 'min', 'sum' ]8999 zerodimops = ['max', 'mean', 'mean2', 'min', 'sum', 'std'] 8993 9000 8994 9001 dimsoperS = gen.numVector_String(dimsoper,', ') … … 9024 9031 dimfinalfile = [] 9025 9032 9026 print ' ' + fname + ": '" + operkind + "' with:", dimsoper,'_______'9033 print ' ' + fname + ": '" + operkind + "' with:", dimsoper, '_______' 9027 9034 newNdim = 0 9028 9035 newNvar = 0 … … 9082 9089 tuple(finaldims)) 9083 9090 newNvar = newNvar + 1 9091 print fname + ': Lluis; shapes:', newvar.shape,' finalvarvals:', finalvarvals.shape 9084 9092 newvar[:] = finalvarvals[:] 9085 9093 … … 9128 9136 9129 9137 # Statistics of the variable dimension along the dimensions operated 9130 basicoper = ['min', 'max', 'me nan', 'mean2', 'sum']9138 basicoper = ['min', 'max', 'mean', 'mean2', 'sum', 'std'] 9131 9139 9132 9140 # operating variable dimension … … 9225 9233 objnewnc.sync() 9226 9234 9235 # Statistics of the variable dimension along the dimensions operated in case 9236 # dimension after operation disapears 9237 print ' ' + fname + ': Statisitcs of operated variable dimension _______' 9238 for vn in dimvn: 9239 print "' " + vn + "' ... .. ." 9240 if not objnc.variables.has_key(vn): 9241 print warnmsg 9242 print ' ' + fname + ': netCDF file "' + ncfile + \ 9243 '" does not have variable "' + vn + '" skipping it !!' 9244 continue 9245 varslice, varsliceddims = SliceVarDict(ov,dimslice) 9246 varvals0 = ov[tuple(varslice)] 9247 varvals = np.squeeze(varvals0) 9248 9249 varname = gen.variables_values(vn)[0] 9250 if gen.searchInlist(oldvarattr, 'standard_name'): 9251 stdname = ov.getncattr('standard_name') 9252 else: 9253 stdname = gen.variables_values(vn)[1] 9254 9255 if gen.searchInlist(oldvarattr, 'long_name'): 9256 lname = ov.getncattr('long_name') 9257 else: 9258 lname = gen.variables_values(vn)[4].replace('|',' ') 9259 9260 if gen.searchInlist(oldvarattr, 'units'): 9261 uname = ov.getncattr('units') 9262 else: 9263 uname = gen.variables_values(vn)[5] 9264 9265 if len(varvals.shape) == 1: 9227 9266 # Statistics of the variable dimension along the dimensions operated 9267 newvar = objnewnc.createVariable(vn+'stats', 'f4' ) 9268 newattr = basicvardef(newvar, stdname + 'statistics', lname + \ 9269 ' statistics', uname) 9270 9271 newattr = set_attributek(newvar, 'Nvalues', len(varvals), 'I') 9228 9272 for op in basicoper: 9229 if op != operkind: 9230 finalvarv, finalds = operdim(varvals,varsliceddims,dimsoper,op) 9231 if varinf.FillValue is not None: 9232 newvar = objnewnc.createVariable(vn+op, nctype(varinf.dtype),\ 9233 tuple(finalds), fillValue=varinf.FillValue) 9234 else: 9235 newvar = objnewnc.createVariable(vn+op, nctype(varinf.dtype),\ 9236 tuple(finalds)) 9237 newNvar = newNvar + 1 9238 newvar[:] = finalvarv[:] 9239 newattr = basicvardef(newvar, stdname + op, lname + ' '+ op + \ 9240 ' along ' + dimsoperS, uname) 9273 finalvarv, finalds = operdim(varvals,varsliceddims,dimsoper,op) 9274 newattr = set_attributek(newvar, op, finalvarv, 'R') 9241 9275 objnewnc.sync() 9242 9276
Note: See TracChangeset
for help on using the changeset viewer.