- Timestamp:
- Apr 18, 2017, 11:06:50 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r1527 r1530 9464 9464 file_oper_alongdims(values, ncfile, varn) 9465 9465 values= [dimvals],[dimsoper],[opkind],[dimvn] 9466 [dimvals]; [dimname1] @[val1]|[dimdname2]@[val2]|[...[dimnameN]@[valN]]9466 [dimvals]; [dimname1]|[val1]:[...[dimnameN]|[valN]] 9467 9467 [value]; 9468 9468 * [integer]: which value of the dimension … … 9487 9487 quit() 9488 9488 9489 dimvals = values.split(',')[0].split(' @')9489 dimvals = values.split(',')[0].split(':') 9490 9490 dimsoper = gen.str_list(values.split(',')[1], ':') 9491 9491 operkind = values.split(',')[2] … … 9554 9554 9555 9555 varslice, varsliceddims = SliceVarDict(ov,dimslice) 9556 # This is absolutely weird m, but if notthere is segmentation fault!9556 # This is absolutely weird, but if I do not make this, there is segmentation fault! 9557 9557 if len(varsliceddims) == len(ov.shape): 9558 varvals0 = np.zeros(tuple(ov.shape), dtype=np.float)9558 varvals00 = np.zeros(tuple(ov.shape), dtype=np.float) 9559 9559 for ix in range(ov.shape[0]): 9560 varvals0[ix,...] = ov[ix,...] 9560 varvals00[ix,...] = ov[ix,...] 9561 if type(ov[:]) == type(ma.array((3), dtype=np.float)): 9562 print warnmsg 9563 print ' ' + fname + ': masked variale !!' 9564 varvals0 = ma.masked_array(varvals00, mask=ov[:].mask) 9565 else: 9566 varvals0 = varvals00 9561 9567 else: 9562 9568 varvals0 = ov[tuple(varslice)] … … 9638 9644 9639 9645 newattr = set_attribute(newvar, 'orig_dimensions', origdimsS) 9646 # Adding original attributes 9647 for attrn in ov.ncattrs(): 9648 if attrn != '_FillValue': 9649 attrv = ov.getncattr(attrn) 9650 newattr = set_attribute(newvar,attrn,attrv) 9651 9640 9652 objnewnc.sync() 9641 9653 else: 9654 varinf = variable_inf(ov) 9655 dimvars = varinf.dimns 9656 shapevar = ov.shape 9657 idim = 0 9658 for dimn in dimvars: 9659 if not gen.searchInlist(list(objnewnc.dimensions), dimn): 9660 if objnc.dimensions[dimn].isunlimited: 9661 newdim = objnewnc.createDimension(dimn,None) 9662 else: 9663 newdim = objnewnc.createDimension(dimn,shapevar[idim]) 9664 idim = idim + 1 9665 9666 # Adding that variables which are not computed via 'operation' 9667 if varinf.FillValue is not None: 9668 newvar = objnewnc.createVariable(vn, nctype(varinf.dtype), \ 9669 tuple(varinf.dimns), fill_value=varinf.FillValue) 9670 else: 9671 newvar = objnewnc.createVariable(vn, nctype(varinf.dtype), \ 9672 tuple(varinf.dimns)) 9673 newvar[:] = ov[:] 9674 for attrn in ov.ncattrs(): 9675 if attrn != '_FillValue': 9676 attrv = ov.getncattr(attrn) 9677 newattr = set_attribute(newvar,attrn,attrv) 9678 objnewnc.sync() 9679 9680 9642 9681 # Statistics of the variable dimension along the dimensions operated 9643 9682 basicoper = ['min', 'max', 'mean', 'mean2', 'sum', 'std', 'var']
Note: See TracChangeset
for help on using the changeset viewer.