# scipy 1.18.1 (BSD-3-Clause), harvested by tools/harvest_corpus.py
=== input

    Calculate the prominence of each peak in a signal.

    The prominence of a peak measures how much a peak stands out from the
    surrounding baseline of the signal and is defined as the vertical distance
    between the peak and its lowest contour line.

    Parameters
    ----------
    x : sequence
        A signal with peaks.
    peaks : sequence
        Indices of peaks in `x`.
    wlen : int, optional
        A window length in samples that optionally limits the evaluated area for
        each peak to a subset of `x`. The peak is always placed in the middle of
        the window therefore the given length is rounded up to the next odd
        integer. This parameter can speed up the calculation (see Notes).

    Returns
    -------
    prominences : ndarray
        The calculated prominences for each peak in `peaks`.
    left_bases, right_bases : ndarray
        The peaks' bases as indices in `x` to the left and right of each peak.
        The higher base of each pair is a peak's lowest contour line.

    Raises
    ------
    ValueError
        If a value in `peaks` is an invalid index for `x`.

    Warns
    -----
    PeakPropertyWarning
        For indices in `peaks` that don't point to valid local maxima in `x`,
        the returned prominence will be 0 and this warning is raised. This
        also happens if `wlen` is smaller than the plateau size of a peak.

    Warnings
    --------
    This function may return unexpected results for data containing NaNs. To
    avoid this, NaNs should either be removed or replaced.

    See Also
    --------
    find_peaks
        Find peaks inside a signal based on peak properties.
    peak_widths
        Calculate the width of peaks.

    Notes
    -----
    Strategy to compute a peak's prominence:

    1. Extend a horizontal line from the current peak to the left and right
       until the line either reaches the window border (see `wlen`) or
       intersects the signal again at the slope of a higher peak. An
       intersection with a peak of the same height is ignored.
    2. On each side find the minimal signal value within the interval defined
       above. These points are the peak's bases.
    3. The higher one of the two bases marks the peak's lowest contour line. The
       prominence can then be calculated as the vertical difference between the
       peaks height itself and its lowest contour line.

    Searching for the peak's bases can be slow for large `x` with periodic
    behavior because large chunks or even the full signal need to be evaluated
    for the first algorithmic step. This evaluation area can be limited with the
    parameter `wlen` which restricts the algorithm to a window around the
    current peak and can shorten the calculation time if the window length is
    short in relation to `x`.
    However, this may stop the algorithm from finding the true global contour
    line if the peak's true bases are outside this window. Instead, a higher
    contour line is found within the restricted window leading to a smaller
    calculated prominence. In practice, this is only relevant for the highest set
    of peaks in `x`. This behavior may even be used intentionally to calculate
    "local" prominences.

    .. versionadded:: 1.1.0

    References
    ----------
    .. [1] Wikipedia Article for Topographic Prominence:
       https://en.wikipedia.org/wiki/Topographic_prominence

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.signal import find_peaks, peak_prominences
    >>> import matplotlib.pyplot as plt

    Create a test signal with two overlaid harmonics

    >>> x = np.linspace(0, 6 * np.pi, 1000)
    >>> x = np.sin(x) + 0.6 * np.sin(2.6 * x)

    Find all peaks and calculate prominences

    >>> peaks, _ = find_peaks(x)
    >>> prominences = peak_prominences(x, peaks)[0]
    >>> prominences
    array([1.24159486, 0.47840168, 0.28470524, 3.10716793, 0.284603  ,
           0.47822491, 2.48340261, 0.47822491])

    Calculate the height of each peak's contour line and plot the results

    >>> contour_heights = x[peaks] - prominences
    >>> plt.plot(x)
    >>> plt.plot(peaks, x[peaks], "x")
    >>> plt.vlines(x=peaks, ymin=contour_heights, ymax=x[peaks])
    >>> plt.show()

    Let's evaluate a second example that demonstrates several edge cases for
    one peak at index 5.

    >>> x = np.array([0, 1, 0, 3, 1, 3, 0, 4, 0])
    >>> peaks = np.array([5])
    >>> plt.plot(x)
    >>> plt.plot(peaks, x[peaks], "x")
    >>> plt.show()
    >>> peak_prominences(x, peaks)  # -> (prominences, left_bases, right_bases)
    (array([3.]), array([2]), array([6]))

    Note how the peak at index 3 of the same height is not considered as a
    border while searching for the left base. Instead, two minima at 0 and 2
    are found in which case the one closer to the evaluated peak is always
    chosen. On the right side, however, the base must be placed at 6 because the
    higher peak represents the right border to the evaluated area.

    >>> peak_prominences(x, peaks, wlen=3.1)
    (array([2.]), array([4]), array([6]))

    Here, we restricted the algorithm to a window from 3 to 7 (the length is 5
    samples because `wlen` was rounded up to the next odd integer). Thus, the
    only two candidates in the evaluated area are the two neighboring samples
    and a smaller prominence is calculated.
    
