o
    i                     @   s  d dl Z d dlZd dlZd dlmZm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)raiseswarns)xp_assert_closexp_assert_equal)	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"   ^/home/kim/smarthome/.venv/lib/python3.10/site-packages/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   sZ  dd }t |}t |}tj|dgtd}| |dddf< |d | d  t| }||k r3td|t| d }|t| d }	td|D ]T}
||
d df }||
d df d }|
| dkrrt|dkrr|d	|
 |	  7 }|
|	 dkrt|dkr||	 7 }|||d }|||d }||g||
ddf< qH|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_bounds5   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gapsr/   Zlocsr   Zdist_intZgap_intr   ZnextcolZnextrowr"   r"   r#   _gen_ridge_line'   s*   

 r:   c                	   @   sn   e Zd Zdd Zdd Zdd Zdd Zej	d	e
g d
e
g de
g dgdd Zdd ZdS )TestLocalMaxima1dc                 C   sD   t jg t jd}t|D ]}t|t g dd |jdu sJ qdS )zTest with empty signal.r   Fcheck_dtypeN)r   arrayfloat64r   r   baseselfxr>   r"   r"   r#   
test_emptyT   s
   zTestLocalMaxima1d.test_emptyc                 C   sB   t dd}t|D ]}t|t jg t jd |jdu sJ q
dS )zTest with linear signal.r   d   r   N)r   r(   r   r   r>   intpr@   rA   r"   r"   r#   test_linear[   s
   zTestLocalMaxima1d.test_linearc                 C   sf   t ddd}|ddd  d7  < t jdddt jd}t|D ]}t||d	d
 |jdu s0J q dS )zTest with simple signal.
   2   r   N   r%   r   Fr<   )r   r(   r   rF   r   r   r@   )rB   rC   expectedr>   r"   r"   r#   test_simpleb   s   zTestLocalMaxima1d.test_simplec                 C   sh   t g d}t|\}}}t|t g ddd t|t g ddd t|t g ddd dS )z+Test if flat maxima are detected correctly.)gr   r%   r   r   r   r   rK   rK   rK   gQ@   rN   rN   rN   rH   rO   rO   rO   rO   rH   )r   rN            Fr<   )r   rN            )r      	         N)r   r>   r   r   )rB   rC   Z	midpoints
left_edgesright_edgesr"   r"   r#   test_flat_maximam   s
   z"TestLocalMaxima1d.test_flat_maximarC   )      ?r   r   )      @rK   r   rN   rN   )      @rV   rV   r      r`   r`   c                 C   s6   t |D ]}t|tjg tjd |jdu sJ qdS )z,Test if behavior on signal edges is correct.r   N)r   r   r   r>   rF   r@   rA   r"   r"   r#   test_signal_edgesv   s   z#TestLocalMaxima1d.test_signal_edgesc                 C   s   t tdd ttd W d   n1 sw   Y  t tdd ttjdtd W d   n1 s7w   Y  t tdd td	d
g W d   n1 sSw   Y  t tdd td W d   dS 1 snw   Y  dS )z,Test input validation and raised exceptions.zwrong number of dimensionsmatch)r%   r%   Nzexpected 'const float64_t'r%   r   listr]          @z'x' must not be None)r   r4   r   r   onesr)   	TypeErrorrB   r"   r"   r#   test_exceptions   s   
"z!TestLocalMaxima1d.test_exceptionsN)__name__
__module____qualname__rD   rG   rM   r\   pytestmarkparametrizer   r>   ra   ri   r"   r"   r"   r#   r;   R   s    	
r;   c                   @   <   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|dksJ d S )NrY   rE   r   r%   r   r   r   r   fullr'   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|dksJ t ddg}d|dddf< t|t ddd}t|dks>J d S )NrY   rE   r%   )r   rI   r   r   rI   rr   rt   r"   r"   r#   test_minimal   s   zTestRidgeLines.test_minimalc           
      C   s   g d}g d}t ddgd }d}tddg|j|||}d	||d |d	 f< t dt|}t||t|d	 }t|d	ksBJ t|d |D ]\}}	t	||	d
