
    UgG                     X   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 Zd Zd	 Z G d
 d          Z G d d          Z G d d          Z G d d          Z G d d          Z d Z! G d d          Z" G 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                    t          j        d|                              t                    }t          j        |t                    }t          |          D ].\  }}|| |         z
  |z  }|t          j        |dz             z  }/|S )Nr   dtype   )nparangeastypefloatzeros	enumerateexp)center_locssigmastotal_lengthxdataout_dataindsigmatmps           c/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/scipy/signal/tests/test_peak_finding.py_gen_gaussiansr(      s    Ia&&--e44ExE222H'' & &
U{3''50BFS!V9%%%O    c                     t          |           }||dz   z  }t          j        |||z
  |                              t                    }t          || |          }||fS )N   )num)lenr   linspacer   intr(   )r    r!   	num_peaksdeltar   r#   s         r'   _gen_gaussians_evenr2   $   sa    FIIM*E+e\E%9yIIIPPQTUUKk6<@@H[  r)   c                 *   d }t          j        |          }t          j        |          }t          j        |dgt                    }| |dddf<   |d         | d         z
  t          |          z
  }||k     rt          d          |t          |          z  dz
  }|t          |          z  dz
  }	t          d|          D ]}
||
dz
  df         }||
dz
  df         dz   }|
|z  dk    r0t          |          dk    r|d|
z  |	                                z  z  }|
|	z  dk    r*t          |          dk    r||	                                z  } |||d                   } |||d                   }||g||
ddf<   |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                 F    t          | d          }t          ||          }|S )Nr   )maxmin)r,   max_valouts      r'   keep_boundsz$_gen_ridge_line.<locals>.keep_bounds:   s#    #qkk#w
r)   r   r   r   Nz3Cannot generate ridge line according to constraintsr+   )
copydeepcopyr   r   r/   sum
ValueErrorr-   rangepop)
start_locsmax_locslength	distancesgapsr9   locsr!   dist_intgap_intr$   nextcolnextrows                r'   _gen_ridge_linerK   ,   s     
 =Di((I8VQKs+++DDAAAJA;A.T:LfNOOOI&*Hs4yy 1$GQ 	* 	*sQwz"sQwz"Q&(Nac)nnq&8&8c	9==??22G'MQSYY]]txxzz!G+gx{33+gx{33)S!!!VAJQQQT
##r)   c            	           e Zd Zd Zd Zd Zd Zej        	                    d e
j        g d           e
j        g d           e
j        g d          g          d	             Zd
 ZdS )TestLocalMaxima1dc                     t          j        g t           j                  }t          |          D ]:}t	          |t          j        g                      t          |j        du            ;dS )zTest with empty signal.r   N)r   arrayfloat64r   r   r   baseselfxrO   s      r'   
