Changeset 793 in lmdz_wrf for trunk/tools


Ignore:
Timestamp:
Jun 1, 2016, 3:11:21 PM (9 years ago)
Author:
lfita
Message:

Adding single-point retrieval in `DataSetSection_multivars' (with int=0)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r791 r793  
    1239612396          [endi] = -1, maximum value
    1239712397          [inti] = -1, all the values within the range
     12398                 = 0, single value. [begi] will be taken as the reference value
    1239812399          NOTE: variables without section by the variables are taken allover their size
    1239912400          NOTE2: if inti = 'str', it is assumed that the variable is a string-list of values
     
    1242512426    endvs = np.zeros((Nvars), dtype=int)
    1242612427    intvs = np.zeros((Nvars), dtype=int)
     12428    fbegvs = np.zeros((Nvars), dtype=np.float)
     12429    fendvs = np.zeros((Nvars), dtype=np.float)
     12430    fintvs = np.zeros((Nvars), dtype=np.float)
    1242712431
    1242812432    for ivar in range(Nvars):
     
    1246012464            endvs[ivar] = np.float(val.split(',')[2])
    1246112465            intvs[ivar] = np.float(val.split(',')[3])
     12466            fbegvs[ivar] = np.float(val.split(',')[1])
     12467            fendvs[ivar] = np.float(val.split(',')[2])
     12468            fintvs[ivar] = np.float(val.split(',')[3])
    1246212469            ofiletile = ofiletile + '_' + varns[ivar] + '_B' + str(begvs[ivar]) + '-E' + \
    1246312470              str(endvs[ivar]) + '-I' + str(intvs[ivar])
     
    1251312520            vardims = ovar.dimensions
    1251412521
    12515         if intvs[ivar] != -99.:
     12522        if intvs[ivar] == -99.:
     12523            ostrvar = nciobj.variables[varns[ivar]]
     12524            finalmask = np.ones((ostrvar.shape), dtype= bool)
     12525            finalmask[int(begvs[ivar]),:] = False
     12526        elif intvs[ivar] == 0.:
     12527            vmask = ma.masked_not_equal(vals, fbegvs[ivar])
     12528            finalmask = vmask.mask
     12529            if np.all(finalmask == True):
     12530                print errormsg
     12531                print '  ' + fname + ": variable '" + varns[ivar] + "' does not " +  \
     12532                  'have value=', fbegvs[ivar]
     12533                quit(-1)
     12534        else:
    1251612535            if endvs[ivar] == -1: endvs[ivar] = np.max(vals)
    1251712536            maskinf = ma.masked_less(vals, begvs[ivar])
     
    1252412543            finalmask = maskinf.mask + masksup.mask
    1252512544            idn = 0
    12526         else:
    12527             ostrvar = nciobj.variables[varns[ivar]]
    12528             finalmask = np.ones((ostrvar.shape), dtype= bool)
    12529             finalmask[int(begvs[ivar]),:] = False
    1253012545
    1253112546        slicedims = {}
     
    1253712552            rightvals = np.where(finalmask, False, True)
    1253812553
    12539             if intvs[ivar] != -99.:
    12540                 slicedims[dn]=[np.min(dinds[rightvals][0,:]), np.max(dinds[rightvals][0,:])+1, None]
    12541             else:
     12554            if intvs[ivar] == -99.:
    1254212555                if iidim == 0:
    1254312556                    slicedims[dn]=[int(begvs[ivar]), int(begvs[ivar]), None]
    1254412557                else:
    1254512558                    slicedims[dn]=[0, ddn, None]
     12559            elif intvs[ivar] == 0.:
     12560                if np.sum(~finalmask,axis=iidim) == 0:
     12561                    slicedims[dn]=[0, ddn, None]
     12562                elif np.sum(~finalmask,axis=iidim) == 1:
     12563                    ivals = gen.index_mat(finalmask, False)
     12564                    ival = ivals[iidim]
     12565                    slicedims[dn]=[ival, ival, None]
     12566                else:
     12567                    print errormsg
     12568                    print '  ' + fname + ': multiple', np.sum(~finalmask,axis=iidim), \
     12569                      'possible values!'
     12570                    print '    I do not know how to proceed'
     12571                    quit(-1)
     12572            else:
     12573                slicedims[dn]=[np.min(dinds[rightvals][0,:]), np.max(dinds[rightvals][0,:])+1, None]
    1254612574
    1254712575            iidim = iidim + 1
Note: See TracChangeset for help on using the changeset viewer.