def find_peaks_spectrum(sx, nwinwidth, threshold=0, debugplot=0):
    """Find peaks in array.

    The algorithm imposes that the signal at both sides of the peak
    decreases monotonically.

    Parameters
    ----------
    sx : 1d numpy array, floats
        Input array.
    nwinwidth : int
        Width of the window where each peak must be found.
    threshold : float
        Minimum signal in the peaks.
    debugplot : int
        Determines whether intermediate computations and/or plots
        are displayed:
        00 : no debug, no plots
        01 : no debug, plots without pauses
        02 : no debug, plots with pauses
        10 : debug, no plots
        11 : debug, plots without pauses
        12 : debug, plots with pauses

    Returns
    -------
    ixpeaks : 1d numpy array, int
        Peak locations, in array coordinates (integers).

    """

    if type(sx) is not np.ndarray:
        raise ValueError("sx=" + str(sx) + " must be a numpy.ndarray")
    elif sx.ndim is not 1:
        raise ValueError("sx.ndim=" + str(sx.ndim) + " must be 1")

    sx_shape = sx.shape
    nmed = nwinwidth//2

    if debugplot >= 10:
        print('find_peaks_spectrum> sx shape......:', sx_shape)
        print('find_peaks_spectrum> nwinwidth.....:', nwinwidth)
        print('find_peaks_spectrum> nmed..........:', nmed)
        print('find_peaks_spectrum> data_threshold:', threshold)
        print('find_peaks_spectrum> the first and last', nmed,
              'pixels will be ignored')

    xpeaks = []  # list to store the peaks
    
    if sx_shape[0] < nwinwidth:
        print('find_peaks_spectrum> sx shape......:', sx_shape)
        print('find_peaks_spectrum> nwinwidth.....:', nwinwidth)
        raise ValueError('sx.shape < nwinwidth')
    
    i = nmed
    while i < sx_shape[0] - nmed:
        if sx[i] > threshold:
            peak_ok = True
            j = 0
            loop = True
            while loop:
                if sx[i - nmed + j] > sx[i - nmed + j + 1]:
                    peak_ok = False
                j += 1
                loop = (j < nmed) and peak_ok
            if peak_ok:
                j = nmed + 1
                loop = True
                while loop:
                    if sx[i - nmed + j - 1] < sx[i - nmed + j]:
                        peak_ok = False
                    j += 1
                    loop = (j < nwinwidth) and peak_ok
            if peak_ok:
                xpeaks.append(i)
                i += nwinwidth - 1
            else:
                i += 1
        else:
            i += 1
    
    ixpeaks = np.array(xpeaks)

    if debugplot >= 10:
        print('find_peaks_spectrum> number of peaks found:', len(ixpeaks))
        print(ixpeaks)

    return ixpeaks
def find_peaks_spectrum ( sx , nwinwidth , threshold = 0 , debugplot = 0 ) : if type ( sx ) is not np . ndarray : raise ValueError ( "sx=" + str ( sx ) + " must be a numpy.ndarray" ) elif sx . ndim is not 1 : raise ValueError ( "sx.ndim=" + str ( sx . ndim ) + " must be 1" ) sx_shape = sx . shape nmed = nwinwidth // 2 if debugplot >= 10 : print ( 'find_peaks_spectrum> sx shape......:' , sx_shape ) print ( 'find_peaks_spectrum> nwinwidth.....:' , nwinwidth ) print ( 'find_peaks_spectrum> nmed..........:' , nmed ) print ( 'find_peaks_spectrum> data_threshold:' , threshold ) print ( 'find_peaks_spectrum> the first and last' , nmed , 'pixels will be ignored' ) xpeaks = [ ] if sx_shape [ 0 ] < nwinwidth : print ( 'find_peaks_spectrum> sx shape......:' , sx_shape ) print ( 'find_peaks_spectrum> nwinwidth.....:' , nwinwidth ) raise ValueError ( 'sx.shape < nwinwidth' ) i = nmed while i < sx_shape [ 0 ] - nmed : if sx [ i ] > threshold : peak_ok = True j = 0 loop = True while loop : if sx [ i - nmed + j ] > sx [ i - nmed + j + 1 ] : peak_ok = False j += 1 loop = ( j < nmed ) and peak_ok if peak_ok : j = nmed + 1 loop = True while loop : if sx [ i - nmed + j - 1 ] < sx [ i - nmed + j ] : peak_ok = False j += 1 loop = ( j < nwinwidth ) and peak_ok if peak_ok : xpeaks . append ( i ) i += nwinwidth - 1 else : i += 1 else : i += 1 ixpeaks = np . array ( xpeaks ) if debugplot >= 10 : print ( 'find_peaks_spectrum> number of peaks found:' , len ( ixpeaks ) ) print ( ixpeaks ) return ixpeaks
Find peaks in array.

    The algorithm imposes that the signal at both sides of the peak
    decreases monotonically.

    Parameters
    ----------
    sx : 1d numpy array, floats
        Input array.
    nwinwidth : int
        Width of the window where each peak must be found.
    threshold : float
        Minimum signal in the peaks.
    debugplot : int
        Determines whether intermediate computations and/or plots
        are displayed:
        00 : no debug, no plots
        01 : no debug, plots without pauses
        02 : no debug, plots with pauses
        10 : debug, no plots
        11 : debug, plots without pauses
        12 : debug, plots with pauses

    Returns
    -------
    ixpeaks : 1d numpy array, int
        Peak locations, in array coordinates (integers).