test_emptyzTestLocalMaxima1d.test_emptyY   si    HRrz***%a(( 	( 	(E---EJ$&''''	( 	(r)   c                     t          j        dd          }t          |          D ]:}t          |t          j        g                      t          |j        du            ;dS )zTest with linear signal.r   d   N)r   r.   r   r   rO   r   rQ   rR   s      r'   test_linearzTestLocalMaxima1d.test_linear`   sd    K3%a(( 	( 	(E---EJ$&''''	( 	(r)   c                     t          j        ddd          }|dddxx         dz  cc<   t          j        ddd          }t          |          D ](}t	          ||           t          |j        du            )dS )zTest with simple signal.
   2   r   N   r+   )r   r.   r   r   r   r   rQ   )rS   rT   expectedrO   s       r'   test_simplezTestLocalMaxima1d.test_simpleg   s    KR$$	!$Q$19QA&&%a(( 	( 	(E )))EJ$&''''		( 	(r)   c                 0   t          j        g d          }t          |          \  }}}t          |t          j        g d                     t          |t          j        g d                     t          |t          j        g d                     dS )z+Test if flat maxima are detected correctly.)gr   r+   r   r   r   r   r]   r]   r]   gQ@   ra   ra   ra   rZ   rb   rb   rb   rb   rZ   )r   ra            )r   ra            )r      	         N)r   rO   r   r   )rS   rT   	midpoints
left_edgesright_edgess        r'   test_flat_maximaz"TestLocalMaxima1d.test_flat_maximar   s    H / / / 0 0-=a-@-@*	:{Y):):): ; ;<<<Z*;*;*;!<!<===["(+<+<+<"="=>>>>>r)   rT   )      ?r   r   )      @r]   r   ra   ra   )      @ri   ri   r      rt   rt   c                     t          |          D ]:}t          |t          j        g                      t	          |j        du            ;dS )z,Test if behavior on signal edges is correct.N)r   r   r   rO   r   rQ   rR   s      r'   test_signal_edgesz#TestLocalMaxima1d.test_signal_edges{   sU     &a(( 	( 	(E---EJ$&''''	( 	(r)   c                 J   t          t          d          5  t          t          j        d                     ddd           n# 1 swxY w Y   t          t          d          5  t          t          j        dt
                               ddd           n# 1 swxY w Y   t          t          d          5  t          d	d
g           ddd           n# 1 swxY w Y   t          t          d          5  t          d           ddd           dS # 1 swxY w 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   listrq          @z'x' must not be None)r   r>   r   r   onesr/   	TypeErrorrS   s    r'   test_exceptionsz!TestLocalMaxima1d.test_exceptions   s   J&BCCC 	. 	.RWV__---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.J&BCCC 	4 	4RWQc222333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4IV,,, 	' 	'b"X&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'I%;<<< 	# 	#T"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#sG   "AA	A	&)BB"B<CC!C;DDDN)__name__
__module____qualname__rU   rX   r_   rp   pytestmarkparametrizer   rO   rv   r    r)   r'   rM   rM   W   s        ( ( (( ( (	( 	( 	(? ? ? [S!!!""'''((#  
( ( 
(	# 	# 	# 	# 	#r)   rM   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )TestRidgeLinesc                     t          j        ddg          }t          |t          j        dd          d          }t	          t          |          dk               d S )Nrl   rW   r   r+   r   r   r   r   fullr   r-   rS   	test_matrliness      r'   rU   zTestRidgeLines.test_empty   sN    Hb#Y''	%iQCCE

a     r)   c                    t          j        ddg          }d|d<   t          |t          j        dd          d          }t	          t          |          dk               t          j        ddg          }d|dddf<   t          |t          j        dd          d          }t	          t          |          dk               d S )Nrl   rW   r+   )r   r[   r   r   r[   r   r   s      r'   test_minimalzTestRidgeLines.test_minimal   s    Hb#Y''		%%iQCCE

a   Hb#Y''		!A#r'%iQCCE

a     r)   c                 N   g d}g d}t          j        ddg          dz   }d}t          ddg|j        |||          }d	||d         |d	         f<   t          j        dt          |                    }t          ||t          |          d	z             }t          ||g           d S )
Nr   r+   r   ri   )r   r+   r   r   r+   rl   r\   g-q=rd   r      r+   )r   r   rK   shaper   r5   r   r   )rS   rD   rE   r   rC   linemax_distancesidentified_liness           r'   test_single_passzTestRidgeLines.test_single_pass   s     LL	Hb"X&&.	2w	DQQ&'	$q'47"#C	NN3301>14TQ@ @ 	+dV44444r)   c                    g d}g d}t          j        ddg          }d}t          ddg|j        |||          }d||d         |d         f<   d	}t          j        d|          }t          ||t          |          dz             }t          t          |          d
k               |D ]}	t          j	        |	d                   }
t           j
                            t          j        |
          |           t          j	        |	d                   }t           j
                            t          j        |          t          |          dz              d S )Nr   )r   r+   r   ra   rl   r\   rd   r   r   r+   r]   r   皙?)r   r   rK   r   r   r   r5   r   r-   difftestingassert_array_lessabs)rS   rD   rE   r   rC   r   max_distr   r   ilineadistsagapss               r'   test_single_bigdistz"TestRidgeLines.test_single_bigdist   sF    LL	||Hb"X&&	2w	DQQ&'	$q'47"#H--01>14TQ@ @ 	$%%*+++% 	I 	IEWU1X&&FJ((BBBGE!H%%EJ((D		CHHHH	I 	Ir)   c                    g d}d}g d}t          j        ddg          }d}t          ddg|j        |||          }d	||d         |d	         f<   d
}t          j        d|          }t          |||          }	t          t          |	          dk               |	D ]}
t          j        |
d	                   }t           j	        
                    t          j        |          |           t          j        |
d                   }t           j	        
                    t          j        |          t          |          dz              d S )Nr   r]   )r   ra   r   r+   rl   r\   rd   r   r   r+   rt   r   r   r   r   rK   r   r   r   r   r-   r   r   r   r   r5   rS   rD   max_gaprE   r   rC   r   r   r   r   r   r   r   s                r'   test_single_biggapz!TestRidgeLines.test_single_biggap   s7    LL	||Hb"X&&	2w	DQQ&'	$q'47"#H--0M7SS$%%*+++% 	I 	IEWU1X&&FJ((BBBGE!H%%EJ((D		CHHHH	I 	Ir)   c                    dg}d}ddg}t          j        ddg          }d}t          ddg|j        |||          }d||d         |d         f<   d}t          j        d|          }t          |||          }	t          t          |	          dk               |	D ]}
t          j        |
d                   }t           j	        
                    t          j        |          |           t          j        |
d                   }t           j	        
                    t          j        |          t          |          dz              d S )	Nr   r+   r]   rt   r\      r   r   r   r   s                r'   test_single_biggapsz"TestRidgeLines.test_single_biggaps   s5   C	1vHb"X&&	2w	DQQ&'	$q'47"#H--0M7SS$%%*+++% 	I 	IEWU1X&&FJ((BBBGE!H%%EJ((D		CHHHH	I 	Ir)   N)	r   r   r   rU   r   r   r   r   r   r   r)   r'   r   r      sy        ! ! !
	! 	! 	!5 5 5I I I,I I I*I I I I Ir)   r   c                   &    e Zd Zd Zd Zd Zd ZdS )