d qId S )Nr   r%   r   rV   )r   r%   r   r   r%   rY   rJ   g-q=rQ   r      r%   Fr<   )
r   r   r:   shapers   r,   r   r'   zipr   )
rB   r8   r9   ru   r7   linemax_distancesidentified_linesZiline_Zline_r"   r"   r#   test_single_pass   s   
zTestRidgeLines.test_single_passc                 C   s   g d}g d}t ddg}d}tddg|j|||}d||d |d f< d	}t d|}t||t|d }t|d
ks@J |D ](}	t |	d }
t j	
t |
| t |	d }t j	
t |t|d  qBd S )Nrx   )r   r%   r   rN   rY   rJ   rQ   r   ry   r%   rK   r   皙?)r   r   r:   rz   rs   r   r,   r'   difftestingassert_array_lessabs)rB   r8   r9   ru   r7   r|   max_distr}   r~   ilineadistsagapsr"   r"   r#   test_single_bigdist   s&   
z"TestRidgeLines.test_single_bigdistc                 C   s   g d}d}g d}t ddg}d}tddg|j|||}d	||d |d	 f< d
}t d|}t|||}	t|	dks>J |	D ](}
t |
d	 }t j	t 
|| t |
d }t j	t 
|t|d  q@d S )Nrx   rK   )r   rN   r   r%   rY   rJ   rQ   r   ry   r%   r`   r   r   r   r   r:   rz   rs   r   r'   r   r   r   r   r,   rB   r8   Zmax_gapr9   ru   r7   r|   r   r}   r~   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|	dks=J |	D ](}
t |
d }t j	t 
|| t |
d }t j	t 
|t|d  q?d S )	Nr   r%   rK   r`   rJ      ry   r   r   r   r"   r"   r#   test_single_biggaps   s"   z"TestRidgeLines.test_single_biggapsN)	rj   rk   rl   rD   rw   r   r   r   r   r"   r"   r"   r#   rq      s    rq   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 |dd t d}t|dd\}}t||dd t||dd t|dd\}}t||dd t||dd d S )	Nr   rV   r%   r   Fr<   )rK   rV   axis)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   sD  t g dg dg dg dg dg}t|dd\}}t |}t|| g dd	d
 t|| g dd	d
 t|dd\}}t |}t|| g dd	d
 t|| g dd	d
 t|dd\}}t |}t|| g dd	d
 t|| g dd	d
 t|dd\}}t |}t|| g dd	d
 t|| g dd	d
 d S )N)r%   r   r   rK   r   )r   r%   r   r   rK   )rK   r   r%   r   r   )r   rK   r   r%   r   )r%   r   rK   r   r%   r   r   r%   r   rK   Fr<   )rN   r   r%   r%   )r   rK   rN   )rK   r%   r   )r   r>   r   Zargsortr   r   )rB   rC   r   r   orderr"   r"   r#   
test_basic	  s,   




zTestArgrel.test_basicc                 C   s|   d}g d}t |d\}}|| d ||| < || d ||| < t||ddd }t|t|ks4J ||k s<J d S )Nr   )r]   re         $@r_   g      .@  gwJ?Zclip)r   moder   )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   g d}t |d\}}d}tdt|| }t||| g}t|ddd\}}td|jd D ] }	||	k}
t||
 t|ksCJ |||
 ||	  k sQJ q1d S )N)r]   re   r   rE   rY   r   r%   )r   r   )	r+   r   r   r'   Zvstackr   r5   rz   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_gaussians3  s   zTestArgrel.test_2d_gaussiansN)rj   rk   rl   rD   r   r   r   r"   r"   r"   r#   r      s
    r   c                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Ze	j
jdd ZdS )TestPeakProminencesc                 C   s   t g dg }t|tjtjtjgD ]\}}|jdksJ |j|ks$J qt g g }t|tjtjtjgD ]\}}|jdks@J |j|ksGJ q5dS )N
        Test if an empty array is returned if no peaks are provided.
        r   r   N)r   r{   r   r?   rF   sizer   )rB   r.   arrr   r"   r"   r#   rD   D  s   
zTestPeakProminences.test_emptyc                 C   s   t g d}t g d}t g d}t g d}|| t j|| || gdd }t||}t|d |dd t|d	 |dd t|d
 |dd dS )z
        Test if height of prominences is correctly calculated in signal with
        rising baseline (peak widths are 1 sample).
        )r0   333333?r   r%   皙	@g?g
