U
    Hvf                     @   s
  d dl Z d dlZd dlmZmZmZmZ d dlZd dlm	Z	m
Z
 d dlmZmZmZmZmZmZmZmZ d dlmZ d dlmZmZ dd Zd	d
 Zdd ZG dd dZG dd dZG dd dZG dd dZG dd dZ dd Z!G dd dZ"G dd dZ#dS )    N)assert_assert_equalassert_allcloseassert_array_equal)raiseswarns)	argrelmax	argrelminpeak_prominencespeak_widths_unpack_condition_args
find_peaksfind_peaks_cwt_identify_ridge_lines)gaussian)_local_maxima_1dPeakPropertyWarningc                 C   sZ   t d|t}t j|td}t|D ],\}}|| |  | }|t |d  7 }q(|S )Nr   dtype   )nparangeastypefloatzeros	enumerateexp)center_locssigmastotal_lengthZxdataout_dataindsigmatmp r$   H/tmp/pip-unpacked-wheel-96ln3f52/scipy/signal/tests/test_peak_finding.py_gen_gaussians   s    r&   c                 C   sB   t | }||d  }tj||| |dt}t|| |}||fS )N   )num)lenr   linspacer   intr&   )r   r   Z	num_peaksdeltar   r    r$   r$   r%   _gen_gaussians_even$   s
    r-   c                 C   s^  dd }t |}t |}tj|dgtd}| |dddf< |d | d  t| }||k rftd|t| d }|t| d }	td|D ]}
||
d df }||
d df d }|
| dkrt|dkr|d	|
 |	  7 }|
|	 dkrt|dkr||	 7 }|||d }|||d }||g||
ddf< q|dddf |dddf gS )
a  
    Generate coordinates for a ridge line.

    Will be a series of coordinates, starting a start_loc (length 2).
    The maximum distance between any adjacent columns will be
    `max_distance`, the max distance between adjacent rows
    will be `map_gap'.

    `max_locs` should be the size of the intended matrix. The
    ending coordinates are guaranteed to be less than `max_locs`,
    although they may not approach `max_locs` at all.
    c                 S   s   t | d}t||}|S )Nr   )maxmin)r(   Zmax_valoutr$   r$   r%   keep_bounds:   s    

z$_gen_ridge_line.<locals>.keep_boundsr   r   r   Nz3Cannot generate ridge line according to constraintsr'   )
copydeepcopyr   r   r+   sum
ValueErrorr)   rangepop)Z
start_locsZmax_locslength	distancesgapsr1   Zlocsr   Zdist_intZgap_intr!   ZnextcolZnextrowr$   r$   r%   _gen_ridge_line,   s*    

r<   c                   @   s   e Zd Zdd Zdd Zdd Zdd Zej	d	e
d
ddge
dddddge
dddddddggdd Zdd ZdS )TestLocalMaxima1dc                 C   s@   t jg t jd}t|D ]"}t|t g  t|jdk qdS )zTest with empty signal.r   N)r   arrayfloat64r   r   r   baseselfxr>   r$   r$   r%   
test_emptyY   s    zTestLocalMaxima1d.test_emptyc                 C   s<   t dd}t|D ]"}t|t g  t|jdk qdS )zTest with linear signal.r   d   N)r   r*   r   r   r>   r   r@   rA   r$   r$   r%   test_linear`   s    zTestLocalMaxima1d.test_linearc                 C   s\   t ddd}|ddd  d7  < t ddd}t|D ]}t|| t|jdk q:dS )zTest with simple signal.
   2   r   N   r'   )r   r*   r   r   r   r   r@   )rB   rC   expectedr>   r$   r$   r%   test_simpleg   s    