=== parse numpydoc
short_description: 'Calculate the prominence of each peak in a signal.'
long_description: |
  The prominence of a peak measures how much a peak stands out from the
  surrounding baseline of the signal and is defined as the vertical distance
  between the peak and its lowest contour line.
blank_after_short_description: True
blank_after_long_description: True
style: numpydoc
- DocstringParam
  description: 'A signal with peaks.'
  kind: param
  key: 'param'
  arg_name: 'x'
  type_name: 'sequence'
  is_optional: False
- DocstringParam
  description: 'Indices of peaks in `x`.'
  kind: param
  key: 'param'
  arg_name: 'peaks'
  type_name: 'sequence'
  is_optional: False
- DocstringParam
  description: |
    A window length in samples that optionally limits the evaluated area for
    each peak to a subset of `x`. The peak is always placed in the middle of
    the window therefore the given length is rounded up to the next odd
    integer. This parameter can speed up the calculation (see Notes).
  kind: param
  key: 'param'
  arg_name: 'wlen'
  type_name: 'int'
  is_optional: True
  raw_type_name: 'int, optional'
- DocstringReturns
  description: 'The calculated prominences for each peak in `peaks`.'
  kind: returns
  key: 'returns'
  type_name: 'ndarray'
  is_generator: False
  return_name: 'prominences'
- DocstringReturns
  description: |
    The peaks' bases as indices in `x` to the left and right of each peak.
    The higher base of each pair is a peak's lowest contour line.
  kind: returns
  key: 'returns'
  type_name: 'ndarray'
  is_generator: False
  return_name: 'left_bases, right_bases'
- DocstringRaises
  description: 'If a value in `peaks` is an invalid index for `x`.'
  kind: raises
  key: 'raises'
  type_name: 'ValueError'
- DocstringRaises
  description: |
    For indices in `peaks` that don't point to valid local maxima in `x`,
    the returned prominence will be 0 and this warning is raised. This
    also happens if `wlen` is smaller than the plateau size of a peak.
  kind: warns
  key: 'warns'
  type_name: 'PeakPropertyWarning'
- DocstringMeta
  description: |
    This function may return unexpected results for data containing NaNs. To
    avoid this, NaNs should either be removed or replaced.
  kind: text
  key: 'warnings'
  title: 'Warnings'
- DocstringMeta
  description: |
    find_peaks
        Find peaks inside a signal based on peak properties.
    peak_widths
        Calculate the width of peaks.
  kind: text
  key: 'see_also'
  title: 'See Also'
- DocstringMeta
  description: |
    Strategy to compute a peak's prominence:
    
    1. Extend a horizontal line from the current peak to the left and right
       until the line either reaches the window border (see `wlen`) or
       intersects the signal again at the slope of a higher peak. An
       intersection with a peak of the same height is ignored.
    2. On each side find the minimal signal value within the interval defined
       above. These points are the peak's bases.
    3. The higher one of the two bases marks the peak's lowest contour line. The
       prominence can then be calculated as the vertical difference between the
       peaks height itself and its lowest contour line.
    
    Searching for the peak's bases can be slow for large `x` with periodic
    behavior because large chunks or even the full signal need to be evaluated
    for the first algorithmic step. This evaluation area can be limited with the
    parameter `wlen` which restricts the algorithm to a window around the
    current peak and can shorten the calculation time if the window length is
    short in relation to `x`.
    However, this may stop the algorithm from finding the true global contour
    line if the peak's true bases are outside this window. Instead, a higher
    contour line is found within the restricted window leading to a smaller
    calculated prominence. In practice, this is only relevant for the highest set
    of peaks in `x`. This behavior may even be used intentionally to calculate
    "local" prominences.
    
    .. versionadded:: 1.1.0
  kind: text
  key: 'notes'
  title: 'Notes'