TestArgrelc                    t          j        g t                    }t          j        d          }t	          |          }t          t          |          d           t          |d         |           t          j        d          }t	          |d          \  }}t          ||           t          ||           t	          |d          \  }}t          ||           t          ||           d S )Nr   ri   r+   r   )r]   ri   axis)r   rO   r/   r   r
   r   r-   r   )rS   empty_arrayz1iz2rowcols          r'   rU   zTestArgrel.test_empty   s     hr---Xa[[bMMSVVQ1Q4---Xe__Ra(((S3,,,3,,,Ra(((S3,,,3,,,,,r)   c                    t          j        g dg dg dg dg dg          }t          |d          \  }}t          j        |          }t	          ||         g d           t	          ||         g d	           t          |d
          \  }}t          j        |          }t	          ||         g d           t	          ||         g d           t          |d          \  }}t          j        |          }t	          ||         g d           t	          ||         g d           t          |d
          \  }}t          j        |          }t	          ||         g d           t	          ||         g d           d S )N)r+   r   r   r]   r   )r   r+   r   r   r]   )r]   r   r+   r   r   )r   r]   r   r+   r   )r+   r   r]   r   r+   r   r   r+   r   r]   )ra   r   r+   r+   )r   r]   ra   )r]   r+   r   )r   rO   r	   argsortr   r
   )rS   rT   r   r   orders        r'   
test_basiczTestArgrel.test_basic  s   
 Hooo%oo%oo%oo%oo	' ( ( QQ'''S
