Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python35
/
lib64
/
python3.5
/
site-packages
/
scipy
/
signal
/
__pycache__
/
File Content:
_peak_finding.cpython-35.pyc
DB�W�E � @ s d Z d d l m Z m Z m Z d d l Z d d l m Z d d l m Z m Z d d l m Z d d d d g Z d d d d d � Z d d d d d � Z d d d d d � Z d d d d d � Z d d � Z d d d d d d � Z d d d d d d d d � Z d S)z- Functions for identifying peaks in signals. � )�division�print_function�absolute_importN)�xrange)�cwt�ricker)�scoreatpercentile� argrelmin� argrelmax� argrelextrema�find_peaks_cwt� Zclipc C s t | � | k s | d k r* t d � � | j | } t j d | � } t j | j d t �} | j | d | d | �} x� t d | d � D]{ } | j | | d | d | �} | j | | d | d | �} | | | | � M} | | | | � M} | j � r� | Sq� W| S)a� Calculate the relative extrema of `data`. Relative extrema are calculated by finding locations where ``comparator(data[n], data[n+1:n+order+1])`` is True. Parameters ---------- data : ndarray Array in which to find the relative extrema. comparator : callable Function to use to compare two data points. Should take 2 numbers as arguments. axis : int, optional Axis over which to select from `data`. Default is 0. order : int, optional How many points on each side to use for the comparison to consider ``comparator(n,n+x)`` to be True. mode : str, optional How the edges of the vector are treated. 'wrap' (wrap around) or 'clip' (treat overflow as the same as the last (or first) element). Default 'clip'. See numpy.take Returns ------- extrema : ndarray Boolean array of the same shape as `data` that is True at an extrema, False otherwise. See also -------- argrelmax, argrelmin Examples -------- >>> testdata = np.array([1,2,3,2,1]) >>> _boolrelextrema(testdata, np.greater, axis=0) array([False, False, True, False, False], dtype=bool) r zOrder must be an int >= 1r Zdtype�axis�mode) �int� ValueError�shape�np�arangeZones�boolZtaker �any)�data� comparatorr �orderr ZdatalenZlocs�results�mainZshiftZplusZminus� r �/_peak_finding.py�_boolrelextrema s ) r c C s t | t j | | | � S)a~ Calculate the relative minima of `data`. Parameters ---------- data : ndarray Array in which to find the relative minima. axis : int, optional Axis over which to select from `data`. Default is 0. order : int, optional How many points on each side to use for the comparison to consider ``comparator(n, n+x)`` to be True. mode : str, optional How the edges of the vector are treated. Available options are 'wrap' (wrap around) or 'clip' (treat overflow as the same as the last (or first) element). Default 'clip'. See numpy.take Returns ------- extrema : tuple of ndarrays Indices of the minima in arrays of integers. ``extrema[k]`` is the array of indices of axis `k` of `data`. Note that the return value is a tuple even when `data` is one-dimensional. See Also -------- argrelextrema, argrelmax Notes ----- This function uses `argrelextrema` with np.less as comparator. .. versionadded:: 0.11.0 Examples -------- >>> from scipy.signal import argrelmin >>> x = np.array([2, 1, 2, 3, 2, 0, 1, 0]) >>> argrelmin(x) (array([1, 5]),) >>> y = np.array([[1, 2, 1, 2], ... [2, 2, 0, 0], ... [5, 3, 4, 4]]) ... >>> argrelmin(y, axis=1) (array([0, 2]), array([2, 1])) )r r Zless)r r r r r r r r K s 2c C s t | t j | | | � S)a~ Calculate the relative maxima of `data`. Parameters ---------- data : ndarray Array in which to find the relative maxima. axis : int, optional Axis over which to select from `data`. Default is 0. order : int, optional How many points on each side to use for the comparison to consider ``comparator(n, n+x)`` to be True. mode : str, optional How the edges of the vector are treated. Available options are 'wrap' (wrap around) or 'clip' (treat overflow as the same as the last (or first) element). Default 'clip'. See `numpy.take`. Returns ------- extrema : tuple of ndarrays Indices of the maxima in arrays of integers. ``extrema[k]`` is the array of indices of axis `k` of `data`. Note that the return value is a tuple even when `data` is one-dimensional. See Also -------- argrelextrema, argrelmin Notes ----- This function uses `argrelextrema` with np.greater as comparator. .. versionadded:: 0.11.0 Examples -------- >>> from scipy.signal import argrelmax >>> x = np.array([2, 1, 2, 3, 2, 0, 1, 0]) >>> argrelmax(x) (array([3, 6]),) >>> y = np.array([[1, 2, 1, 2], ... [2, 2, 0, 0], ... [5, 3, 4, 4]]) ... >>> argrelmax(y, axis=1) (array([0]), array([1])) )r r �greater)r r r r r r r r � s 1c C s% t | | | | | � } t j | � S)a� Calculate the relative extrema of `data`. Parameters ---------- data : ndarray Array in which to find the relative extrema. comparator : callable Function to use to compare two data points. Should take 2 numbers as arguments. axis : int, optional Axis over which to select from `data`. Default is 0. order : int, optional How many points on each side to use for the comparison to consider ``comparator(n, n+x)`` to be True. mode : str, optional How the edges of the vector are treated. 'wrap' (wrap around) or 'clip' (treat overflow as the same as the last (or first) element). Default is 'clip'. See `numpy.take`. Returns ------- extrema : tuple of ndarrays Indices of the maxima in arrays of integers. ``extrema[k]`` is the array of indices of axis `k` of `data`. Note that the return value is a tuple even when `data` is one-dimensional. See Also -------- argrelmin, argrelmax Notes ----- .. versionadded:: 0.11.0 Examples -------- >>> from scipy.signal import argrelextrema >>> x = np.array([2, 1, 2, 3, 2, 0, 1, 0]) >>> argrelextrema(x, np.greater) (array([3, 6]),) >>> y = np.array([[1, 2, 1, 2], ... [2, 2, 0, 0], ... [5, 3, 4, 4]]) ... >>> argrelextrema(y, np.less, axis=1) (array([0, 2]), array([2, 1])) )r r �where)r r r r r r r r r r � s 3 c s� t | � | j d k r% t d � � t | t j d d d d �} t j | j d d � � d } t | � d k rx g S| d � � f d d � t j | � � d D� } g } t j � d d d � } t j d | j d � } x~| D]v} | | | } x | D] } | d d 7<qWt j d d � | D� � } x� t | � D]� \ } } d } t | � d k r�t j | | � } t j | � } | | | | k r�| | } | d k r�| d j | � | d j | � d | d <qG| g | g d g } | j | � qGWxR t t | � d d d � D]4 } | | } | d | k r)| j | � | | =q)Wq� Wg } x| | | D]p } t j t j | d � � } t j | � t j | � } } | d | | <| d | | <| j | | g � qvW| S)a� Identify ridges in the 2-D matrix. Expect that the width of the wavelet feature increases with increasing row number. Parameters ---------- matr : 2-D ndarray Matrix in which to identify ridge lines. max_distances : 1-D sequence At each row, a ridge line is only connected if the relative max at row[n] is within `max_distances`[n] from the relative max at row[n+1]. gap_thresh : int If a relative maximum is not found within `max_distances`, there will be a gap. A ridge line is discontinued if there are more than `gap_thresh` points without connecting a new relative maximum. Returns ------- ridge_lines : tuple Tuple of 2 1-D sequences. `ridge_lines`[ii][0] are the rows of the ii-th ridge-line, `ridge_lines`[ii][1] are the columns. Empty if none found. Each ridge-line will be sorted by row (increasing), but the order of the ridge lines is not specified. References ---------- Bioinformatics (2006) 22 (17): 2059-2065. doi: 10.1093/bioinformatics/btl355 http://bioinformatics.oxfordjournals.org/content/22/17/2059.long Examples -------- >>> data = np.random.rand(5,5) >>> ridge_lines = _identify_ridge_lines(data, 1, 1) Notes ----- This function is intended to be used in conjunction with `cwt` as part of `find_peaks_cwt`. r z5Max_distances must have at least as many rows as matrr r r c s% g | ] } � g | g d g � q S)r r )�.0�col)� start_rowr r � <listcomp>& s z)_identify_ridge_lines.<locals>.<listcomp>� c S s g | ] } | d d � q S)r ���r )r! �liner r r r$ 7 s Nr&