ףp=
@g @)r%   r   rN   r`   )r   r   r   rV   )rK   rK   rV   rS   r   r   Fr<   r%   r   N)r   r>   r,   r   r   )rB   rC   peakslbasesrbasespromsr.   r"   r"   r#   r   R  s   "
zTestPeakProminences.test_basicc                 C   s   g d}g d}t ||\}}}t|tg ddd t|g ddd t|g ddd g d}tg d}t ||\}}}t|tg d	 t||d
 dd t||d
 dd dS )z"
        Test edge cases.
        )r   r   r%   r   r%   r   r   r%   rK   rV   )re   r   r   Fr<   )r   r   r   )r`   r`   r`   )r   r%   r   r%   r   r%   r   )r]   r%   r%   r%   N)r   r   r   asarrayr>   rB   rC   r   r   r   r   r"   r"   r#   test_edge_casesc  s   z#TestPeakProminences.test_edge_casesc                 C   s   t g dd}t g dd}t|ddd |ddd \}}}t|t g d t|g ddd t|g d	dd dS )
:
        Test with non-C-contiguous input arrays.
        )irW   rW   r   rK   r%   r   )r%   r   rN   N)g      "@rW   r   )r   r   rK   Fr<   )rK   rK   rV   )r   repeatr   r   r   r   r"   r"   r#   test_non_contiguousw  s   $z'TestPeakProminences.test_non_contiguousc                 C   s   g d}dg}t ||}t|g dD ]
\}}||ksJ qdD ]#\}}t |||}t|d| d| d| gD ]
\}}||ksBJ q8q dS )	zO
        Test if wlen actually shrinks the evaluation range correctly.
        )r   r%   r   rK   r%   r   r0   rK   )r^   r   r`   ))rP   r   )rS   r   )r`   r   )rV   r%   )r   r%   rK   r   )皙?r   r^   r   r`   N)r   r{   )rB   rC   peakr   Zpromvalwlenr   r"   r"   r#   	test_wlen  s   
$zTestPeakProminences.test_wlenc              	   C   s  t tdd tg dgddg W d   n1 sw   Y  t tdd tg dddgg W d   n1 s;w   Y  t tdd tddg W d   n1 sWw   Y  t td	d tg dg W d   n1 ssw   Y  d
D ] }t td	d tg d|g W d   n1 sw   Y  qzt tdd tg dddg W d   n1 sw   Y  t tdd ttdddgdd W d   dS 1 sw   Y  dS )zA
        Verify that exceptions and warnings are raised.
        	1-D arrayrb   )r   r%   r%   r   r%   r   NrK   r   not a valid index)ir0   rK     r%   r   r   cannot safely castr   ffffff@r   rI   rV   r   )r   r4   r   rg   r   r   )rB   pr"   r"   r#   ri     s.   "z#TestPeakProminences.test_exceptionsc              	   C   s   d}dD ] }t t|d tg d|g W d   n1 sw   Y  qt t|d tg ddgdd W d   dS 1 sAw   Y  dS )	>
        Verify that appropriate warnings are raised.
        z!some peaks have a prominence of 0)r   r%   r   rb   r   Nr   r%   r%   r%   r   r   r   )r   r   r   )rB   msgr   r"   r"   r#   test_warnings  s   "z!TestPeakProminences.test_warningsN)rj   rk   rl   rD   r   r   r   r   ri   rm   rn   thread_unsafer   r"   r"   r"   r#   r   B  s    r   c                   @   sd   e Zd Zdd Zejddd Zdd Zdd	 Z	ejj
d
d Zdd Zejddd ZdS )TestPeakWidthsc                 C   s   t g g d }t|tjsJ |jdksJ t g dg d }t|tjs'J |jdks.J t g g }|D ]}t|tjs?J |jdksFJ q5dS )r   r   r   N)r	   
isinstancer   Zndarrayr   )rB   widthsr.   r   r"   r"   r#   rD     s   
zTestPeakWidths.test_empty#ignore:some peaks have a width of 0c                 C   s   t g d}d}dD ]9\}}}}t|dg|\}}}	}
t|t |g t|t d||  g t|	t |g t|
t |g qdS )zk
        Test a simple use case with easy to verify results at different relative
        heights.
        )r%   r   r%   r   r%   r   r0   r   ))        r   r^   r^   )g      ?r]         @      @)      ?re   re         @)      ?r^         ?      @)r]   r   r]   r_   )re   r_   r]         @)r^   r_   r]   r   rK   N)r   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   s`   t g dd}t dgd}t|ddd |ddd }t|t dgdgdgdgg dS )	r   )r   rE   rJ   rN   r%   rK   Nr   K   r   )r   r   r	   r   r   )rB   rC   r   resultr"   r"   r#   r     s   z"TestPeakWidths.test_non_contiguousc                 C   sB  t tdd ttdtd W d   n1 sw   Y  t tdd tddg W d   n1 s8w   Y  t tdd ttdtjdtjd	 W d   n1 s\w   Y  t tdd ttdd W d   n1 szw   Y  t td
