Changeset 1530 in lmdz_wrf for trunk


Ignore:
Timestamp:
Apr 18, 2017, 11:06:50 PM (8 years ago)
Author:
lfita
Message:

Adding on `file_oper_alongdims':

  • Addition of that variables which are not computed in output file
  • Tacking into account if variable is masked
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r1527 r1530  
    94649464    file_oper_alongdims(values, ncfile, varn)
    94659465      values= [dimvals],[dimsoper],[opkind],[dimvn]
    9466         [dimvals]; [dimname1]@[val1]|[dimdname2]@[val2]|[...[dimnameN]@[valN]]
     9466        [dimvals]; [dimname1]|[val1]:[...[dimnameN]|[valN]]
    94679467          [value];
    94689468            * [integer]: which value of the dimension
     
    94879487        quit()
    94889488
    9489     dimvals = values.split(',')[0].split('@')
     9489    dimvals = values.split(',')[0].split(':')
    94909490    dimsoper = gen.str_list(values.split(',')[1], ':')
    94919491    operkind = values.split(',')[2]
     
    95549554
    95559555            varslice, varsliceddims = SliceVarDict(ov,dimslice)
    9556             # This is absolutely weirdm, but if not there is segmentation fault!
     9556            # This is absolutely weird, but if I do not make this, there is segmentation fault!
    95579557            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)
    95599559                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
    95619567            else:
    95629568                varvals0 = ov[tuple(varslice)]
     
    96389644
    96399645            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
    96409652            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
    96429681    # Statistics of the variable dimension along the dimensions operated
    96439682    basicoper = ['min', 'max', 'mean', 'mean2', 'sum', 'std', 'var']
Note: See TracChangeset for help on using the changeset viewer.