3SZ+++SZ+++QQ'''S
3SZ+++SZ+++QQ'''S
3SZ+++SZ+++QQ'''S
3SZ+++SZ+++++r)   c                 P   d}g d}t          |d          \  }}||         dz  |||z   <   ||         dz  |||z
  <   t          ||d          d         }t          t          |          t          |          k               t          ||k                                               d S )Nr   )rq   r{         $@rs   g      .@  gwJ?clip)r   moder   )r2   r	   r   r-   all)rS   r   r    	test_dataact_locsrel_max_locss         r'   test_highorderzTestArgrel.test_highorder+  s    ,,,1&#>>	8&/&9'&A	(U"#&/&9'&A	(U"# %fEEEaHL!!S]]2333)..0011111r)   c                    g d}t          |d          \  }}d}t          j        dt          |                    |z
  }t          j        |||         g          }t          |dd          \  }}t          d|j        d                   D ]l}	||	k    }
t          t          ||
                   t          |          k               t          |||
         ||	z  z
  k    	                                           md S )N)rq   r{   r   rW   rl   r   r+   )r   r   )
r2   r   r   r-   vstackr	   r?   r   r   r   )rS   r    r   r   
rot_factor	rot_rangetest_data_2rel_max_rowsrel_max_colsrwindss              r'   test_2d_gaussianszTestArgrel.test_2d_gaussians6  s   !!!1&#>>	8
IaY00:=	iIi,@ ABB%.{!%L%L%L"l;,Q/00 	N 	NB B&DCT*++s8}}<===X,t"4z"}"DEJJLLMMMM		N 	Nr)   N)r   r   r   rU   r   r   r   r   r)   r'   r   r      sU        - - -0, , ,>	2 	2 	2N N N N Nr)   r   c                   8    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dS )	TestPeakProminencesc                    t          g dg           }t          |t          j        t          j        t          j        g          D ]5\  }}t          |j        dk               t          |j        |k               6t          g g           }t          |t          j        t          j        t          j        g          D ]5\  }}t          |j        dk               t          |j        |k               6dS )N
        Test if an empty array is returned if no peaks are provided.
        r   r   N)r   zipr   rP   intpr   sizer   )rS   r8   arrr   s       r'   rU   zTestPeakProminences.test_emptyG  s     yyy"--cBJ#ABB 	( 	(JCCHM"""CI&''''r2&&cBJ#ABB 	( 	(JCCHM"""CI&''''	( 	(r)   c                    t          j        g d          }t          j        g d          }t          j        g d          }t          j        g d          }||         t          j        ||         ||         gd          z
  }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).
        )r:   333333?r   r+   皙	@g?g
ףp=
@g @)r+   r   ra   rt   )r   r   r   ri   )r]   r]   ri   rf   r   r   r+   r   N)r   rO   r5   r   r   )rS   rT   peakslbasesrbasespromsr8   s          r'   r   zTestPeakProminences.test_basicU  s     H;;;<<&&,,,'',,,''%261V9ai"8qAAAAq%((SVU###SVV$$$SVV$$$$$r)   c                 v   g d}g d}t          ||          \  }}}t          |g d           t          |g d           t          |g d           g d}t          j        g d          }t          ||          \  }}}t          |g d           t          ||dz
             t          ||dz              d	S )
z"
        Test edge cases.
        )r   r   r+   r   r+   r   r   r+   r]   ri   )r   r   r   )r   r   r   )rt   rt   rt   )r   r+   r   r+   r   r+   r   )r+   r+   r+   r+   N)r   r   r   rO   rS   rT   r   r   r   r   s         r'   test_edge_casesz#TestPeakProminences.test_edge_casesf  s    
 "!!		 0E : :vvUIII&&&VYYY'''VYYY''' "!!## 0E : :vvUIII&&&VUQY'''VUQY'''''r)   c                    t          j        g dd          }t          j        g dd          }t          |ddd         |ddd                   \  }}}t          |g d           t          |g d           t          |g d           dS ):
        Test with non-C-contiguous input arrays.
        )irj   rj   r   r]   r+   r   )r+   r   ra   N)rj   rj   r   )r   r   r]   )r]   r]   ri   )r   repeatr   r   r   s         r'   test_non_contiguousz'TestPeakProminences.test_non_contiguousz  s     I)))1--	)))Q'' 033Q3sss D DvvUIII&&&VYYY'''VYYY'''''r)   c                     g d}dg}t          t          ||          g d           dD ]0\  }}t          t          |||          d|z
  d|z   d|z
  g           1dS )	zO
        Test if wlen actually shrinks the evaluation range correctly.
        )r   r+   r   r]   r+   r   r:   r]   )rr   r   rt   ))rc   r   )rf   r   )rt   r   )ri   r+   )r   r+   r]   r   )皙?r   rr   r   rt   N)r   r   )rS   rT   peakwlenr   s        r'   	test_wlenzTestPeakProminences.test_wlen  s     #""s%a..


;;;S 	R 	RGD!)!T488261q5!a%:PQQQQ	R 	Rr)   c                    t          t          d          5  t          g dgddg           ddd           n# 1 swxY w Y   t          t          d          5  t          g dddgg           ddd           n# 1 swxY w Y   t          t          d          5  t          ddg           ddd           n# 1 swxY w Y   t          t          d	          5  t          g dg           ddd           n# 1 swxY w Y   d
D ]C}t          t          d	          5  t          g d|g           ddd           n# 1 swxY w Y   Dt          t          d          5  t          g dddg           ddd           n# 1 swxY w Y   t          t          d          5  t          t	          j        d          ddgd           ddd           dS # 1 swxY w Y   dS )zA
        Verify that exceptions and warnings are raised.
        	1-D arrayrx   )r   r+   r+   r   r+   r   Nr]   r   not a valid index)ir:   r]     r+   r   r   cannot safely castr   ffffff@r   r[   ri   r   )r   r>   r   r}   r   r   )rS   ps     r'   r   z#TestPeakProminences.test_exceptions  s   
 Jk222 	5 	5lll^aV444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 Jk222 	5 	5\\\QF8444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 Jk222 	& 	&Q%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& J&9::: 	& 	&R!%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& % 	1 	1A
*=>>> 1 1 QC0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 I%9::: 	7 	7\\\C:666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 Jf--- 	< 	<RYr]]QF;;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<sy   9= =A<<B B B;;B?B?C::C>C>D??E	E	!FF	F#'GGGc                    d}dD ]C}t          t          |          5  t          g d|g           ddd           n# 1 swxY w Y   Dt          t          |          5  t          g ddgd           ddd           dS # 1 swxY w Y   dS )	>
        Verify that appropriate warnings are raised.
        z!some peaks have a prominence of 0)r   r+   r   rx   r   Nr   r+   r+   r+   r   r   r   )r   r   r   )rS   msgr   s      r'   test_warningsz!TestPeakProminences.test_warnings  s+    2 	2 	2A*#666 2 2 QD1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2&c222 	; 	;___qc::::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s!   =A	A	BB	BN)
r   r   r   rU   r   r   r   r   r   r   r   r)   r'   r   r   E  s        ( ( (% % %"( ( ((	( 	( 	(	R 	R 	R< < <<	; 	; 	; 	; 	;r)   r   c                       e Zd Zd Zej                            d          d             Zd Zd Z	d Z
d Zej                            d          d             Zd	S )
TestPeakWidthsc                    t          g g           d         }t          t          |t          j                             t          |j        d           t          g dg           d         }t          t          |t          j                             t          |j        d           t          g g           }|D ]>}t          t          |t          j                             t          |j        d           ?dS )r   r   r   N)r   r   
isinstancer   ndarrayr   r   )rS   widthsr8   r   s       r'   rU   zTestPeakWidths.test_empty  s     R$$Q'
62:..///V[!$$$YYY++A.
62:..///V[!$$$"b!! 	& 	&CJsBJ//0001%%%%	& 	&r)   #ignore:some peaks have a width of 0c                    t          j        g d          }d}dD ]d\  }}}}t          |dg|          \  }}}	}
t          ||           t          |d||z  z
             t          |	|           t          |
|           edS )zk
        Test a simple use case with easy to verify results at different relative
        heights.
        )r+   r   r+   r   r+   r   r:   r   ))        r  rr   rr   )g      ?rq         @      @)      ?r{   r{         @)      ?rr         ?      @)rq   r  rq   rs   )r{   rs   rq         @)rr   rs   rq   r  r]   N)r   rO   r   r   )rS   rT   
prominence
rel_height
width_truelip_truerip_true
width_calcheightlip_calcrip_calcs              r'   r   zTestPeakWidths.test_basic  s     H+++,,
;
 	0 	06J
Hh 6AA3
6$ 6$2J(J
333FA
Z(?$?@@@Hh///Hh////	0 	0r)   c                     t          j        g dd          }t          j        dgd          }t          |ddd         |ddd                   }t          |g d           dS )r   )r   rW   r\   ra   r+   r]   N)r  K   r  r	  )r   r   r   r   )rS   rT   r   results       r'   r   z"TestPeakWidths.test_non_contiguous  sl     IlllA&&	1#q!!QsssVU33Q3Z00V22233333r)   c                    t          t          d          5  t          t          j        d          t          j        d                     ddd           n# 1 swxY w Y   t          t          d          5  t          ddg           ddd           n# 1 swxY w Y   t          t          d          5  t          t          j        d          t          j        dt          j        	                     ddd           n# 1 swxY w Y   t          t          d          5  t          t          j        d          d           ddd           n# 1 swxY w Y   t          t          d
          5  t          t          j        d          ddg           ddd           n# 1 swxY w Y   t          t          d
          5  t          g ddg           ddd           n# 1 swxY w Y   t          t          d          5  t          t          j        d          ddg           ddd           n# 1 swxY w Y   t          t          d          5  t          g dddgd           ddd           n# 1 swxY w Y   t          t          d          5  t          g ddgd           ddd           dS # 1 swxY w Y   dS )zD
        Verify that argument validation works as intended.
        r   rx   )r]   ra   r]   Nr   r[   r   r   r   rc   rg   r+   r   r   r   r   r  )r   r+   r   r+   r   r:   r  None)r+   r   r+   )NNNprominence_data)	r   r>   r   r   r   r|   r   r   r}   r~   s    r'   r   zTestPeakWidths.test_exceptions  s    Jk222 	6 	6(("'!**555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 Jk222 	  	 A3	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  Jk222 	G 	G	"rwvRW'E'E'EFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G Jk222 	* 	*	"q)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* J&9::: 	0 	0	"2w///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 J&9::: 	$ 	$QF###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ I%9::: 	3 	3	"Sz222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 Jl333 	@ 	@!QB????	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ IV,,, 	L 	L			A38JKKKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	Ls   5AAA9BBB8ADD	D	&#EEE6%F''F+.F+G''G+.G+%H99H= H=I==JJKKKc                    d}t          t          |          5  t          g ddgd           ddd           n# 1 swxY w Y   t          t          |          5  t          g dd	gt          j        d
gt          j                  t          j        d	gt          j                  t          j        d	gt          j                  f           ddd           dS # 1 swxY w Y   dS )r   zsome peaks have a width of 0rx   r   r+   r   r+   r   r  Nr   r   r  r  )r   r   r   r   rO   rP   r   )rS   r   s     r'   r   zTestPeakWidths.test_warnings  sg    -&c222 	6 	6			A315555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 &c222 	 	!!#2$
!;!;!#1#rw!7!7!#1#rw!7!7!9   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s    ;??A3CC #C c                    g d}dg}t          g d          D ]\  }\  }}}t          j        |t          j                  t          j        |t          j                  t          j        |t          j                  f}|dk     rd}nd}t          t          |          5  t          |||	           d
d
d
           n# 1 swxY w Y   d
S )z4Test with mismatching peak and / or prominence data.r  r+   ))rq   )r:   r   )r   r   )r]   )r   r!  r"  )rq   rq   r   r   r   r   )r#  r"  r!  )r   r$  r!  )r   r"  r%  r   r]   z#prominence data is invalid for peakz4arrays in `prominence_data` must have the same shaperx   r  N)r   r   rO   rP   r   r   r>   r   )	rS   rT   r   r   prominences
left_basesright_basesr  ry   s	            r'    test_mismatching_prominence_dataz/TestPeakWidths.test_mismatching_prominence_data  sC   IIs9B D
 D
 D
 : : 	F 	F5A5Z  "x2:FFF!x
"'BBB!x27CCCEO 1uu=N
%000 F FAt_EEEEF F F F F F F F F F F F F F F%	F 	Fs   "CC	C	c                     g d}t          t          |dgd          g d           t          t          |dgd          g d           dS )	z3Test if x == eval_height counts as an intersection.)r   r+   r   r+   r]   r]   r]   r+   r   r+   r   ri   r   )r   r  ))r  rr   rs   r,  gUUUUUU?))r  r   r+  )g      @N)r   r   )rS   rT   s     r'   test_intersection_rulesz&TestPeakWidths.test_intersection_rules6  sw     .--AaSQ???444	6 	6 	6 	AaSSAAA444	6 	6 	6 	6 	6r)   N)r   r   r   rU   r   r   filterwarningsr   r   r   r   r)  r-  r   r)   r'   r   r     s        & & & [ EFF0 0 GF0.4 4 4L L L@  "F F F2 [ EFF	6 	6 GF	6 	6 	6r)   r   c                  t   t          j        d          } | }|dz   }|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	
          5  t          |t          j        d          |           ddd           n# 1 swxY w Y   t          t          d
          5  t          d|ft          j        d          |           ddd           dS # 1 swxY w Y   dS )zW
    Verify parsing of condition arguments for `scipy.signal.find_peaks` function.
    r[   r+   Nr   NN)r+   NNr   )rr   r
  zarray size of lowerrx   rg   zarray size of upper)r   r   r   r   r   r   r>   )rT   	amin_true	amax_truer   	amin_calc	amax_calcs         r'   test_unpack_condition_argsr6  C  sX    		"AIBIaddOE L2<EJJJKKKI/1e<<<===I/	1eDDDEEEI/	1eDDDEEEI/	1eDDDEEE 29i2H!USSIyIe,---Ie,--- 

"7	8	8	8 @ @y")B--???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @	
"7	8	8	8 H Hi0")B--GGGH H H H H H H H H H H H H H H H H Hs$   )$EE E:&F--F14F1c                       e Zd Zh dZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zej                            dd          d             Zej                            di ddiddiddig          d             ZdS )TestFindPeaks>
   r   left_ips	right_ipsr'  r&  r(  peak_heightswidth_heightsleft_thresholdsright_thresholdsc                     d}t          t          j        d          ||||          \  }}t          |j        dk               | j        D ] }t          ||         j        dk               !dS )z@
        Test behavior for signal without local maxima.
        r0  r[   r  	thresholdr  widthr   N)r   r   r|   r   r   property_keys)rS   open_intervalr   propskeys        r'   test_constantzTestFindPeaks.test_constantf  s     %!"'"++)6--:-Q Q Qu 	
a   % 	* 	*CE#JOq())))	* 	*r)   c                    t          j        g d          }t          j        |j        dz  dz             }||ddd<   t          j        |j        t
                    }|ddd         |ddd<   t          j        ||          }t          |d          \  }}t          |g d           t          |d	         |           t          |d
         ||dz
  dz  z
             t          |d         ||dz  z              t          t          |d          d         g d           t          t          |d          d         g d           t          t          |d          d         ddg           dS )z8
        Test plateau size condition for peaks.
        )r+   r   r]   ra   rc   rl   o   r   r+   Nr   r0  )plateau_size)r+   r]   rf   rg   re   !   rW   plateau_sizesrn   ro   ra   r   )rg   re   rK  rW   )Nr  )r+   r]   rf   )ri   r\   re   rK  )	r   rO   r   r   r|   r/   r   r   r   )rS   rL  rT   repeatsr   rE  s         r'   test_plateau_sizezTestFindPeaks.test_plateau_sizer  s   
 !9!9!9::H]'!+a/00!$Q$'!&,,,!$Q$1Ia!! "!,???uU666777U?+];;;U<(%=13D2J*JKKKU=)5=A3E+EFFF 	Z222157H7H7HIIIZ<<<Q?KKKZ888;b"XFFFFFr)   c                 "   d}t          |d          \  }}t          |t          j        g d                     t          |d         t          j        g d                     t          t          |d          d         t          j        d	d
g                     t          t          |d          d         t          j        dd	g                     t          t          |d          d         t          j        d	g                     dS )z2
        Test height condition for peaks.
        )r  UUUUUU?r  r  r   r  r   r0  )r  r   r;  )rP  r  r  r  r   r]   ri   )Nr]   r+   )r   r]   Nr   r   r   rO   rS   rT   r   rE  s       r'   test_height_conditionz#TestFindPeaks.test_height_condition  s     )!!L999uUBHYYY//000U>*BH^^^,D,DEEEZ#...q128QF3C3CDDDZ)444Q71a&9I9IJJJZ&111!4bhsmmDDDDDr)   c                 P   d}t          |d          \  }}t          |t          j        ddg                     t          |d         t          j        ddg                     t          |d         t          j        dd	g                     t          t          |d          d
         t          j        dg                     t          t          |d          d
         t          j        g                      t          t          |d          d
         t          j        ddg                     t          t          |d          d
         t          j        dg                     t          t          |d          d
         t          j        g                      dS )z5
        Test threshold condition for peaks.
        )r   r   r+   ra   r:   r0  )rA  r+   r]   r=  r   r>  ri   r   r  )Nri   )Nra   )r   ra   NrQ  rR  s       r'   test_threshold_conditionz&TestFindPeaks.test_threshold_condition  sg    !!|<<<uUBHaV,,---U,-rxA/?/?@@@U-.!Q0@0@AAAZQ///2BHaSMMBBBZS111!4bhrllCCCZY777:BHaV<L<LMMMZY777:BHaSMMJJJZV444Q7"FFFFFr)   c                 @   t          j        ddd          }t          j        d          }||xx         t          j        dd|j                  z  cc<   t          t          |d          d         |           t          |d          d         }t          t          j        ||d	          j        dk               t          t          j	        |          d
           g d}t          |d          d         }t          |j        dk    o|d         dk               dS )z4
        Test distance condition for peaks.
        r+      r]   r   distancer   g9m4 @T)assume_uniquert   )r+   r:   r   r[   N)
r   r   r   r.   r   r   r   r   	setdiff1dr   )rS   	peaks_allrT   peaks_subsets       r'   test_distance_conditionz%TestFindPeaks.test_distance_condition  s   
 IaQ''	HRLL	)Aq).999 	ZA...q19=== "!f555a8LyEEEJaO	
 	
 	
 	RW\**A... !!b111!4!Q&?<?a+?@@@@@r)   c                 ,   t          j        ddd          }t          j        ddd          }t          j        dd|j                  }||xx         |z  cc<   ||         ||dz            z
  }d}t          j        |d         |k    ||d         k    z            }t          ||          \  }}t          |||                    t          |d	         ||                    t          |d
         d           t          |d         ||         dz              dS )z6
        Test prominence condition for peaks.
        r   r[   rW   r+   c   r   )r]   rj   )r  r&  r'  r(  N)r   r.   r   r   nonzeror   r   )	rS   rT   
peaks_trueoffsetr&  intervalkeep
peaks_calc
propertiess	            r'   test_prominence_conditionz'TestFindPeaks.test_prominence_condition  s     K2s##Yq"a((
QJO44	*
ma
Q&77za[K'K8A;,FGI I ",A(!C!C!C
JZD!1222Z.D0ABBBZ-q111Z.
40@10DEEEEEr)   c                 V   t          j        g d          }t          |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+   r   r+   r   r:   ra   r   r1  r  )rB  r  r+   rf   r   g?r<  rq   r9  g@r:  g      @N)r   rO   r   r   r   r   rR  s       r'   test_width_conditionz"TestFindPeaks.test_width_condition  s     H11122!!9FFFuUZ###UAh...o.333j)3///k*D11111r)   c                     d}g d}t          |||||          \  }}t          t          |          t          | j                  k               | j        D ]%}t          |j        ||         j        k               &dS )z+
        Test returned properties.
        r0  )
r   r+   r   r   r	  r   r]   r   ri   rj   r@  N)r   r   r-   rC  r   )rS   rD  rT   r   rE  rF  s         r'   test_propertieszTestFindPeaks.test_properties  s     %,,,!!)6--:-Q Q Qu 	E

c$"4555666% 	3 	3CEJ%*/12222	3 	3r)   c                    t          t          d          5  t          t          j        d                     ddd           n# 1 swxY w Y   t          t          d          5  t          t          j        d                     ddd           n# 1 swxY w Y   t          t          d          5  t          t          j        d          d	           ddd           dS # 1 swxY w Y   dS )
z5
        Test exceptions raised by function.
        r   rx   r+   Nr%  rY  r[   r:   rX  )r   r>   r   r   rO   r|   r   r~   s    r'   test_raiseszTestFindPeaks.test_raises  s    Jk222 	$ 	$rx{{###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$Jk222 	( 	(rwv'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(Jj111 	3 	3ry}}r2222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3s5   "AA	A	&"BBB5$C&&C*-C*z(ignore:some peaks have a prominence of 0r  c                    t          g dddd          \  }}t          |d           t          |d         d           t          |d         d           t          |d         d	           d
D ]}t          ||         |           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   r0  r   )r  rB  r   r&  r   r   r<  r+   )r'  r(  r9  r:  N)r   r   )rS   r   rE  rF  s       r'   test_wlen_smaller_plateauz'TestFindPeaks.test_wlen_smaller_plateau  s     "///l(41> > >uUAU=)1---U8_a(((U?+Q///I 	, 	,CsU++++	, 	,r)   kwargsrY  rr   r  r0  rB  r1  c                     t          j        ddd          }|                                }d|j        _        t          |          \  }}t          |fi |\  }}t          ||           dS )z4
        Test readonly arrays are accepted.
        r   r[      FN)r   r.   r;   flags	writeabler   r   )rS   rs  rT   
x_readonlyr   _peaks_readonlys          r'   test_readonly_arrayz!TestFindPeaks.test_readonly_array	  sn     K2r""VVXX
%*
"a==q&z<<V<<~.....r)   N)r   r   r   rC  rG  rN  rS  rU  r`  rj  rl  rn  rp  r   r   r.  rr  r   r{  r   r)   r'   r8  r8  _  sG       ? ? ?M
* 
* 
*G G G0
E 
E 
EG G GA A A4F F F&2 2 23 3 3	3 	3 	3 [ J EG G, ,G G,  [X
	S	|$	)	(  / / / / /r)   r8  c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )TestFindPeaksCwtc                     g d}d}t          ||          \  }}t          j        dt          |                    }t	          ||ddd          }t          j                            ||d           dS )	zX
        Generate a series of gaussians and attempt to find the peak locations.
        rs   rr   r   g      4@r   g      I@r   r   r   r   N)
gap_threshmin_snr
min_lengthz4Found maximum locations did not equal those expected)r2   r   r   r5   r   r   r   )rS   r    
num_pointsr   r   r   
found_locss          r'   test_find_peaks_exactz&TestFindPeaksCwt.test_find_peaks_exact   s     433
1&*EE	83F,,#Iv!Q48: : :


%%j(N	P 	P 	P 	P 	Pr)   c                 b   g d}d}t          ||          \  }}t          j        dt          |                    }d}t          j                            d           |t          j                            |          dz
  d|z  z  z  }t          ||dd	|d
z            }t          j        	                    t          |          t          |          d           t          j        ||z
            }t          j        |          d
z  }	t          j                            ||	dd|	z  z              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   ru  r+   ri   )r  r  r  z,Different numberof peaks found than expectedzMaximum location differedzby more than %sN)r2   r   r   r5   randomseedrandr   r   r   r-   r   rO   r   )
rS   r    r  r   r   r   	noise_ampr  diffs	max_diffss
             r'   test_find_peaks_withnoisez*TestFindPeaksCwt.test_find_peaks_withnoise-  s?   
 433
1&*EE	83F,,	
	x   binnZ00369EE	#Iv"45y1}N N N
 	
JX A? 	@ 	@ 	@zH,--HV$$q(	

$$UI7R%6)%D8E 	F 	F 	F 	F 	Fr)   c                 F   d}d}t           j                            d           t           j                            |          dz
  d|z  z  }t          j        dd          }t          ||dd	
          }t           j                            t          |          d           dS )zQ
        Verify that no peak is found in
        data that's just noise.
        rq   rW   iW
r  r   r[   r\   ri   r   )r  
noise_percr   N)	r   r  r  r  r   r   r   r   r-   )rS   r  r  r   r   r  s         r'   test_find_peaks_nopeakz'TestFindPeaksCwt.test_find_peaks_nopeakC  s    
 	

	y!!!Y^^J//#5)D	2r""#IvqRPPP


J33333r)   c                     t          dd          }t          j        g d          }t          ||t                     }t          j                            t          j        dg          |           d S )N   r   )r+   r   r]   ra   )waveletrW   )r   r   rO   r   r   r   )rS   rT   r   as       r'   )test_find_peaks_with_non_default_waveletsz:TestFindPeaksCwt.test_find_peaks_with_non_default_waveletsP  s`    S!,,,''1fh777

#33333r)   c                 :   ddg}d}t          ||          \  }}t          j        dt          |          d          }d}t          j                            d           |t          j                            |          dz
  d|z  z  z  }|d	d
xx         dz  cc<   t          ||dddd          }t          j	        t                    5  |j        |j        k    sJ 	 ddd           n# 1 swxY w Y   t          ||dddd          }|j        |j        k    sJ dS )zq
        Verify that window_size is passed correctly to private function and
        affects the result.
        r{   r   r   g?皙?r  r  r      i@  r+   r]   N)r  r  r  window_sizerl   )r2   r   r   r5   r  r  r  r   r   r   AssertionErrorr   )rS   r    r  r   r   r   r  r  s           r'   test_find_peaks_window_sizez,TestFindPeaksCwt.test_find_peaks_window_sizeW  s   
 s
1&*EE	83FS11	
	x   binnZ00369EE	 	#c'a#Iv!Q/3G G G
]>** 	4 	4?hm33333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 $Iv!Q/3E E E
(-//////s   	C))C-0C-c                     t          j        dt           j        d          }t          j        |          }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   )rS   xsr   r   r  s        r'   test_find_peaks_with_one_widthz/TestFindPeaksCwt.test_find_peaks_with_one_widthq  sX    
 Yq"%&&F2JJ	#Iv66



B/////r)   N)	r   r   r   r  r  r  r  r  r  r   r)   r'   r}  r}    st        P P PF F F,4 4 44 4 40 0 04
0 
0 
0 
0 
0r)   r}  )$r;   numpyr   numpy.testingr   r   r   r   r   r   r   scipy.signal._peak_findingr	   r
   r   r   r   r   r   r   scipy.signal.windowsr    scipy.signal._peak_finding_utilsr   r   r(   r2   rK   rM   r   r   r   r   r6  r8  r}  r   r)   r'   <module>r     s                                   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 * ) ) ) ) ) R R R R R R R R  ! ! !($ ($ ($V8# 8# 8# 8# 8# 8# 8# 8#v]I ]I ]I ]I ]I ]I ]I ]I@PN PN PN PN PN PN PN PNfr; r; r; r; r; r; r; r;jF6 F6 F6 F6 F6 F6 F6 F6RH H H8|/ |/ |/ |/ |/ |/ |/ |/~]0 ]0 ]0 ]0 ]0 ]0 ]0 ]0 ]0 ]0r)   