Changeset 795 in lmdz_wrf


Ignore:
Timestamp:
Jun 1, 2016, 4:45:27 PM (9 years ago)
Author:
lfita
Message:

Fixing `DataSetSection_multivars' by keeping dimensions' modification ranges

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r794 r795  
    2121# ijlonlat: Function to provide the imin,jmin imax,jmax of a lon,lat box
    2222# PolyArea: Function to compute the area of the polygon following 'Shoelace formula'
     23# significant_decomposition: Function to decompose a given number by its signifcant potencies
    2324
    2425def values_line(line, splitv, chars):
  • trunk/tools/nc_var_tools.py

    r793 r795  
    1243712437            print '  ' + fname + ": file '" + filen + "' does not have variable '" + \
    1243812438              vn + "' !!"
    12439             print '    it has:', nciobj.variables
     12439            print '    it has:', list(nciobj.variables)
    1244012440            quit(-1)
    1244112441
     
    1245212452                print errormsg
    1245312453                print '  ' + fname + ": variable '" + val + "' does not have " +     \
    12454                   "value: '" + strvalue + "' !!"
     12454                  "value= '" + strvalue + "' !!"
    1245512455                print '    values:', strvals
    1245612456                quit(-1)
     
    1247012470              str(endvs[ivar]) + '-I' + str(intvs[ivar])
    1247112471            if intvs[ivar] != -1:
    12472                 slicevalS = slicevalS + varns[ivar] + ' (' + str(begvs[ivar]) + ',' +    \
    12473                   str(endvs[ivar]) + ',' + str(intvs[ivar]) + '); '
     12472                slicevalS = slicevalS + varns[ivar] + ' (' + str(fbegvs[ivar]) + ',' +   \
     12473                  str(fendvs[ivar]) + ',' + str(fintvs[ivar]) + '); '
    1247412474            else:
    12475                 slicevalS = slicevalS + varns[ivar] + ' (' + str(begvs[ivar]) + ',' +    \
    12476                   str(endvs[ivar]) + ',1); '
     12475                slicevalS = slicevalS + varns[ivar] + ' (' + str(fbegvs[ivar]) + ',' +   \
     12476                  str(fendvs[ivar]) + ',1); '
    1247712477
    1247812478    ofile = ofile=filen.split('.')[0] + ofiletile + '.nc'
     
    1249212492# Looking for limits due to the variables
    1249312493##
     12494    slicedims = {}
    1249412495    for ivar in range(Nvars):
    1249512496        print '  ' + fname + ": masking with '" + varns[ivar] + "':",  begvs[ivar],  \
     
    1252512526            finalmask[int(begvs[ivar]),:] = False
    1252612527        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)
     12528#           Looking in the non efficient way
     12529            diffvar = np.abs(vals-fbegvs[ivar])
     12530            mindiffvar = np.min(diffvar)
     12531            imindiff = gen.index_mat(diffvar, mindiffvar)
     12532            if np.all(imindiff == -1):
     12533                print errmsg
     12534                print '  ' + fname + ': no exact value with:',  fbegvs[ivar],        \
     12535                  'has been found!!'
     12536                print '    attempting within the range:', potminv, ',', potmaxv
     12537            finalmask = np.ones(vals.shape, dtype=np.float)
     12538            finalmask[tuple(imindiff)] = False
    1253412539        else:
    1253512540            if endvs[ivar] == -1: endvs[ivar] = np.max(vals)
     
    1254312548            finalmask = maskinf.mask + masksup.mask
    1254412549            idn = 0
    12545 
    12546         slicedims = {}
    1254712550       
    1254812551        iidim = 0
     
    1255012553            ddn = len(nciobj.dimensions[dn])
    1255112554            dinds = np.arange(ddn)
    12552             rightvals = np.where(finalmask, False, True)
    12553 
    12554             if intvs[ivar] == -99.:
    12555                 if iidim == 0:
    12556                     slicedims[dn]=[int(begvs[ivar]), int(begvs[ivar]), None]
     12555            rightvals = ~ma.array(vals, mask=finalmask).mask
     12556
     12557# Checking if dimension is already cut:
     12558            if slicedims.has_key(dn):
     12559                slicedval = slicedims[dn]
     12560                if slicedval[0] == 0 and slicedval[1] == ddn:
     12561                    fulldim = True
    1255712562                else:
    12558                     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]
     12563                    fulldim = False
     12564            else:
     12565                fulldim = True
     12566
     12567            if not slicedims.has_key(dn) or fulldim:
     12568                if intvs[ivar] == -99.:
     12569                    if iidim == 0:
     12570                        slicedims[dn]=[int(begvs[ivar]), int(begvs[ivar]), None]
     12571                    else:
     12572                        slicedims[dn]=[0, ddn, None]
     12573                elif intvs[ivar] == 0.:
     12574                    if imindiff[iidim] == 0:
     12575                        slicedims[dn]=[0, ddn, None]
     12576                    else:
     12577                        slicedims[dn]=[iidim, iidim, None]
    1256612578                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]
     12579                    slicedims[dn]=[np.min(dinds[rightvals][0,:]),                    \
     12580                      np.max(dinds[rightvals][0,:])+1, None]
    1257412581
    1257512582            iidim = iidim + 1
Note: See TracChangeset for help on using the changeset viewer.