d ttdddg W d   n1 sw   Y  t td
d tg ddg W d   n1 sw   Y  t tdd ttdddg W d   n1 sw   Y  t tdd tg dddgdd W d   n1 sw   Y  t tdd tg ddgdd W d   dS 1 sw   Y  dS )zD
        Verify that argument validation works as intended.
        r   rb   )rK   rN   rK   Nr   rI   r   r   r   rP   rT   r%   r   r   r   r   r   )r   r%   r   r%   r   r0   r   None)r%   r   r%   )NNNprominence_data)	r   r4   r	   r   r   rf   r   rF   rg   rh   r"   r"   r#   ri     s6   $zTestPeakWidths.test_exceptionsc              
   C   s   d}t t|d tg ddgdd W d   n1 sw   Y  t t|d( tg dd	gtd
gtjtd	gtjtd	gtjfd W d   dS 1 sSw   Y  dS )r   zsome peaks have a width of 0rb   r   r%   r   r%   r   r   Nr   r   r   r   )r   r   r	   r   r>   r?   rF   )rB   r   r"   r"   r#   r     s   
"zTestPeakWidths.test_warningsc           	   	   C   s   g d}dg}t g dD ]D\}\}}}tj|tjdtj|tjdtj|tjdf}|dk r2d}nd}tt|d t|||d	 W d
   n1 sLw   Y  qd
S )z4Test with mismatching peak and / or prominence data.r   r%   ))r]   )r0   r   )r   r   )rK   )r   r   r   )r]   r]   r   r   r   r   )r   r   r   )r   r   r   )r   r   r   r   rK   z#prominence data is invalid for peakz4arrays in `prominence_data` must have the same shaperb   r   N)r   r   r>   r?   rF   r   r4   r	   )	rB   rC   r   r   prominences
left_basesright_basesr   rc   r"   r"   r#    test_mismatching_prominence_data#  s   
z/TestPeakWidths.test_mismatching_prominence_datac                 C   s@   g d}t t|dgddg d t t|dgddg d dS )	z3Test if x == eval_height counts as an intersection.)r   r%   r   r%   rK   rK   rK   r%   r   r%   r   rV   r   )r   r   ))r   r^   r_   r   gUUUUUU?))r   r   r   )g      @N)r   r	   )rB   rC   r"   r"   r#   test_intersection_rules<  s   z&TestPeakWidths.test_intersection_rulesN)rj   rk   rl   rD   rm   rn   filterwarningsr   r   ri   r   r   r   r   r"   r"   r"   r#   r     s    

 

r   c                  C   s>  t d} | }|d }|ddd }dtd| |ksJ dtd| |ks&J dtd| |ks0J dtd| |ks:J dtd| |ksDJ t||f| |\}}t|||  t|||  ttd	d
 t|t d| W d   n1 svw   Y  ttdd
 td|ft d| W d   dS 1 sw   Y  dS )zW
    Verify parsing of condition arguments for `scipy.signal.find_peaks` function.
    rI   r%   Nr   NN)r%   NNr   )r^   r   zarray size of lowerrb   rT   zarray size of upper)r   r   r
   r   r   r4   )rC   Z	amin_trueZ	amax_truer   Z	amin_calcZ	amax_calcr"   r"   r#   test_unpack_condition_argsI  s$   
