- Timestamp:
- Jun 18, 2016, 4:33:15 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r875 r876 8975 8975 # Variables with dimension values 8976 8976 vardims = dimvn.split(':') 8977 for ivdim in range(len(vardims)): 8978 if not objnewnc.variables.has_key(vardims[ivdim]): 8979 objvdim = objnc.variables[vardims[ivdim]] 8977 Nvardims = len(vardims) 8978 for ivd in range(Nvardims): 8979 if not objnewnc.variables.has_key(vardims[ivd]): 8980 objvdim = objnc.variables[vardims[ivd]] 8981 coinvardims = objvdim.dimensions 8982 8983 # Introducing only that variable dimensions with coincident dims 8984 toadd = False 8985 for vdn in coinvardims: 8986 if gen.searchInlist(newvardimns, vdn): toadd = True 8987 8980 8988 vdimtype = objvdim.dtype 8981 newdimvarv, newdimvardimns=operation_alongdims(objvdim,dimvals,dimsoper,operkind) 8989 if toadd: 8990 newdvarv, newdvards=operation_alongdims(objvdim,dimvals, \ 8991 dimsoper,operkind) 8982 8992 8983 8993 # Introducing only that dimension variables with any dimension after the operation 8984 if len(newdimvardimns) > 0: 8985 8986 # Old method introducing new dimension if needed 8987 ## dimsvdim = objvdim.dimensions 8988 ## dimvslice = [] 8989 ## dimvdims = [] 8990 ## for idmvd in range(len(dimsvdim)): 8991 ## found = False 8992 ## for idimv in range(len(newvardimns)): 8993 ## if dimsvdim[idmvd] == newvardimns[idimv]: 8994 ## dimvslice.append(slice(0,objvdim.shape[idmvd])) 8995 ## dimvdims.append(dimsvdim[idmvd]) 8996 ## found = True 8997 ## break 8998 ## if not found: 8999 ## print warnmsg 9000 ## print ' ' + fname + ": dimension '" + dimsvdim[idmvd] + \ 9001 ## "' not found !!" 9002 ## print " adding it for variable dimension: '" + \ 9003 ## vardims[ivdim] + "'" 9004 ## if not objnewnc.dimensions.has_key(dimsvdim[idmvd]): 9005 ## dsize = len(objnc.dimensions[dimsvdim[idmvd]]) 9006 ## objnewnc.createDimension(dimsvdim[idmvd], dsize) 9007 ## dimvslice.append(slice(len(objnc.dimensions[dimsvdim[idmvd]]))) 9008 ## dimvdims.append(dimsvdim[idmvd]) 9009 9010 newvar = objnewnc.createVariable(vardims[ivdim], vdimtype, \ 9011 tuple(newdimvardimns)) 9012 newvar[:] = newdimvarv 9013 dimvattrs = objvdim.ncattrs() 9014 for attrn in dimvattrs: 9015 attrv = objvdim.getncattr(attrn) 9016 newattr = set_attribute(newvar,attrn,attrv) 9017 9018 newattr = set_attribute(newvar, 'operation:', operkind + \ 9019 ' along ' + dimsoperS) 8994 if len(newdvards) > 0: 8995 newvar = objnewnc.createVariable(vardims[ivd], \ 8996 vdimtype, tuple(newdvards)) 8997 newvar[:] = newdvarv 8998 dimvattrs = objvdim.ncattrs() 8999 for attrn in dimvattrs: 9000 attrv = objvdim.getncattr(attrn) 9001 newattr = set_attribute(newvar,attrn,attrv) 9002 9003 newattr = set_attribute(newvar, 'operation', operkind + \ 9004 ' along ' + dimsoperS) 9020 9005 9021 9006 # new variable
Note: See TracChangeset
for help on using the changeset viewer.