- DocstringMeta
  description: |
    .. [1] Wikipedia Article for Topographic Prominence:
       https://en.wikipedia.org/wiki/Topographic_prominence
  kind: text
  key: 'references'
  title: 'References'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> import numpy as np'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> from scipy.signal import find_peaks, peak_prominences'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> import matplotlib.pyplot as plt'
- DocstringExample
  description: 'Create a test signal with two overlaid harmonics'
  kind: examples
  key: 'examples'
  snippet: '>>> x = np.linspace(0, 6 * np.pi, 1000)'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> x = np.sin(x) + 0.6 * np.sin(2.6 * x)'
- DocstringExample
  description: 'Find all peaks and calculate prominences'
  kind: examples
  key: 'examples'
  snippet: '>>> peaks, _ = find_peaks(x)'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> prominences = peak_prominences(x, peaks)[0]'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> prominences
    array([1.24159486, 0.47840168, 0.28470524, 3.10716793, 0.284603  ,
           0.47822491, 2.48340261, 0.47822491])
- DocstringExample
  description: "Calculate the height of each peak's contour line and plot the results"
  kind: examples
  key: 'examples'
  snippet: '>>> contour_heights = x[peaks] - prominences'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> plt.plot(x)'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> plt.plot(peaks, x[peaks], "x")'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> plt.vlines(x=peaks, ymin=contour_heights, ymax=x[peaks])'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> plt.show()'
- DocstringExample
  description: |
    Let's evaluate a second example that demonstrates several edge cases for
    one peak at index 5.
  kind: examples
  key: 'examples'
  snippet: '>>> x = np.array([0, 1, 0, 3, 1, 3, 0, 4, 0])'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> peaks = np.array([5])'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> plt.plot(x)'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> plt.plot(peaks, x[peaks], "x")'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> plt.show()'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> peak_prominences(x, peaks)  # -> (prominences, left_bases, right_bases)
    (array([3.]), array([2]), array([6]))
- DocstringExample
  description: |
    Note how the peak at index 3 of the same height is not considered as a
    border while searching for the left base. Instead, two minima at 0 and 2
    are found in which case the one closer to the evaluated peak is always
    chosen. On the right side, however, the base must be placed at 6 because the
    higher peak represents the right border to the evaluated area.
  kind: examples
  key: 'examples'
  snippet: |
    >>> peak_prominences(x, peaks, wlen=3.1)
    (array([2.]), array([4]), array([6]))
- DocstringExample
  description: |
    Here, we restricted the algorithm to a window from 3 to 7 (the length is 5
    samples because `wlen` was rounded up to the next odd integer). Thus, the
    only two candidates in the evaluated area are the two neighboring samples
    and a smaller prominence is calculated.
  kind: examples
  key: 'examples'
=== detect
numpydoc
=== compose numpydoc
Calculate the prominence of each peak in a signal.

The prominence of a peak measures how much a peak stands out from the
surrounding baseline of the signal and is defined as the vertical distance
between the peak and its lowest contour line.

Parameters
----------
x : sequence
    A signal with peaks.
peaks : sequence
    Indices of peaks in `x`.
wlen : int, optional
    A window length in samples that optionally limits the evaluated area for
    each peak to a subset of `x`. The peak is always placed in the middle of
    the window therefore the given length is rounded up to the next odd
    integer. This parameter can speed up the calculation (see Notes).

Returns
-------
prominences : ndarray
    The calculated prominences for each peak in `peaks`.