"r   c                   @   s   e Zd Zh 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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>
   r   left_thresholdsr   r   	right_ipspeak_heightsleft_ipsright_thresholdswidth_heightsr   c                 C   sP   d}t td||||d\}}|jdksJ | jD ]}|| jdks%J qdS )z@
        Test behavior for signal without local maxima.
        r   rI   r   	thresholdr   widthr   N)r   r   rf   r   property_keys)rB   open_intervalr   propskeyr"   r"   r#   test_constantl  s   


zTestFindPeaks.test_constantc                 C   s.  t g d}t |jd d }||ddd< t j|jtd}|ddd |ddd< t ||}t|dd\}}t|g dd	d
 t|d |d	d
 t|d ||d d  d	d
 t|d ||d  d	d
 tt|ddd g dd	d
 tt|ddd g dd	d
 tt|ddd ddgd	d
 dS )z8
        Test plateau size condition for peaks.
        )r%   r   rK   rN   rP   rY   o   r   r%   Nr   r   )Zplateau_size)r%   rK   rS   rT   rR   !   rE   Fr<   plateau_sizesrZ   r[   rN   r   )rT   rR   r   rE   )Nr   )r%   rK   rS   )rV   rJ   rR   r   )	r   r>   r   r   rf   r)   r   r   r   )rB   r   rC   Zrepeatsr   r   r"   r"   r#   test_plateau_sizex  s0   
zTestFindPeaks.test_plateau_sizec                 C   s   d}t |dd\}}t|tg ddd t|d tg ddd tt |d	dd
 tddgdd tt |ddd
 tddgdd tt |ddd
 tdgdd dS )z2
        Test height condition for peaks.
        )r   UUUUUU?r   r   r   r   r   r   )r   r   Fr<   r   )r   r   r   r   r   rK   rV   )NrK   r%   )r   rK   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dd t|d td	d
g t|d tddg tt |ddd tdgdd tt |ddd tjg tddd tt |ddd tddgdd tt |ddd tdgdd tt |ddd tjg tddd dS )z5
        Test threshold condition for peaks.
        )r   r   r%   rN   r0   r   )r   r%   rK   Fr<   r   re   r^   r   r]   r_   r   r   r   r   )NrV   )NrN   )r   rN   N)r   r   r   r>   r)   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 |dd t|d	dd }t j||d
