peak finding stuck at indexes in peak.py

Issue #18 resolved
Sen Wang created an issue

For cases where there is a flat signal, the package seems to get stuck at the while loop at line 46 in peak.py.

    while len(zeros):
        # add pixels 2 by 2 to propagate left and right value onto the zero-value pixel
        zerosr = np.hstack([dy[1:], 0.])
        zerosl = np.hstack([0., dy[:-1]])

        # replace 0 with right value if non zero
        dy[zeros]=zerosr[zeros]
        zeros,=np.where(dy == 0)

        # replace 0 with left value if non zero
        dy[zeros]=zerosl[zeros]
        zeros,=np.where(dy == 0)

Comments (9)

  1. eringong

    This seems to still be an issue for me. Not sure if it's getting stuck at the same while loop or elsewhere, but it's hanging when I run on data that is flat (all values = 0.037778). Verified the version I'm running is 1.1.0

  2. Colin Cooke

    Hey having the same issue here, a simple repro is:

    In [1]: import numpy as np
    
    In [2]: import peakutils
    
    In [3]: peakutils.indexes(-90*np.ones([1000]))
    

    obviously a pretty simple patch on my end (just do my own flat check) but would be nice to have it incorporated into the package.

    Thanks!

  3. Lucas Hermann Negri repo owner

    Hi,

    This is by design: there is no peak in the [1, 1, 1, 1, 1, 1, 1] array, for example (there aren't numbers before or after the ones, they are undefined and not just 0).

    However, notice that there is a peak in [1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1] array, it is just a 'flat' peak.

  4. Colin Cooke

    So I understand why there is no peak (its obviously flat), the issue is that it hangs -- as in blocks the entire program. I really hope that's not intended behavior....

    In my opinion it should either throw an exception or return an empty list. However of course the handling of this situation would be up to you

  5. Lucas Hermann Negri repo owner

    Hi,

    It indeed returns an empy list:

    >>> import numpy as np
    >>> import peakutils   
    >>> print(peakutils.__version__)
    1.1.0
    >>> peakutils.indexes(-90*np.ones([1000]))
    array([], dtype=float64)
    

    Can you try with git HEAD? Thanks.

  6. Colin Cooke

    As far as I can tell there is nothing new since 1.1.0(?) so we should be running the same code. Seems weird it works for you. Here are the versions of the libs:

    Python 3.6.1 |Anaconda custom (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)]
    Type "copyright", "credits" or "license" for more information.
    
    IPython 5.3.0 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.
    
    In [1]: import numpy as np
    
    In [2]: import scipy
    
    In [3]: import peakutils
    
    In [4]: np.__version__
    Out[4]: '1.13.1'
    
    In [5]: scipy.__version__
    Out[5]: '0.19.1'
    
    In [6]: peakutils.__version__
    Out[6]: '1.1.0'
    
    In [7]: peakutils.indexes(np.ones([1000]))
    

    which then hangs at [7], waited a minute just to be sure.

    No idea why it would work for you and not for me

  7. Lucas Hermann Negri repo owner

    Interesting. Can you try it with git HEAD? I may have fixed it but not released the change to the CheeseShop yet.

  8. Log in to comment