Changeset 1558 in lmdz_wrf for trunk/tools/generic_tools.py


Ignore:
Timestamp:
May 9, 2017, 3:48:14 PM (8 years ago)
Author:
lfita
Message:

Adding management of error response in `mask_quantiles'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r1552 r1558  
    1919main = 'nc_var_tools.py'
    2020
    21 errormsg='ERROR -- error -- ERROR -- error'
    22 warnmsg='WARNING -- warning -- WARNING -- warning'
     21errormsg = 'ERROR -- error -- ERROR -- error'
     22warnmsg = 'WARNING -- warning -- WARNING -- warning'
     23infmsg = 'INFORMATION -- information -- INFORMATION -- information'
    2324
    2425fillValue = 1.e20
     
    36883689    return pearsonr
    36893690
    3690 def mask_quantiles(maskmat, Nquants):
     3691def mask_quantiles(maskmat, Nquants, Notenough=True):
    36913692    """ Function to provide the quantiles of a masked array 20 for %5 bins (21 in total)
    36923693    """
    36933694    import numpy.ma as ma
    3694 
    3695     fillValue = 1.e20
    3696 
     3695    fname = 'mask_quantiles'
     3696
     3697    if type(maskmat) != type(mamat):
     3698        maskvals = np.zeros((maskmat.shape), dtype=bool)
     3699    else:
     3700        maskvals = maskmat.mask
    36973701    sortmat = maskmat.flatten().copy()
    36983702    sortmat.sort()
    36993703    quants = np.zeros(Nquants+1, dtype=type(maskmat[0]))
    37003704    Nv = ma.size(maskmat)
    3701     NoMask=maskmat.count()
     3705    NoMask=np.sum(~maskvals)
    37023706
    37033707    if NoMask < Nquants:
    3704         quants[:] = fillValue
     3708        if Notenough:
     3709            print errormsg
     3710            print '  ' + fname + ': Not enough data=', NoMask, 'to compute', Nquants,\
     3711              'quantiles !!'
     3712            quit(-1)
     3713        else:
     3714            quants = gen.fillValueF
    37053715    else:
    37063716        for iq in range(Nquants):
Note: See TracChangeset for help on using the changeset viewer.