zTestLocalMaxima1d.test_simplec                 C   s   t ddddddddddddddddd	d	d	d	d	dg}t|\}}}t|t ddd
ddg t|t dddddg t|t dddddg dS )z+Test if flat maxima are detected correctly.gr   r'   r   rJ   gQ@   rG                        	         N)r   r>   r   r   )rB   rC   Z	midpoints
left_edgesright_edgesr$   r$   r%   test_flat_maximar   s    $     z"TestLocalMaxima1d.test_flat_maximarC         ?r   r         @rJ   rM         @rU      c                 C   s0   t |D ]"}t|tg  t|jdk qdS )z,Test if behavior on signal edges is correct.N)r   r   r   r>   r   r@   rA   r$   r$   r%   test_signal_edges{   s    z#TestLocalMaxima1d.test_signal_edgesc              	   C   s   t tdd ttd W 5 Q R X t tdd ttjdtd W 5 Q R X t tdd tdd	g W 5 Q R X t td
d td W 5 Q R X dS )z,Test input validation and raised exceptions.zwrong number of dimensionsmatch)r'   r'   zexpected 'const float64_t'r'   r   listr\          @z'x' must not be NoneN)r   r6   r   r   onesr+   	TypeErrorrB   r$   r$   r%   test_exceptions   s    z!TestLocalMaxima1d.test_exceptionsN)__name__
__module____qualname__rD   rF   rL   r[   pytestmarkparametrizer   r>   r`   rh   r$   r$   r$   r%   r=   W   s   	
r=   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestRidgeLinesc                 C   s6   t ddg}t|t ddd}tt|dk d S )NrX   rE   r   r'   r   r   r   r   fullr   r)   rB   	test_matrlinesr$   r$   r%   rD      s    zTestRidgeLines.test_emptyc                 C   s   t ddg}d|d< t|t ddd}tt|dk t ddg}d|dddf< t|t ddd}tt|dk d S )NrX   rE   r'   )r   rH   r   r   rH   rp   rr   r$   r$   r%   test_minimal   s    zTestRidgeLines.test_minimalc                 C   s   ddddg}dddddg}t ddgd }d}tdd	g|j|||}d||d |d f< t dt|}t||t|d }t||g d S )
Nr   r'   r   rU   rX   rI   g-q=rP      )r   r   r<   shaperq   r.   r   r   )rB   r:   r;   rs   r9   linemax_distancesidentified_linesr$   r$   r%   test_single_pass   s    zTestRidgeLines.test_single_passc                 C   s   ddddg}ddddg}t ddg}d}tdd	g|j|||}d||d |d f< d
}t d|}t||t|d }tt|dk |D ]P}	t 	|	d }
t j
t |
| t 	|	d }t j
t |t|d  qd S )Nr   r'   r   rU   rM   rX   rI   rP   rv   rJ   皙?)r   r   r<   rw   rq   r   r.   r   r)   difftestingassert_array_lessabs)rB   r:   r;   rs   r9   rx   max_distry   rz   ilineadistsagapsr$   r$   r%   test_single_bigdist   s    z"TestRidgeLines.test_single_bigdistc                 C   s   ddddg}d}ddddg}t ddg}d	}tdd
g|j|||}d||d |d f< d}t d|}t|||}	tt|	dk |	D ]P}
t |
d }t j	
t || t |
d }t j	
t |t|d  qd S )Nr   r'   r   rU   rJ   rM   rX   rI   rP   rv   r_   r|   r   r   r<   rw   rq   r   r   r)   r}   r~   r   r   r.   rB   r:   Zmax_gapr;   rs   r9   rx   r   ry   rz   r   r   r   r$   r$   r%   test_single_biggap   s     z!TestRidgeLines.test_single_biggapc                 C   s   dg}d}ddg}t ddg}d}tddg|j|||}d||d |d f< d}t d|}t|||}	tt|	dk |	D ]P}
t |
d }t j	
t || t |
d }t j	
t |t|d  q~d S )	Nr   r'   rJ   r_   rI      rv   r|   r   r   r$   r$   r%   test_single_biggaps   s     z"TestRidgeLines.test_single_biggapsN)	ri   rj   rk   rD   ru   r{   r   r   r   r$   r$   r$   r%   ro      s   ro   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )

TestArgrelc                 C   s   t jg td}t d}t|}tt|d t|d | t d}t|dd\}}t|| t|| t|dd\}}t|| t|| d S )Nr   rU   r'   r   )rJ   rU   axis)r   r>   r+   r   r	   r   r)   r   )rB   Zempty_arrayZz1iZz2rowcolr$   r$   r%   rD      s    




zTestArgrel.test_emptyc                 C   sR  t dddddgdddddgdddddgdddddgdddddgg}t|dd\}}t |}t|| dddg t|| dddg t|dd\}}t |}t|| dddg t|| dddg t|dd\}}t |}t|| dddg t|| dddg t|dd\}}t |}t|| dddg t|| dddg d S )Nr'   r   rJ   r   r   rM   )r   r>   r   Zargsortr   r	   )rB   rC   r   r   orderr$   r$   r%   
test_basic  s,    



zTestArgrel.test_basicc                 C   s   d}dddddg}t |d\}}|| d ||| < || d ||| < t||d	d
d }tt|t|k t||k  d S )Nr   r\   rd         $@r^   g      .@  gwJ?Zclip)r   moder   )r-   r   r   r)   all)rB   r   r   	test_dataact_locsZrel_max_locsr$   r$   r%   test_highorder'  s    zTestArgrel.test_highorderc                 C   s   dddg}t |d\}}d}tdt|| }t||| g}t|ddd\}}td|jd D ]@}	||	k}
tt||
 t|k t|||
 ||	  k	  qdd S )	Nr\   rd   r   rE   rX   r   r'   )r   r   )
r-   r   r   r)   Zvstackr   r7   rw   r   r   )rB   r   r   r   Z
rot_factorZ	rot_rangeZtest_data_2Zrel_max_rowsZrel_max_colsrwZindsr$   r$   r%   test_2d_gaussians2  s    
zTestArgrel.test_2d_gaussiansN)ri   rj   rk   rD   r   r   r   r$   r$   r$   r%   r      s   r   c                   @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )TestPeakProminencesc                 C   s   t dddgg }t|tjtjtjgD ]$\}}t|jdk t|j|k q&t g g }t|tjtjtjgD ]$\}}t|jdk t|j|k qldS )N
        Test if an empty array is returned if no peaks are provided.
        r'   r   rJ   r   N)r
   zipr   r?   intpr   sizer   )rB   r0   arrr   r$   r$   r%   rD   C  s    
zTestPeakProminences.test_emptyc              
   C   s   t ddddddddg}t ddd	d
g}t ddddg}t ddddg}|| t j|| || gdd }t||}t|d | t|d | t|d | dS )z
        Test if height of prominences is correctly calculated in signal with
        rising baseline (peak widths are 1 sample).
        r2   g333333?r'   皙	@g?g
ףp=
@g @r   rM   r_   r   rU   rJ   rR   r   N)r   r>   r.   r
   r   )rB   rC   peakslbasesrbasespromsr0   r$   r$   r%   r   Q  s    "
zTestPeakProminences.test_basicc                 C   s   dddddddg}dddg}t ||\}}}t|dddg t|dddg t|dddg dddddddg}tdddg}t ||\}}}t|dddg t||d  t||d  dS )z"
        Test edge cases.
        r   r   r'   rJ   rU   r_   N)r
   r   r   r>   rB   rC   r   r   r   r   r$   r$   r%   test_edge_casesb  s    
z#TestPeakProminences.test_edge_casesc                 C   s   t ddddddgd}t dddgd}t|ddd |ddd \}}}t|dddg t|dddg t|ddd	g dS )
:
        Test with non-C-contiguous input arrays.
        irV   r   rJ   r'   r   rM   NrU   )r   repeatr
   r   r   r$   r$   r%   test_non_contiguousv  s    $z'TestPeakProminences.test_non_contiguousc                 C   sd   dddddddg}dg}t t||dddg dD ],\}}t t|||d| d| d| g q2d	S )
zO
        Test if wlen actually shrinks the evaluation range correctly.
        r   r'   r   rJ   r2   r]   r_   ))rO   r   )rR   r   )r_   r   )rU   r'   )r   r'   rJ   r   )皙?r   N)r   r
   )rB   rC   peakwlenr   r$   r$   r%   	test_wlen  s
    zTestPeakProminences.test_wlenc              
   C   s>  t tdd tddddggddg W 5 Q R X t tdd tddddgddgg W 5 Q R X t tdd tddg W 5 Q R X t tdd tg dg W 5 Q R X dD ].}t tdd tdddg|g W 5 Q R X qt td	d tddddgd
dg W 5 Q R X t tdd ttdddgdd W 5 Q R X dS )zA
        Verify that exceptions and warnings are raised.
        	1-D arrayra   r   r'   r   rJ   not a valid index)ir2   rJ     cannot safely castr   ffffff@r   rH   rU   r   N)r   r6   r
   rf   r   r   )rB   pr$   r$   r%   rh     s    "" z#TestPeakProminences.test_exceptionsc              
   C   sn   d}dD ].}t t|d tdddg|g W 5 Q R X qt t|d  tdddddgdgdd W 5 Q R X dS )	>
        Verify that appropriate warnings are raised.
        z!some peaks have a prominence of 0)r   r'   r   ra   r'   r   r   r   N)r   r   r
   )rB   msgr   r$   r$   r%   test_warnings  s    z!TestPeakProminences.test_warningsN)
ri   rj   rk   rD   r   r   r   r   rh   r   r$   r$   r$   r%   r   A  s   r   c                   @   s\   e Zd Zdd Zejddd Zdd Zdd	 Z	d
d Z
dd Zejddd ZdS )TestPeakWidthsc                 C   s   t g g d }tt|tj t|jd t dddgg d }tt|tj t|jd t g g }|D ] }tt|tj t|jd qhdS )r   r   r'   r   rJ   N)r   r   
isinstancer   Zndarrayr   r   )rB   widthsr0   r   r$   r$   r%   rD     s    
zTestPeakWidths.test_empty#ignore:some peaks have a width of 0c              	   C   sx   t dddddddg}d}dD ]R\}}}}t|dg|\}}}	}
t|| t|d||   t|	| t|
| q dS )zk
        Test a simple use case with easy to verify results at different relative
        heights.
        r'   r   r   r2   ))        r   r]   r]   )g      ?r\         @      @)      ?rd   rd         @)      ?r]         ?      @)r\   r   r\   r^   )rd   r^   r\         @)r]   r^   r\   r   rJ   N)r   r>   r   r   )rB   rC   
prominence
rel_heightZ
width_trueZlip_trueZrip_trueZ
width_calcheightZlip_calcZrip_calcr$   r$   r%   r     s    	  

zTestPeakWidths.test_basicc                 C   sT   t dddgd}t dgd}t|ddd |ddd }t|dd	dd
g dS )r   r   rE   rI   rM   r'   rJ   Nr   K   r   )r   r   r   r   )rB   rC   r   resultr$   r$   r%   r     s    z"TestPeakWidths.test_non_contiguousc              	   C   s  t tdd ttdtd W 5 Q R X t tdd tddg W 5 Q R X t tdd" ttdtjdtjd W 5 Q R X t tdd ttdd W 5 Q R X t td	d ttdd
dg W 5 Q R X t td	d tg ddg W 5 Q R X t tdd ttdddg W 5 Q R X t tdd" tdddddgddgdd W 5 Q R X t tdd tdddgdgdd W 5 Q R X dS )zD
        Verify that argument validation works as intended.
        r   ra   )rJ   rM   rJ   r   rH   r   r   r   rO   rS   r'   r   r   r   r   r   r2   r   None)NNNprominence_dataN)	r   r6   r   r   r   re   r   r   rf   rg   r$   r$   r%   rh     s$     &&zTestPeakWidths.test_exceptionsc              
   C   s   d}t t|d tdddgdgdd W 5 Q R X t t|dJ tdddddgdgtdgtjtdgtjtdgtjfd W 5 Q R X d	S )
r   zsome peaks have a width of 0ra   r   r'   r   r   r   r   N)r   r   r   r   r>   r?   r   )rB   r   r$   r$   r%   r     s      zTestPeakWidths.test_warningsc           	   
   C   s   dddg}dg}t ddddddd	gD ]t\}\}}}tj|tjd
tj|tjd
tj|tjd
f}|dk rpd}nd}tt|d t|||d W 5 Q R X q&dS )z4Test with mismatching peak and / or prominence data.r   r'   )r\   )r2   r   )r   r   )rJ   )r   r   r   )r\   r\   r   r   r   r   )r   r   r   )r   r   r   )r   r   r   r   rJ   z#prominence data is invalid for peakz4arrays in `prominence_data` must have the same shapera   r   N)r   r   r>   r?   r   r   r6   r   )	rB   rC   r   r   prominences
left_basesright_basesr   rb   r$   r$   r%    test_mismatching_prominence_data  s(    

z/TestPeakWidths.test_mismatching_prominence_datac                 C   sZ   dddddddddddg}t t|dgddddd	d	g t t|dgd
dddddg dS )z3Test if x == eval_height counts as an intersection.r   r'   r   rJ   rU   )r   r   )r   )r]   )r^   gUUUUUU?)r   r   )g      @N)r   r   )rB   rC   r$   r$   r%   test_intersection_rules2  s    

z&TestPeakWidths.test_intersection_rulesN)ri   rj   rk   rD   rl   rm   filterwarningsr   r   rh   r   r   r   r$   r$   r$   r%   r     s   

	 
r   c               	   C   s  t d} | }|d }|ddd }tdtd| |k tdtd| |k tdtd| |k tdtd| |k tdtd| |k t||f| |\}}t|||  t|||  ttd	d
 t|t d| W 5 Q R X ttdd
 td|ft d| W 5 Q R X dS )zW
    Verify parsing of condition arguments for `scipy.signal.find_peaks` function.
    rH   r'   Nr   NN)r'   NNr   )r]   r   zarray size of lowerra   rS   zarray size of upper)r   r   r   r   r   r   r6   )rC   Z	amin_trueZ	amax_truer   Z	amin_calcZ	amax_calcr$   r$   r%   test_unpack_condition_args?  s     
r   c                
   @   s   e Zd Zddddddddd	d
h
Zdd Zdd Zdd Zdd Zdd Zdd Z	dd Z
dd Zdd Zejdddd  Zejd!i d"d#id$d%id&d'igd(d) Zd*S )+TestFindPeakspeak_heightsleft_thresholdsright_thresholdsr   r   r   r   width_heightsleft_ips	right_ipsc                 C   sP   d}t td||||d\}}t|jdk | jD ]}t|| jdk q4dS )z@
        Test behavior for signal without local maxima.
        r   rH   r   	thresholdr   widthr   N)r   r   re   r   r   property_keys)rB   open_intervalr   propskeyr$   r$   r%   test_constantb  s    
  

zTestFindPeaks.test_constantc              	   C   s,  t dddddddg}t |jd d }||ddd< t j|jtd	}|ddd |ddd< t ||}t|d
d\}}t|dddddddg t|d | t|d ||d d   t|d ||d   tt|ddd ddddg tt|ddd dddg tt|ddd ddg dS )z8
        Test plateau size condition for peaks.
        r'   r   rJ   rM   rO   rX   o   Nr   r   )Zplateau_sizerR   rS   rQ   !   rE   plateau_sizesrY   rZ   r   )Nr   )rU   rI   )	r   r>   r   r   re   r+   r   r   r   )rB   r   rC   Zrepeatsr   r   r$   r$   r%   test_plateau_sizen  s    zTestFindPeaks.test_plateau_sizec                 C   s   d}t |dd\}}t|tdddg t|d tdd	d
g tt |ddd tddg tt |ddd tddg tt |ddd tdg dS )z2
        Test height condition for peaks.
        )r   UUUUUU?r   r   r   r   r   r   )r   r'   rJ   rU   r   r   r   r   r   r   )NrJ   )r   rJ   Nr   r   r   r>   rB   rC   r   r   r$   r$   r%   test_height_condition  s      z#TestFindPeaks.test_height_conditionc                 C   s   d}t |dd\}}t|tddg t|d tddg t|d tdd	g tt |ddd
 tdg tt |ddd
 tg  tt |ddd
 tddg tt |ddd
 tdg tt |ddd
 tg  dS )z5
        Test threshold condition for peaks.
        )r   r   r'   rM   r2   r   )r   r'   rJ   r   r   r   rU   r   r   )NrU   )NrM   )r   rM   Nr   r   r$   r$   r%   test_threshold_condition  s     z&TestFindPeaks.test_threshold_conditionc                 C   s   t ddd}t d}||  t dd|j7  < tt|ddd | t|ddd }tt j||dd	jdk tt 	|d
 dddddg}t|ddd }t|jdko|d dk dS )z4
        Test distance condition for peaks.
        r'      rJ   r   distancer   g9m4 @T)Zassume_uniquer_   r2   rH   N)
r   r   r   r*   r   r   r   r   Z	setdiff1dr}   )rB   Z	peaks_allrC   Zpeaks_subsetr$   r$   r%   test_distance_condition  s    
z%TestFindPeaks.test_distance_conditionc           	      C   s   t ddd}t ddd}t dd|j}||  |7  < || ||d   }d}t |d |k||d k@ }t||d\}}t|||  t|d	 ||  t|d
 d t|d || d  dS )z6
        Test prominence condition for peaks.
        r   rH   rE   r'   c   r   )rJ   rV   )r   r   r   r   N)r   r*   r   r   Znonzeror   r   )	rB   rC   Z
peaks_trueoffsetr   intervalZkeepZ
peaks_calcZ
propertiesr$   r$   r%   test_prominence_condition  s    z'TestFindPeaks.test_prominence_conditionc                 C   s   t dddddddddg	}t|ddd\}}t|jd t|d	 t|d
 d t|d d t|d d t|d d dS )z1
        Test width condition for peaks.
        r'   r   r   r2   rM   r   r   )r   r   rR   r   g?r   r\   r   g@r   g      @N)r   r>   r   r   r   r   r   r$   r$   r%   test_width_condition  s    
z"TestFindPeaks.test_width_conditionc              
   C   sl   d}ddddddddddg
}t |||||d	\}}tt|t| jk | jD ]}t|j|| jk qNd
S )z+
        Test returned properties.
        r   r   r'   r   r   rJ   rU   rV   r   N)r   r   r)   r   r   )rB   r   rC   r   r   r   r$   r$   r%   test_properties  s      

zTestFindPeaks.test_propertiesc              	   C   sz   t tdd ttd W 5 Q R X t tdd ttd W 5 Q R X t tdd ttddd W 5 Q R X d	S )
z5
        Test exceptions raised by function.
        r   ra   r'   r   r   rH   r2   r   N)r   r6   r   r   r>   re   r   rg   r$   r$   r%   test_raises  s    zTestFindPeaks.test_raisesz(ignore:some peaks have a prominence of 0r   c                 C   sn   t dddddgdddd\}}t|d t|d d t|d d t|d d d	D ]}t|| | qVd
S )z
        Test behavior of prominence and width calculation if the given window
        length is smaller than a peak's plateau size.

        Regression test for gh-9110.
        r   r'   r   r   )r   r   r   r   r   r   )r   r   r   r   N)r   r   )rB   r   r   r   r$   r$   r%   test_wlen_smaller_plateau  s    	 

z'TestFindPeaks.test_wlen_smaller_plateaukwargsr   r]   r   r   r   r   c                 C   sH   t ddd}| }d|j_t|\}}t|f|\}}t|| dS )z4
        Test readonly arrays are accepted.
        r   rH      FN)r   r*   r3   flagsZ	writeabler   r   )rB   r  rC   Z
x_readonlyr   _Zpeaks_readonlyr$   r$   r%   test_readonly_array  s    z!TestFindPeaks.test_readonly_arrayN)ri   rj   rk   r   r   r   r   r   r   r  r  r  r  rl   rm   r   r  rn   r
  r$   r$   r$   r%   r   [  s:        
r   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestFindPeaksCwtc                 C   sX   ddddddg}d}t ||\}}tdt|}t||dd	d
d}tj||d d
S )zX
        Generate a series of gaussians and attempt to find the peak locations.
        r^   r]   r         4@      I@r   r|   r   r   N)
gap_threshmin_snr
min_lengthz4Found maximum locations did not equal those expected)r-   r   r   r.   r   r~   r   )rB   r   
num_pointsr   r   r   
found_locsr$   r$   r%   test_find_peaks_exact  s    

z&TestFindPeaksCwt.test_find_peaks_exactc           
      C   s   ddddddg}d}t ||\}}tdt|}d}tjd	 |tj|d
 d|  7 }t||dd|d d}tj	t
|t
|d t|| }t|d }	tj||	dd|	   dS )zz
        Verify that peak locations are (approximately) found
        for a series of gaussians with added noise.
        r^   r]   r   r  r  r   r|   gQ?or   r   r  r'   rU   )r  r  r  z,Different numberof peaks found than expectedzMaximum location differedzby more than %sN)r-   r   r   r.   randomseedrandr   r~   r   r)   r   r>   r   )
rB   r   r  r   r   r   	noise_ampr  ZdiffsZ	max_diffsr$   r$   r%   test_find_peaks_withnoise)  s"     z*TestFindPeaksCwt.test_find_peaks_withnoisec                 C   s^   d}d}t jd t j|d d|  }t dd}t||dd	d
}t jt|d dS )zQ
        Verify that no peak is found in
        data that's just noise.
        r\   rE   iW
r   r   rH   rI   rU   r   )r  Z
noise_percr   N)	r   r  r  r  r   r   r~   r   r)   )rB   r  r  r   r   r  r$   r$   r%   test_find_peaks_nopeak?  s    z'TestFindPeaksCwt.test_find_peaks_nopeakc                 C   sD   t dd}tddddg}t||t d}tjtdg| d S )N   r   r'   rJ   rM   )ZwaveletrE   )r   r   r>   r   r~   r   )rB   rC   r   ar$   r$   r%   )test_find_peaks_with_non_default_waveletsL  s    
z:TestFindPeaksCwt.test_find_peaks_with_non_default_waveletsc              	   C   s   ddg}d}t ||\}}tdt|d}d}tjd |tj|d d|  7 }|d	d
  d8  < t||ddddd}t	t
 |j|jkst
W 5 Q R X t||ddddd}|j|jkst
dS )zq
        Verify that window_size is passed correctly to private function and
        affects the result.
        rd   r   r|   g?皙?r  r   r      i@  r'   rJ   N)r  r  r  Zwindow_sizerX   )r-   r   r   r.   r  r  r  r   rl   r   AssertionErrorr   )rB   r   r  r   r   r   r  r  r$   r$   r%   test_find_peaks_window_sizeS  s&    
 
 z,TestFindPeaksCwt.test_find_peaks_window_sizec                 C   s:   t dt jd}t |}d}t||}t j|d dS )z]
        Verify that the `width` argument
        in `find_peaks_cwt` can be a float
        r   r  r'       N)r   r   pisinr   r~   r   )rB   xsr   r   r  r$   r$   r%   test_find_peaks_with_one_widthm  s
    

z/TestFindPeaksCwt.test_find_peaks_with_one_widthN)	ri   rj   rk   r  r  r  r  r!  r&  r$   r$   r$   r%   r    s   r  )$r3   Znumpyr   Znumpy.testingr   r   r   r   rl   r   r   Zscipy.signal._peak_findingr   r	   r
   r   r   r   r   r   Zscipy.signal.windowsr   Z scipy.signal._peak_finding_utilsr   r   r&   r-   r<   r=   ro   r   r   r   r   r   r  r$   r$   r$   r%   <module>   s(   (
	+;\Su 
 @