left_bases, right_bases : ndarray
    The peaks' bases as indices in `x` to the left and right of each peak.
    The higher base of each pair is a peak's lowest contour line.

Raises
------
ValueError
    If a value in `peaks` is an invalid index for `x`.

Warns
-----
PeakPropertyWarning
    For indices in `peaks` that don't point to valid local maxima in `x`,
    the returned prominence will be 0 and this warning is raised. This
    also happens if `wlen` is smaller than the plateau size of a peak.

Warnings
--------
This function may return unexpected results for data containing NaNs. To
avoid this, NaNs should either be removed or replaced.

See Also
--------
find_peaks
    Find peaks inside a signal based on peak properties.
peak_widths
    Calculate the width of peaks.

Notes
-----
Strategy to compute a peak's prominence:

1. Extend a horizontal line from the current peak to the left and right
   until the line either reaches the window border (see `wlen`) or
   intersects the signal again at the slope of a higher peak. An
   intersection with a peak of the same height is ignored.
2. On each side find the minimal signal value within the interval defined
   above. These points are the peak's bases.
3. The higher one of the two bases marks the peak's lowest contour line. The
   prominence can then be calculated as the vertical difference between the
   peaks height itself and its lowest contour line.

Searching for the peak's bases can be slow for large `x` with periodic
behavior because large chunks or even the full signal need to be evaluated
for the first algorithmic step. This evaluation area can be limited with the
parameter `wlen` which restricts the algorithm to a window around the
current peak and can shorten the calculation time if the window length is
short in relation to `x`.
However, this may stop the algorithm from finding the true global contour
line if the peak's true bases are outside this window. Instead, a higher
contour line is found within the restricted window leading to a smaller
calculated prominence. In practice, this is only relevant for the highest set
of peaks in `x`. This behavior may even be used intentionally to calculate
"local" prominences.

.. versionadded:: 1.1.0

References
----------
.. [1] Wikipedia Article for Topographic Prominence:
   https://en.wikipedia.org/wiki/Topographic_prominence

Examples
--------
>>> import numpy as np
>>> from scipy.signal import find_peaks, peak_prominences
>>> import matplotlib.pyplot as plt

Create a test signal with two overlaid harmonics

>>> x = np.linspace(0, 6 * np.pi, 1000)
>>> x = np.sin(x) + 0.6 * np.sin(2.6 * x)

Find all peaks and calculate prominences

>>> peaks, _ = find_peaks(x)
>>> prominences = peak_prominences(x, peaks)[0]
>>> prominences
array([1.24159486, 0.47840168, 0.28470524, 3.10716793, 0.284603  ,
       0.47822491, 2.48340261, 0.47822491])

Calculate the height of each peak's contour line and plot the results

>>> contour_heights = x[peaks] - prominences
>>> plt.plot(x)
>>> plt.plot(peaks, x[peaks], "x")
>>> plt.vlines(x=peaks, ymin=contour_heights, ymax=x[peaks])
>>> plt.show()

Let's evaluate a second example that demonstrates several edge cases for
one peak at index 5.

>>> x = np.array([0, 1, 0, 3, 1, 3, 0, 4, 0])
>>> peaks = np.array([5])
>>> plt.plot(x)
>>> plt.plot(peaks, x[peaks], "x")
>>> plt.show()
>>> peak_prominences(x, peaks)  # -> (prominences, left_bases, right_bases)
(array([3.]), array([2]), array([6]))

Note how the peak at index 3 of the same height is not considered as a
border while searching for the left base. Instead, two minima at 0 and 2
are found in which case the one closer to the evaluated peak is always
chosen. On the right side, however, the base must be placed at 6 because the
higher peak represents the right border to the evaluated area.

>>> peak_prominences(x, peaks, wlen=3.1)
(array([2.]), array([4]), array([6]))

Here, we restricted the algorithm to a window from 3 to 7 (the length is 5
samples because `wlen` was rounded up to the next odd integer). Thus, the
only two candidates in the evaluated area are the two neighboring samples
and a smaller prominence is calculated.
