- Timestamp:
- Jun 21, 2016, 9:50:11 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r917 r918 9035 9035 newNvar = 0 9036 9036 for vn in varns: 9037 print " '" + vn + "' ... .. ."9037 print " '" + vn + "' ... .. ." 9038 9038 if not objnc.variables.has_key(vn): 9039 9039 print errormsg … … 9089 9089 tuple(finaldims)) 9090 9090 newNvar = newNvar + 1 9091 print fname + ': Lluis; shapes:', newvar.shape,' finalvarvals:', finalvarvals.shape9092 9091 newvar[:] = finalvarvals[:] 9093 9092 … … 9141 9140 print ' ' + fname + ': Opering slice of variable dimension _______' 9142 9141 for vn in dimvn: 9143 print " '" + vn + "' ... .. ."9142 print " '" + vn + "' ... .. ." 9144 9143 if not objnc.variables.has_key(vn): 9145 9144 print warnmsg … … 9235 9234 # Statistics of the variable dimension along the dimensions operated in case 9236 9235 # dimension after operation disapears 9237 print ' ' + fname + ': Statisitcs of operated variable dimension _______'9238 9236 for vn in dimvn: 9239 print "' " + vn + "' ... .. ."9240 9237 if not objnc.variables.has_key(vn): 9241 9238 print warnmsg … … 9243 9240 '" does not have variable "' + vn + '" skipping it !!' 9244 9241 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: 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') 9272 for op in basicoper: 9273 finalvarv, finalds = operdim(varvals,varsliceddims,dimsoper,op) 9274 newattr = set_attributek(newvar, op, finalvarv, 'R') 9275 objnewnc.sync() 9242 # Do we have to compute this variable? 9243 ov = objnc.variables[vn] 9244 tocompute = False 9245 for vd in ov.dimensions: 9246 if gen.searchInlist(dimsoper, vd): tocompute = True 9247 9248 if tocompute: 9249 varslice, varsliceddims = SliceVarDict(ov,dimslice) 9250 varvals0 = ov[tuple(varslice)] 9251 varvals = np.squeeze(varvals0) 9252 9253 varname = gen.variables_values(vn)[0] 9254 if gen.searchInlist(oldvarattr, 'standard_name'): 9255 stdname = ov.getncattr('standard_name') 9256 else: 9257 stdname = gen.variables_values(vn)[1] 9258 9259 if gen.searchInlist(oldvarattr, 'long_name'): 9260 lname = ov.getncattr('long_name') 9261 else: 9262 lname = gen.variables_values(vn)[4].replace('|',' ') 9263 9264 if gen.searchInlist(oldvarattr, 'units'): 9265 uname = ov.getncattr('units') 9266 else: 9267 uname = gen.variables_values(vn)[5] 9268 9269 if len(varvals.shape) == 1: 9270 print ' ' + fname + ': Statisitcs of operated variable dimension _______' 9271 print " '" + vn + "' ... .. ." 9272 # Statistics of the variable dimension along the dimensions operated 9273 newvar = objnewnc.createVariable(vn+'stats', 'f4' ) 9274 newattr = basicvardef(newvar, stdname + 'statistics', lname + \ 9275 ' statistics', uname) 9276 9277 newattr = set_attributek(newvar, 'Nvalues', len(varvals), 'I') 9278 for op in basicoper: 9279 finalvarv, finalds = operdim(varvals,varsliceddims,dimsoper,op) 9280 newattr = set_attributek(newvar, op, finalvarv, 'R') 9281 objnewnc.sync() 9276 9282 9277 9283 # Including operation dimensions on the new slice for the variables dimension … … 9287 9293 print ' ' + fname + ': Adding slice of variable dimension _______' 9288 9294 for vn in dimvn: 9289 print " '" + vn + "' ... .. ."9295 print " '" + vn + "' ... .. ." 9290 9296 if not objnc.variables.has_key(vn): 9291 9297 print warnmsg … … 9306 9312 varvals0 = ov[tuple(varslice)] 9307 9313 varvals = np.squeeze(varvals0) 9308 9309 print 'Lluis: variables to add:', varsliceddims9310 9314 9311 9315 for idv in range(len(varvals.shape)):
Note: See TracChangeset
for help on using the changeset viewer.