Changeset 917 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jun 20, 2016, 9:21:43 PM (8 years ago)
Author:
lfita
Message:

Adding:

  • dimoper + 'statistics' for that variable dimensions which disappear after the operation in `file_oper_alongdims'
  • `std' in 'operdim'
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r916 r917  
    87958795    """
    87968796    fname = 'operdim'
     8797    readyop = ['max', 'mean', 'mean2', 'min', 'std', 'sum']
    87978798
    87988799    operslice = []
     
    88138814                varoper = np.mean(varoper, axis=idim-noper)
    88148815            elif oper == 'mean2':
    8815                 varoper = np.mean(varoper, axis=idim-noper)
     8816                varoper1 = np.mean(varoper, axis=idim-noper)
     8817                varoper = varoper1*varoper1
    88168818            elif oper == 'min':
    88178819                varoper = np.min(varoper, axis=idim-noper)
     8820            elif oper == 'std':
     8821                varoper = np.std(varoper, axis=idim-noper)
    88188822            elif oper == 'sum':
    88198823                varoper = np.sum(varoper, axis=idim-noper)
     
    88218825                print errormsg
    88228826                print '  ' + fname + ': operation "' + oper + '" not ready!!'
     8827                print '    operations available:', readyop
    88238828                quit(-1)
    88248829            noper = noper + 1
     
    89178922                elif opkind == 'sum':
    89188923                    varoper = np.sum(origvar, axis=ids-noper)
     8924                elif opkind == 'std':
     8925                    varoper = np.std(origvar, axis=ids-noper)
    89198926                else:
    89208927                    print errormsg
     
    89908997# Operations with which when the variable dimensions will be ajusted to the file
    89918998#   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']
    89939000
    89949001    dimsoperS = gen.numVector_String(dimsoper,', ')
     
    90249031    dimfinalfile = []
    90259032
    9026     print '  ' + fname + ": '" + operkind + "' with:",dimsoper,'_______'
     9033    print '  ' + fname + ": '" + operkind + "' with:", dimsoper, '_______'
    90279034    newNdim = 0
    90289035    newNvar = 0
     
    90829089                  tuple(finaldims))
    90839090                newNvar = newNvar + 1
     9091            print fname + ': Lluis; shapes:', newvar.shape,' finalvarvals:', finalvarvals.shape
    90849092            newvar[:] = finalvarvals[:]
    90859093
     
    91289136   
    91299137    # Statistics of the variable dimension along the dimensions operated
    9130     basicoper = ['min', 'max', 'menan', 'mean2', 'sum']
     9138    basicoper = ['min', 'max', 'mean', 'mean2', 'sum', 'std']
    91319139
    91329140# operating variable dimension
     
    92259233            objnewnc.sync()
    92269234
     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:
    92279266            # 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')
    92289272            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')
    92419275            objnewnc.sync()
    92429276
Note: See TracChangeset for help on using the changeset viewer.