djdks<J t |}t|dt 	|  g d}t|ddd }|jdkrb|d dksdJ dS )z4
        Test distance condition for peaks.
        r%      rK   r   distancer   Fr<   g9m4 @T)Zassume_uniquer`   )r%   r0   r   rI   N)
r   r   r   r(   r   r   r   Z	setdiff1dr   	ones_like)rB   Z	peaks_allrC   Zpeaks_subsetdfsr"   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||| d	d
 t|d || d	d
 t|d t |d  t|d || d d	d
 dS )z6
        Test prominence condition for peaks.
        r   rI   rE   r%   c   r   )rK   rW   )r   Fr<   r   r   r   N)r   r(   r   r   Znonzeror   r   
zeros_like)	rB   rC   Z
peaks_trueoffsetr   intervalZkeepZ
peaks_calc
propertiesr"   r"   r#   test_prominence_condition  s$   
z'TestFindPeaks.test_prominence_conditionc                 C   s   t g d}t|ddd\}}|jdksJ t|dt |  t|d t dg t|d	 t d
g t|d t dg t|d t dg dS )z1
        Test width condition for peaks.
        )	r%   r   r%   r   r%   r   r0   rN   r   r   r   )r   r   r%   rS   r   g?r   r]   r   g@r   g      @N)r   r>   r   r   r   r	  r   r   r  r"   r"   r#   test_width_condition  s   z"TestFindPeaks.test_width_conditionc                 C   s\   d}g d}t |||||d\}}t|t| jksJ | jD ]}|j|| jks+J qdS )z+
        Test returned properties.
        r   )
r   r%   r   r   r   r   rK   r   rV   rW   r   N)r   r'   r   r   )rB   r   rC   r   r   r   r"   r"   r#   test_properties  s   

zTestFindPeaks.test_propertiesc                 C   s   t tdd ttd W d   n1 sw   Y  t tdd ttd W d   n1 s5w   Y  t tdd ttddd	 W d   dS 1 sUw   Y  dS )
z5
        Test exceptions raised by function.
        r   rb   r%   Nr   r  rI   r0   r  )r   r4   r   r   r>   rf   r   rh   r"   r"   r#   test_raises  s   "zTestFindPeaks.test_raisesz(ignore:some peaks have a prominence of 0r   c                 C   s   t g ddddd\}}t|dt|  t|d t|d  t|d t|d  t|d t|d  dD ]}t|| |d	d
 q<d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   Fr<   N)r   r   r   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   sL   t ddd}| }d|j_t|\}}t|fi |\}}t|| dS )z4
        Test readonly arrays are accepted.
        r   rI      FN)r   r(   r1   flagsZ	writeabler   r   )rB   r  rC   Z
x_readonlyr   _Zpeaks_readonlyr"   r"   r#   test_readonly_array  s   z!TestFindPeaks.test_readonly_arrayN)rj   rk   rl   r   r   r   r  r  r  r  r  r  r  rm   rn   r   r  ro   r  r"   r"   r"   r#   r   e  s,    
r   c                   @   rp   )TestFindPeaksCwtc                 C   sP   g d}d}t ||\}}tdt|}t||dddd}t||dd	d
 dS )zX
        Generate a series of gaussians and attempt to find the peak locations.
        r_   r^   r   g      4@r   g      I@r   r   r   r   N)
gap_threshmin_snr
min_lengthFz4Found maximum locations did not equal those expected)r=   err_msg)r+   r   r   r,   r   r   )rB   r   
num_pointsr   r   r   
found_locsr"   r"   r#   test_find_peaks_exact6  s   

z&TestFindPeaksCwt.test_find_peaks_exactc                 C   s   g d}d}t ||\}}tdt|}d}tjd |tj|d d|  7 }t||dd	|d
 d}d}t|t|ksDJ |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   gQ?or   r   r  r%   rV   )r  r  r  z-Different number of peaks found than expectedzMaximum location differedzby more than N)r+   r   r   r,   randomseedrandr   r'   r   r>   r   r   )rB   r   r!  r   r   r   	noise_ampr"  r   ZdiffsZ	max_diffsr"   r"   r#   test_find_peaks_withnoiseE  s"   
z*TestFindPeaksCwt.test_find_peaks_withnoisec                 C   sZ   d}d}t jd}||d d|  }t dd}t||dd	d
}t|dks+J dS )zQ
        Verify that no peak is found in
        data that's just noise.
        r]   rE   iW
r   r   rI   rJ   rV   r   )r  Z
noise_percr   N)r   r%  RandomStater'  r   r   r'   )rB   r(  r!  rngr   r   r"  r"   r"   r#   test_find_peaks_nopeak[  s   z'TestFindPeaksCwt.test_find_peaks_nopeakc                 C   s@   t dd}tg d}t||t d}t|tdgdd d S )N   r   )r%   r   rK   rN   )ZwaveletrE   Fr<   )r   r   r>   r   r   r   )rB   rC   r   ar"   r"   r#   )test_find_peaks_with_non_default_waveletsh  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}|||d d|  7 }|d	d
  d8  < t||ddddd}t	t
 |j|jksMJ W d   n1 sWw   Y  t||ddddd}|j|jksnJ dS )zq
        Verify that window_size is passed correctly to private function and
        affects the result.
        re   r   r   g?皙?r$  r   r      i@  r%   rK   N)r  r  r  Zwindow_sizerY   )r+   r   r   r,   r%  r*  r'  r   rm   r   AssertionErrorr   )	rB   r   r!  r   r   r   r(  r+  r"  r"   r"   r#   test_find_peaks_window_sizeo  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   r0  r%       N)r   r   pisinr   r   Zassert_equal)rB   Zxsr   r   r"  r"   r"   r#   test_find_peaks_with_one_width  s
   

z/TestFindPeaksCwt.test_find_peaks_with_one_widthN)	rj   rk   rl   r#  r)  r,  r/  r3  r7  r"   r"   r"   r#   r  4  s    r  )"r1   numpyr   rm   r   r   Zscipy._lib._array_apir   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;   rq   r   r   r   r   r   r  r"   r"   r"   r#   <module>   s*    (
	+;bS{  P