403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/scipy/signal/tests/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/scipy/signal/tests/__pycache__/test_peak_finding.cpython-311.pyc
�

d�c����X�ddlZddlZddlmZmZmZmZddlZddlm	Z	m
Z
ddlmZm
Z
mZmZmZmZmZmZddlmZddlmZmZd�Zd�Zd	�ZGd
�d��ZGd�d
��ZGd�d��ZGd�d��ZGd�d��Z d�Z!Gd�d��Z"Gd�d��Z#dS)�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��tjd|���t��}tj|t���}t|��D].\}}|||z
|z}|tj|dz��z
}�/|S)Nr��dtype�)�np�arange�astype�float�zeros�	enumerate�exp)�center_locs�sigmas�total_length�xdata�out_data�ind�sigma�tmps        �F/usr/lib/python3/dist-packages/scipy/signal/tests/test_peak_finding.py�_gen_gaussiansr(s����I�a��&�&�-�-�e�4�4�E��x��E�2�2�2�H���'�'�&�&�
��U��{�3�'�'�5�0���B�F�S�!�V�9�%�%�%����O�c��t|��}||dzz}tj|||z
|����t��}t|||��}||fS)N�)�num)�lenr�linspacer�intr()r r!�	num_peaks�deltarr#s      r'�_gen_gaussians_evenr2$sa���F���I��I��M�*�E��+�e�\�E�%9�y�I�I�I�P�P�QT�U�U�K��k�6�<�@�@�H��[� � r)c�*�d�}tj|��}tj|��}tj|dgt���}||ddd�f<|d|dz
t|��z
}||krt
d���|t|��zdz
}|t|��zdz
}	td|��D]�}
||
dz
df}||
dz
dfdz}|
|zdkr0t|��dkr|d|
z|�	��zz
}|
|	zdkr*t|��dkr||�	��z
}|||d��}|||d��}||g||
dd�f<��|dd�df|dd�dfgS)	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#���#�q�k�k���#�w�����
r)rrrNz3Cannot generate ridge line according to constraintsr+���)
�copy�deepcopyrrr/�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�
�8�V�Q�K�s�+�+�+�D��D��A�A�A��J��A�;��A��.��T���:�L��f����N�O�O�O���I���&��*�H��s�4�y�y� �1�$�G��Q����	*�	*���s�Q�w��z�"���s�Q�w��z�"�Q�&���(�N�a���c�)�n�n�q�&8�&8���c�	�9�=�=�?�?�2�2�G��'�M�Q���S��Y�Y��]�]��t�x�x�z�z�!�G��+�g�x��{�3�3���+�g�x��{�3�3����)��S�!�!�!�V�������A��J��Q�Q�Q��T�
�#�#r)c	���eZdZd�Zd�Zd�Zd�Zej�	de
jgd���e
jgd���e
jgd���g��d	���Zd
�Z
dS)�TestLocalMaxima1dc���tjgtj���}t|��D]:}t	|tjg����t|jdu���;dS)zTest with empty signal.rN)r�array�float64rrr�base��self�xrOs   r'�
test_emptyzTestLocalMaxima1d.test_emptyYsi���H�R�r�z�*�*�*��%�a�(�(�	(�	(�E��������-�-�-��E�J�$�&�'�'�'�'�	(�	(r)c���tjdd��}t|��D]:}t|tjg����t|jdu���;dS)zTest with linear signal.r�dN)rr.rrrOrrQrRs   r'�test_linearzTestLocalMaxima1d.test_linear`sd���K��3����%�a�(�(�	(�	(�E��������-�-�-��E�J�$�&�'�'�'�'�	(�	(r)c���tjddd��}|ddd�xxdz
cc<tjddd��}t|��D](}t	||��t|jdu���)dS)zTest with simple signal.����
�2rN�r+)rr.rrrrrQ)rSrT�expectedrOs    r'�test_simplezTestLocalMaxima1d.test_simplegs����K��R��$�$��	�!�$�Q�$����1������9�Q��A�&�&��%�a�(�(�	(�	(�E�
���)�)�)��E�J�$�&�'�'�'�'�		(�	(r)c�0�tjgd���}t|��\}}}t|tjgd�����t|tjgd�����t|tjgd�����dS)z+Test if flat maxima are detected correctly.)g�������rr+rrrrr]r]r]g�Q���@�rarararZ���rbrbrbrbrZ)rra���)rra���)r��	��N)rrOrr)rSrT�	midpoints�
left_edges�right_edgess     r'�test_flat_maximaz"TestLocalMaxima1d.test_flat_maximars����H�/�/�/�
0�
0��-=�a�-@�-@�*�	�:�{��Y���):�):�):� ;� ;�<�<�<��Z���*;�*;�*;�!<�!<�=�=�=��[�"�(�+<�+<�+<�"=�"=�>�>�>�>�>r)rT)��?rr)�@r]rrara)�@ririr�rtrtc��t|��D]:}t|tjg����t	|jdu���;dS)z,Test if behavior on signal edges is correct.N)rrrrOrrQrRs   r'�test_signal_edgesz#TestLocalMaxima1d.test_signal_edges{sU��&�a�(�(�	(�	(�E��������-�-�-��E�J�$�&�'�'�'�'�	(�	(r)c�J�ttd���5ttjd����ddd��n#1swxYwYttd���5ttjdt
�����ddd��n#1swxYwYttd���5td	d
g��ddd��n#1swxYwYttd���5td��ddd��dS#1swxYwYdS)z,Test input validation and raised exceptions.zwrong number of dimensions��match)r+r+Nzexpected 'const float64_t'r+r�listrq�@z'x' must not be None)rr>rr�onesr/�	TypeError�rSs r'�test_exceptionsz!TestLocalMaxima1d.test_exceptions�s��
�J�&B�
C�
C�
C�	.�	.��R�W�V�_�_�-�-�-�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.�
�J�&B�
C�
C�
C�	4�	4��R�W�Q�c�2�2�2�3�3�3�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4����	4�	4�	4�	4�
�I�V�
,�
,�
,�	'�	'��b�"�X�&�&�&�	'�	'�	'�	'�	'�	'�	'�	'�	'�	'�	'����	'�	'�	'�	'�
�I�%;�
<�
<�
<�	#�	#��T�"�"�"�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#����	#�	#�	#�	#�	#�	#sG�"A�A	�A	�&)B�B�"B�<C�C�!C�;D�D�DN)�__name__�
__module__�__qualname__rUrXr_rp�pytest�mark�parametrizerrOrvr�r)r'rMrMWs�������(�(�(�(�(�(�	(�	(�	(�?�?�?��[���S������������!�!�!�"�"����'�'�'�(�(�#���
(�(���
(�	#�	#�	#�	#�	#r)rMc�2�eZdZd�Zd�Zd�Zd�Zd�Zd�ZdS)�TestRidgeLinesc��tjddg��}t|tjdd��d��}t	t|��dk��dS)NrlrWrr+r�rrr�fullrr-�rS�	test_matr�liness   r'rUzTestRidgeLines.test_empty�sN���H�b�#�Y�'�'�	�%�i����Q����C�C����E�
�
�a�� � � � � r)c��tjddg��}d|d<t|tjdd��d��}t	t|��dk��tjddg��}d|dd�df<t|tjdd��d��}t	t|��dk��dS)NrlrWr+)rr[rrr[r�r�s   r'�test_minimalzTestRidgeLines.test_minimal�s����H�b�#�Y�'�'�	��	�%��%�i����Q����C�C����E�
�
�a�� � � ��H�b�#�Y�'�'�	��	�!�A�#�r�'��%�i����Q����C�C����E�
�
�a�� � � � � r)c�N�gd�}gd�}tjddg��dz}d}tddg|j|||��}d	||d|d	f<tjdt|����}t
||t|��d	z��}t||g��dS)
N�rr+rri)rr+rrr+rlr\g�-���q=rdr�r+)rrrK�shaper�r5rr)rSrDrEr�rC�line�
max_distances�identified_liness        r'�test_single_passzTestRidgeLines.test_single_pass�s��� �L�L�	������H�b�"�X�&�&��.�	�����2�w�	����D�Q�Q��&'�	�$�q�'�4��7�"�#����C�	�N�N�3�3�
�0��M�3�t�9�9�WX�=�Y�Y���+�d�V�4�4�4�4�4r)c��gd�}gd�}tjddg��}d}tddg|j|||��}d||d|df<d	}tjd|��}t||t
|��dz��}tt|��d
k��|D]�}	tj	|	d��}
tj
�tj|
��|��tj	|	d��}tj
�tj|��t
|��dz����dS)Nr�)rr+rrarlr\rdrr�r+r]r皙�����?)
rrrKr�r�rr5rr-�diff�testing�assert_array_less�abs)rSrDrEr�rCr��max_distr�r��iline�adists�agapss            r'�test_single_bigdistz"TestRidgeLines.test_single_bigdist�s=�� �L�L�	��|�|���H�b�"�X�&�&�	�����2�w�	����D�Q�Q��&'�	�$�q�'�4��7�"�#������H�-�-�
�0��M�3�t�9�9�WX�=�Y�Y����$�%�%��*�+�+�+�%�	I�	I�E��W�U�1�X�&�&�F��J�(�(�������B�B�B��G�E�!�H�%�%�E��J�(�(�������D�	�	�C��H�H�H�H�	I�	Ir)c��gd�}d}gd�}tjddg��}d}tddg|j|||��}d	||d|d	f<d
}tjd|��}t|||��}	t
t|	��dk��|	D]�}
tj|
d	��}tj	�
tj|��|��tj|
d��}tj	�
tj|��t|��dz����dS)
Nr�r])rrarr+rlr\rdrr�r+rtrr��
rrrKr�r�rrr-r�r�r�r�r5�
rSrD�max_gaprEr�rCr�r�r�r�r�r�r�s
             r'�test_single_biggapz!TestRidgeLines.test_single_biggap�s7�� �L�L�	����|�|���H�b�"�X�&�&�	�����2�w�	����D�Q�Q��&'�	�$�q�'�4��7�"�#������H�-�-�
�0��M�7�S�S����$�%�%��*�+�+�+�%�	I�	I�E��W�U�1�X�&�&�F��J�(�(�������B�B�B��G�E�!�H�%�%�E��J�(�(�������D�	�	�C��H�H�H�H�	I�	Ir)c��dg}d}ddg}tjddg��}d}tddg|j|||��}d||d|df<d}tjd|��}t|||��}	t
t|	��dk��|	D]�}
tj|
d��}tj	�
tj|��|��tj|
d��}tj	�
tj|��t|��dz����dS)	Nrr+r]rtr\�r�r�r�r�s
             r'�test_single_biggapsz"TestRidgeLines.test_single_biggaps�s5���C�	����1�v���H�b�"�X�&�&�	�����2�w�	����D�Q�Q��&'�	�$�q�'�4��7�"�#������H�-�-�
�0��M�7�S�S����$�%�%��*�+�+�+�%�	I�	I�E��W�U�1�X�&�&�F��J�(�(�������B�B�B��G�E�!�H�%�%�E��J�(�(�������D�	�	�C��H�H�H�H�	I�	Ir)N)	r�r�r�rUr�r�r�r�r�r�r)r'r�r��sy������!�!�!�
	!�	!�	!�	5�	5�	5�I�I�I�(I�I�I�*I�I�I�I�Ir)r�c�&�eZdZd�Zd�Zd�Zd�ZdS)�
TestArgrelc���tjgt���}tjd��}t	|��}tt
|��d��t|d|��tjd��}t	|d���\}}t||��t||��t	|d���\}}t||��t||��dS)Nrrir+r)r]ri��axis)rrOr/rr
rr-r)rS�empty_array�z1�i�z2�row�cols       r'rUzTestArgrel.test_empty�s����h�r��-�-�-��
�X�a�[�[���b�M�M���S��V�V�Q�����1�Q�4��-�-�-�
�X�e�_�_���R�a�(�(�(���S��3��,�,�,��3��,�,�,��R�a�(�(�(���S��3��,�,�,��3��,�,�,�,�,r)c��tjgd�gd�gd�gd�gd�g��}t|d���\}}tj|��}t	||gd���t	||gd	���t|d
���\}}tj|��}t	||gd���t	||gd���t|d���\}}tj|��}t	||gd���t	||gd���t|d
���\}}tj|��}t	||gd���t	||gd���dS)
N)r+rrr]r)rr+rrr])r]rr+rr)rr]rr+r)r+rr]rr+rr��r+rr])rarr+r+)rr]ra)r]r+r)rrOr	�argsortrr
)rSrTr�r��orders     r'�
test_basiczTestArgrel.test_basics���

�H�o�o�o�%�o�o�%�o�o�%�o�o�%�o�o�	'�
(�
(���Q�Q�'�'�'���S��
�3�����S��Z����+�+�+��S��Z����+�+�+��Q�Q�'�'�'���S��
�3�����S��Z����+�+�+��S��Z����+�+�+��Q�Q�'�'�'���S��
�3�����S��Z����+�+�+��S��Z����+�+�+��Q�Q�'�'�'���S��
�3�����S��Z����+�+�+��S��Z����+�+�+�+�+r)c�P�d}gd�}t|d��\}}||dz|||z<||dz|||z
<t||d���d}tt|��t|��k��t||k�����dS)Nr)rqr{�$@rsg.@��gwJ��?�clip)r��moder)r2r	rr-�all)rSr�r �	test_data�act_locs�rel_max_locss      r'�test_highorderzTestArgrel.test_highorder's�����,�,�,��1�&�#�>�>��	�8�&/��&9�'�&A�	�(�U�"�#�&/��&9�'�&A�	�(�U�"�#� ��%�f�E�E�E�a�H����L�!�!�S��]�]�2�3�3�3����)�.�.�0�0�1�1�1�1�1r)c���gd�}t|d��\}}d}tjdt|����|z
}tj|||g��}t|dd���\}}t
d|jd��D]l}	||	k}
tt||
��t|��k��t|||
||	zz
k�	�����mdS)N)rqr{r�rWrlrr+)r�r�)
r2rrr-�vstackr	r?r�rr�)rSr r�r��
rot_factor�	rot_range�test_data_2�rel_max_rows�rel_max_cols�rw�indss           r'�test_2d_gaussianszTestArgrel.test_2d_gaussians2s��!�!�!��1�&�#�>�>��	�8��
��I�a��Y���0�0�:�=�	��i��I�i�,@� A�B�B��%.�{��!�%L�%L�%L�"��l���;�,�Q�/�0�0�	N�	N�B� �B�&�D��C��T�*�+�+�s�8�}�}�<�=�=�=��X�,�t�"4�z�"�}�"D�E�J�J�L�L�M�M�M�M�		N�	Nr)N)r�r�r�rUr�r�r�r�r)r'r�r��sU������-�-�-�0,�,�,�>	2�	2�	2�N�N�N�N�Nr)r�c�8�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	dS)	�TestPeakProminencesc���tgd�g��}t|tjtjtjg��D]5\}}t|jdk��t|j|k���6tgg��}t|tjtjtjg��D]5\}}t|jdk��t|j|k���6dS)�N
        Test if an empty array is returned if no peaks are provided.
        r�rN)r�ziprrP�intpr�sizer)rSr8�arrrs    r'rUzTestPeakProminences.test_emptyCs����y�y�y�"�-�-���c�B�J�����#A�B�B�	(�	(�J�C���C�H��M�"�"�"��C�I��&�'�'�'�'��r�2�&�&���c�B�J�����#A�B�B�	(�	(�J�C���C�H��M�"�"�"��C�I��&�'�'�'�'�	(�	(r)c��tjgd���}tjgd���}tjgd���}tjgd���}||tj||||gd���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+rrart)rrrri)r]r]rirfrr�r+rN)rrOr5rr)rSrT�peaks�lbases�rbases�promsr8s       r'r�zTestPeakProminences.test_basicQs���
�H�;�;�;�<�<�������&�&����,�,�,�'�'����,�,�,�'�'���%��2�6�1�V�9�a��i�"8�q�A�A�A�A���q�%�(�(���S��V�U�#�#�#��S��V�V�$�$�$��S��V�V�$�$�$�$�$r)c�v�gd�}gd�}t||��\}}}t|gd���t|gd���t|gd���gd�}tjgd���}t||��\}}}t|gd���t||dz
��t||dz��d	S)
z"
        Test edge cases.
        )rrr+rr+rr�r+r]ri)rrr)rrr)rtrtrt)rr+rr+rr+r)r+r+r+r+N)rrrrO�rSrTr�r�r�r�s      r'�test_edge_casesz#TestPeakProminences.test_edge_casesbs���

"�!�!���	�	�� 0��E� :� :���v�v��U�I�I�I�&�&�&��V�Y�Y�Y�'�'�'��V�Y�Y�Y�'�'�'�
"�!�!�������#�#�� 0��E� :� :���v�v��U�I�I�I�&�&�&��V�U�Q�Y�'�'�'��V�U�Q�Y�'�'�'�'�'r)c��tjgd�d��}tjgd�d��}t|ddd�|ddd���\}}}t|gd���t|gd���t|gd���dS)�:
        Test with non-C-contiguous input arrays.
        )i����rjrjrr]r+r)r+rraN)rjrjr)rrr])r]r]ri)r�repeatrrr�s      r'�test_non_contiguousz'TestPeakProminences.test_non_contiguousvs���
�I�)�)�)�1�-�-���	�)�)�)�Q�'�'�� 0��3�3�Q�3���s�s��s�� D� D���v�v��U�I�I�I�&�&�&��V�Y�Y�Y�'�'�'��V�Y�Y�Y�'�'�'�'�'r)c��gd�}dg}tt||��gd���dD]0\}}tt|||��d|z
d|zd|z
g���1dS)	zO
        Test if wlen actually shrinks the evaluation range correctly.
        )rr+rr]r+rr:r])rrrrt))rcr)rfr)rtr)rir+)r�r+�r]r)皙�����?rrrrrtN)rr)rSrT�peak�wlenr�s     r'�	test_wlenzTestPeakProminences.test_wlen�s���
#�"�"���s���%�a��.�.�
�
�
�;�;�;�S�	R�	R�G�D�!��)�!�T�4�8�8�2��6�1�q�5�!�a�%�:P�Q�Q�Q�Q�	R�	Rr)c���ttd���5tgd�gddg��ddd��n#1swxYwYttd���5tgd�ddgg��ddd��n#1swxYwYttd���5tddg��ddd��n#1swxYwYttd	���5tgdg��ddd��n#1swxYwYd
D]C}ttd	���5tgd�|g��ddd��n#1swxYwY�Dttd���5tgd�d
dg��ddd��n#1swxYwYttd���5tt	jd��ddgd���ddd��dS#1swxYwYdS)zA
        Verify that exceptions and warnings are raised.
        �	1-D arrayrx)rr+r+rr+rNr]r�not a valid index)i����r:r]���r+rr�cannot safely castr��ffffff@r�r[ri�r�)rr>rr}rr)rS�ps  r'rz#TestPeakProminences.test_exceptions�s���
�J�k�
2�
2�
2�	5�	5��l�l�l�^�a��V�4�4�4�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5����	5�	5�	5�	5��J�k�
2�
2�
2�	5�	5��\�\�\�Q��F�8�4�4�4�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5����	5�	5�	5�	5��J�k�
2�
2�
2�	&�	&��Q���%�%�%�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&����	&�	&�	&�	&��J�&9�
:�
:�
:�	&�	&��R�!��%�%�%�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&����	&�	&�	&�	&�%�	1�	1�A��
�*=�>�>�>�
1�
1� ����Q�C�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��J�f�
-�
-�
-�	<�	<��R�Y�r�]�]�Q��F��;�;�;�;�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<����	<�	<�	<�	<�	<�	<sy�9�=�=�A<�<B�B�B;�;B?�B?�C:�:C>�C>�D?�?E	�E	�!F�F�	F�#'G�G�Gc��d}dD]C}tt|���5tgd�|g��ddd��n#1swxYwY�Dtt|���5tgd�dgd���ddd��dS#1swxYwYdS)	�>
        Verify that appropriate warnings are raised.
        z!some peaks have a prominence of 0)rr+rrxr�N�rr+r+r+rrr�)rrr)rS�msgr�s   r'�
test_warningsz!TestPeakProminences.test_warnings�s+��2���	2�	2�A��*�#�6�6�6�
2�
2� ����Q�D�1�1�1�
2�
2�
2�
2�
2�
2�
2�
2�
2�
2�
2����
2�
2�
2�
2��
�&�c�
2�
2�
2�	;�	;��_�_�_�q�c��:�:�:�:�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;����	;�	;�	;�	;�	;�	;s!�=�A	�A	�B�B�	BN)
r�r�r�rUr�r�r�r�rr�r�r)r'r�r�As�������(�(�(�%�%�%�"(�(�(�(	(�	(�	(�	R�	R�	R�<�<�<�<	;�	;�	;�	;�	;r)r�c��eZdZd�Zej�d��d���Zd�Zd�Z	d�Z
d�Zej�d��d���Zd	S)
�TestPeakWidthsc���tgg��d}tt|tj����t|jd��tgd�g��d}tt|tj����t|jd��tgg��}|D]>}tt|tj����t|jd���?dS)r�rr�N)rr�
isinstancer�ndarrayrr�)rS�widthsr8r�s    r'rUzTestPeakWidths.test_empty�s����R��$�$�Q�'���
�6�2�:�.�.�/�/�/��V�[�!�$�$�$��Y�Y�Y��+�+�A�.���
�6�2�:�.�.�/�/�/��V�[�!�$�$�$��"�b�!�!���	&�	&�C��J�s�B�J�/�/�0�0�0����1�%�%�%�%�	&�	&r)�#ignore:some peaks have a width of 0c��tjgd���}d}dD]d\}}}}t|dg|��\}}}	}
t||��t|d||zz
��t|	|��t|
|���edS)zk
        Test a simple use case with easy to verify results at different relative
        heights.
        )r+rr+rr+rr:r))�rrrrr)g�?rq�@�@)��?r{r{�@)��?rr��?�@)rqrrqrs)r{rsrq�@)rrrsrqrr]N)rrOrr)rSrT�
prominence�
rel_height�
width_true�lip_true�rip_true�
width_calc�height�lip_calc�rip_calcs           r'r�zTestPeakWidths.test_basic�s���
�H�+�+�+�,�,���
�;
�	0�	0�6�J�
�H�h�6A��A�3�
�6$�6$�2�J���(��J�
�3�3�3��F�A�
�Z�(?�$?�@�@�@��H�h�/�/�/��H�h�/�/�/�/�	0�	0r)c���tjgd�d��}tjdgd��}t|ddd�|ddd���}t|gd���dS)r�)rrWr\rar+r]N)r�Krr	)rr�rr)rSrTr��results    r'r�z"TestPeakWidths.test_non_contiguous�sl��
�I�l�l�l�A�&�&���	�1�#�q�!�!���Q�s�s��s�V�U�3�3�Q�3�Z�0�0���V�2�2�2�3�3�3�3�3r)c��ttd���5ttjd��tjd����ddd��n#1swxYwYttd���5tddg��ddd��n#1swxYwYttd���5ttjd��tjdtj�	����ddd��n#1swxYwYttd���5ttjd��d��ddd��n#1swxYwYttd
���5ttjd��ddg��ddd��n#1swxYwYttd
���5tgd
dg��ddd��n#1swxYwYttd���5ttjd��ddg��ddd��n#1swxYwYttd���5tgd�d
dgd���ddd��n#1swxYwYttd���5tgd�d
gd���ddd��dS#1swxYwYdS)zD
        Verify that argument validation works as intended.
        r�rx)r]rar]Nrr[r�rr�rcrgr+rr�r�r�r
)rr+rr+rr:�r
�None)r+rr+)NNN��prominence_data)	rr>rrrr|rr�r}r~s r'rzTestPeakWidths.test_exceptions�s����J�k�
2�
2�
2�	6�	6�����(�(�"�'�!�*�*�5�5�5�	6�	6�	6�	6�	6�	6�	6�	6�	6�	6�	6����	6�	6�	6�	6��J�k�
2�
2�
2�	 �	 ���A�3����	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 ��J�k�
2�
2�
2�	G�	G���	�"�
�
�r�w�v�R�W�'E�'E�'E�F�F�F�	G�	G�	G�	G�	G�	G�	G�	G�	G�	G�	G����	G�	G�	G�	G��J�k�
2�
2�
2�	*�	*���	�"�
�
�q�)�)�)�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*����	*�	*�	*�	*��J�&9�
:�
:�
:�	0�	0���	�"�
�
��2�w�/�/�/�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0����	0�	0�	0�	0��J�&9�
:�
:�
:�	$�	$���Q��F�#�#�#�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$����	$�	$�	$�	$��I�%9�
:�
:�
:�	3�	3���	�"�
�
��S�z�2�2�2�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3����	3�	3�	3�	3��J�l�
3�
3�
3�	@�	@�����!�Q��B�?�?�?�?�	@�	@�	@�	@�	@�	@�	@�	@�	@�	@�	@����	@�	@�	@�	@��I�V�
,�
,�
,�	L�	L��	�	�	�A�3�8J�K�K�K�K�	L�	L�	L�	L�	L�	L�	L�	L�	L�	L�	L�	L����	L�	L�	L�	L�	L�	Ls��5A�A�A�9B�B�B�8AD�D	�D	�&#E�E�E�6%F'�'F+�.F+�G'�'G+�.G+�%H9�9H=�H=�I=�=J�J�K�K�Kc���d}tt|���5tgd�dgd���ddd��n#1swxYwYtt|���5tgd�d	gtjd
gtj��tjd	gtj��tjd	gtj��f���ddd��dS#1swxYwYdS)r�zsome peaks have a width of 0rx�rr+rr+rrNr�rrr)rrrrrOrPr�)rSr�s  r'r�zTestPeakWidths.test_warningssg��-��
�&�c�
2�
2�
2�	6�	6��	�	�	�A�3�1�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�#�r�w�!7�!7�!#��1�#�r�w�!7�!7�!9�
�
�
�
�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s �;�?�?�A3C�C �#C c��gd�}dg}tgd���D]�\}\}}}tj|tj���tj|tj���tj|tj���f}|dkrd}nd}tt|���5t|||�	��d
d
d
��n#1swxYwY��d
S)z4Test with mismatching peak and / or prominence data.rr+))�rq)r:�r)r �r)r])r r!r")�rqrq�rr�rr)r#r"r!)r r$r!)r r"r%rr]z#prominence data is invalid for peakz4arrays in `prominence_data` must have the same shaperxrN)rrrOrPr�rr>r)	rSrTr�r��prominences�
left_bases�right_basesrrys	         r'� test_mismatching_prominence_dataz/TestPeakWidths.test_mismatching_prominence_datasC���I�I���s��9B�D
�D
�D
�:�:�	F�	F�5�A�5��Z�� "�x��2�:�F�F�F�!�x�
�"�'�B�B�B�!�x��2�7�C�C�C�E�O��1�u�u�=���N���
�%�0�0�0�
F�
F��A�t�_�E�E�E�E�
F�
F�
F�
F�
F�
F�
F�
F�
F�
F�
F����
F�
F�
F�
F��%	F�	Fs�"C�C	�C	c��gd�}tt|dgd���gd���tt|dgd���gd���dS)	z3Test if x == eval_height counts as an intersection.)rr+rr+r]r]r]r+rr+rrir)r�r
))r�rr�rsr,gUUUUUU�?))rr r+)g@N)rr)rSrTs  r'�test_intersection_rulesz&TestPeakWidths.test_intersection_rules2sw��
.�-�-����A�a�S�Q�?�?�?�4�4�4�	6�	6�	6�	��A�a�S�S�A�A�A�4�4�4�	6�	6�	6�	6�	6r)N)
r�r�r�rUr�r��filterwarningsr�r�rr�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�tjd��}|}|dz}|ddd�}tdtd||��k��tdtd||��k��tdtd||��k��tdtd||��k��tdtd||��k��t||f||��\}}t	|||��t	|||��ttd	�
��5t|tjd��|��ddd��n#1swxYwYttd�
��5td|ftjd��|��ddd��dS#1swxYwYdS)
zW
    Verify parsing of condition arguments for `scipy.signal.find_peaks` function.
    r[r+Nr�NN)r+N�Nr)rrr
zarray size of lowerrxrgzarray size of upper)rrrr
rrr>)rT�	amin_true�	amax_truer��	amin_calc�	amax_calcs      r'�test_unpack_condition_argsr6?sX��	�	�"�
�
�A��I��B��I��a�d��d�O�E��L�2�<��E�J�J�J�K�K�K��I�/��1�e�<�<�<�=�=�=��I�/�	�1�e�D�D�D�E�E�E��I�/�	�1�e�D�D�D�E�E�E��I�/�	�1�e�D�D�D�E�E�E�2�9�i�2H�!�U�S�S��I�y���I�e�,�-�-�-���I�e�,�-�-�-�
�
�"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�Hs$�)$E�E� E�:&F-�-F1�4F1c���eZdZhd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Ze
j�dd��d
���Ze
j�diddiddiddig��d���ZdS)�
TestFindPeaks>
r�left_ips�	right_ipsr'r&r(�peak_heights�
width_heights�left_thresholds�right_thresholdsc���d}ttjd��||||���\}}t|jdk��|jD] }t||jdk���!dS)z@
        Test behavior for signal without local maxima.
        r0r[�r�	thresholdr�widthrN)rrr|rr��
property_keys)rS�
open_intervalr��props�keys     r'�
test_constantzTestFindPeaks.test_constantbs���%�
�!�"�'�"�+�+�)6�-�-:�-�Q�Q�Q���u�	��
�a�� � � ��%�	*�	*�C��E�#�J�O�q�(�)�)�)�)�	*�	*r)c���tjgd���}tj|jdzdz��}||ddd�<tj|jt
���}|ddd�|ddd�<tj||��}t|d���\}}t|gd���t|d	|��t|d
||dz
dzz
��t|d||dzz��tt|d���d
gd���tt|d���d
gd���tt|d���d
ddg��dS)z8
        Test plateau size condition for peaks.
        )r+rr]rarcrl�orr+Nrr0)�plateau_size)r+r]rfrgre�!rW�
plateau_sizesrnrorar)rgrerKrW)Nr)r+r]rf)rir\rerK)	rrOrr�r|r/r�rr)rSrLrT�repeatsr�rEs      r'�test_plateau_sizezTestFindPeaks.test_plateau_sizens���
��!9�!9�!9�:�:�
��H�]�'�!�+�a�/�0�0����!�$�Q�$���'�!�&��,�,�,���!�$�Q�$�����1��
��I�a��!�!��"�!�,�?�?�?���u��U�6�6�6�7�7�7��U�?�+�]�;�;�;��U�<�(�%�=�1�3D��2J�*J�K�K�K��U�=�)�5�=�A�3E�+E�F�F�F�	�Z���2�2�2�1�5�7H�7H�7H�I�I�I��Z���<�<�<�Q�?����K�K�K��Z���8�8�8��;�b�"�X�F�F�F�F�Fr)c�"�d}t|d���\}}t|tjgd�����t|dtjgd�����tt|d���dtjd	d
g����tt|d���dtjdd	g����tt|d
���dtjd	g����dS)z2
        Test height condition for peaks.
        )r�UUUUUU�?rrrrrr0)rr�r;)rPrrrrr]ri)Nr]r+)rr]N�rrrrO�rSrTr�rEs    r'�test_height_conditionz#TestFindPeaks.test_height_condition�s���
)��!�!�L�9�9�9���u��U�B�H�Y�Y�Y�/�/�0�0�0��U�>�*�B�H�^�^�^�,D�,D�E�E�E��Z��#�.�.�.�q�1�2�8�Q��F�3C�3C�D�D�D��Z��)�4�4�4�Q�7���1�a�&�9I�9I�J�J�J��Z��&�1�1�1�!�4�b�h��s�m�m�D�D�D�D�Dr)c�P�d}t|d���\}}t|tjddg����t|dtjddg����t|dtjdd	g����tt|d���d
tjdg����tt|d���d
tjg����tt|d���d
tjddg����tt|d
���d
tjdg����tt|d���d
tjg����dS)z5
        Test threshold condition for peaks.
        )rrr+rar:r0)rAr+r]r=rr>rirr)Nri)Nra)rraNrQrRs    r'�test_threshold_conditionz&TestFindPeaks.test_threshold_condition�sg��
��!�!�|�<�<�<���u��U�B�H�a��V�,�,�-�-�-��U�,�-�r�x��A��/?�/?�@�@�@��U�-�.���!�Q��0@�0@�A�A�A��Z��Q�/�/�/��2�B�H�a�S�M�M�B�B�B��Z��S�1�1�1�!�4�b�h�r�l�l�C�C�C��Z��Y�7�7�7��:�B�H�a��V�<L�<L�M�M�M��Z��Y�7�7�7��:�B�H�a�S�M�M�J�J�J��Z��V�4�4�4�Q�7���"���F�F�F�F�Fr)c�@�tjddd��}tjd��}||xxtjdd|j��z
cc<tt
|d���d|��t
|d���d}ttj||d�	��jdk��ttj	|��d
��gd�}t
|d���d}t|jdko|ddk��d
S)z4
        Test distance condition for peaks.
        r+�r]r��distancerg9��m4@T)�
assume_uniquert)���r+r:r���r[N)
rrrr.r�rrr�	setdiff1dr�)rS�	peaks_allrT�peaks_subsets    r'�test_distance_conditionz%TestFindPeaks.test_distance_condition�s��
�I�a��Q�'�'�	��H�R�L�L��	�)������A�q�)�.�9�9�9����	�Z��A�.�.�.�q�1�9�=�=�=�"�!�f�5�5�5�a�8����L��y��E�E�E�J�a�O�	
�	
�	
�	�R�W�\�*�*�A�.�.�.�
����!�!�b�1�1�1�!�4����!�Q�&�?�<��?�a�+?�@�@�@�@�@r)c�,�tjddd��}tjddd��}tjdd|j��}||xx|z
cc<||||dzz
}d}tj|d|k||dkz��}t||���\}}t
|||��t
|d	||��t
|d
d��t
|d||dz��dS)
z6
        Test prominence condition for peaks.
        rr[rWr+�cr)r]rj)rr&r'r(N)rr.rr��nonzerorr)	rSrT�
peaks_true�offsetr&�interval�keep�
peaks_calc�
propertiess	         r'�test_prominence_conditionz'TestFindPeaks.test_prominence_condition�s ��
�K��2�s�#�#���Y�q�"�a�(�(�
���Q��J�O�4�4��	�*�
�
�
���
�
�
��
�m�a�
�Q��&7�7�����z�
�a�[�K�
'�K�8�A�;�,F�G�I�I��",�A�(�!C�!C�!C��
�J��Z��D�!1�2�2�2��Z�
�.��D�0A�B�B�B��Z��-�q�1�1�1��Z�
�.�
�4�0@�1�0D�E�E�E�E�Er)c�V�tjgd���}t|dd���\}}t|jd��t|d��t|dd��t|d	d
��t|dd��t|d
d��dS)z1
        Test width condition for peaks.
        )	r+rr+rr+rr:rarr1r)rBr
r+rfrg�������?r<rqr9g������@r:g@N)rrOrrr�rrRs    r'�test_width_conditionz"TestFindPeaks.test_width_condition�s���
�H�1�1�1�2�2��!�!�9��F�F�F���u��U�Z��#�#�#��U�A������h���.�.�.���o�.��3�3�3���j�)�3�/�/�/���k�*�D�1�1�1�1�1r)c��d}gd�}t|||||���\}}tt|��t|j��k��|jD]%}t|j||jk���&dS)z+
        Test returned properties.
        r0)
rr+rrr	rr]rrirjr@N)rrr-rCr�)rSrDrTr�rErFs      r'�test_propertieszTestFindPeaks.test_properties�s���%�
�,�,�,��!�!�)6�-�-:�-�Q�Q�Q���u�	��E�
�
�c�$�"4�5�5�5�6�6�6��%�	3�	3�C��E�J�%��*�/�1�2�2�2�2�	3�	3r)c���ttd���5ttjd����ddd��n#1swxYwYttd���5ttjd����ddd��n#1swxYwYttd���5ttjd��d�	��ddd��dS#1swxYwYdS)
z5
        Test exceptions raised by function.
        r�rxr+Nr%rYr[r:rX)rr>rrrOr|rr~s r'�test_raiseszTestFindPeaks.test_raises�s����J�k�
2�
2�
2�	$�	$��r�x��{�{�#�#�#�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$����	$�	$�	$�	$�
�J�k�
2�
2�
2�	(�	(��r�w�v���'�'�'�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(����	(�	(�	(�	(�
�J�j�
1�
1�
1�	3�	3��r�y��}�}�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 0rc��tgd�ddd���\}}t|d��t|dd��t|dd��t|dd	��d
D]}t|||���dS)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�r0r)rrBr�r&rrr<r+)r'r(r9r:N)rr)rSr�rErFs    r'�test_wlen_smaller_plateauz'TestFindPeaks.test_wlen_smaller_plateau�s���"�/�/�/�l�(4�1�>�>�>���u��U�A�����U�=�)�1�-�-�-��U�8�_�a�(�(�(��U�?�+�Q�/�/�/�I�	,�	,�C���s��U�+�+�+�+�	,�	,r)�kwargsrYrrrr0rBr1c���tjddd��}|���}d|j_t|��\}}t|fi|��\}}t
||��dS)z4
        Test readonly arrays are accepted.
        rr[�FN)rr.r;�flags�	writeablerr)rSrsrT�
x_readonlyr��_�peaks_readonlys       r'�test_readonly_arrayz!TestFindPeaks.test_readonly_arraysn��
�K��2�r�"�"���V�V�X�X�
�%*�
��"��a�=�=���q�&�z�<�<�V�<�<������~�.�.�.�.�.r)N)r�r�r�rCrGrNrSrUr`rjrlrnrpr�r�r.rrr�r{r�r)r'r8r8[sG������?�?�?�M�
*�
*�
*�G�G�G�0
E�
E�
E�
G�
G�
G�A�A�A�4F�F�F�&2�2�2�3�3�3�	3�	3�	3��[��� J� E�G�G�,�,�G�G�,� �[���X�
�	�S��	�|�$�	�)��	(���/�/���/�/�/r)r8c�2�eZdZd�Zd�Zd�Zd�Zd�Zd�ZdS)�TestFindPeaksCwtc���gd�}d}t||��\}}tjdt|����}t	||ddd���}tj�||d��dS)	zX
        Generate a series of gaussians and attempt to find the peak locations.
        �rsrrr�g4@r�gI@r�r�rrN)�
gap_thresh�min_snr�
min_lengthz4Found maximum locations did not equal those expected)r2rrr5rr�r)rSr �
num_pointsr�r�r�
found_locss       r'�test_find_peaks_exactz&TestFindPeaksCwt.test_find_peaks_exacts���4�3�3���
�1�&�*�E�E��	�8���3��F���,�,��#�I�v�!�Q�48�:�:�:�
�
�
�%�%�j�(�N�	P�	P�	P�	P�	Pr)c�b�gd�}d}t||��\}}tjdt|����}d}tj�d��|tj�|��dz
d|zzz
}t||dd	|d
z���}tj�	t|��t|��d��tj||z
��}tj|��d
z}	tj�
||	d
d|	zz��dS)zz
        Verify that peak locations are (approximately) found
        for a series of gaussians with added noise.
        rr�r�g�Q���?�orrrur+ri)r�r�r�z,Different numberof peaks found than expectedzMaximum location differedzby more than %sN)r2rrr5�random�seed�randrr�rr-r�rOr�)
rSr 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� � � ��b�i�n�n�Z�0�0�3�6��9��E�E�	�#�I�v�"�45�y�1�}�N�N�N�
�	�
����J����X���A?�	@�	@�	@���z�H�,�-�-���H�V�$�$�q�(�	�
�
�$�$�U�I�7R�%6�)�%D�8E�	F�	F�	F�	F�	Fr)c�F�d}d}tj�d��tj�|��dz
d|zz}tjdd��}t||dd	�
��}tj�t|��d��dS)
zQ
        Verify that no peak is found in
        data that's just noise.
        rqrWiW�
rrr[r\rir�)r��
noise_percrN)	rr�r�r�rrr�rr-)rSr�r�r�rr�s      r'�test_find_peaks_nopeakz'TestFindPeaksCwt.test_find_peaks_nopeak?s���
�	��
�
�	���y�!�!�!��Y�^�^�J�/�/�#�5��)��D�	���2�r�"�"��#�I�v�q�R�P�P�P�
�
�
����J����3�3�3�3�3r)c���tdd��}tjgd���}t||t���}tj�tjdg��|��dS)N��r)r+rr]ra)�waveletrW)rrrOrr�r)rSrTr�as    r'�)test_find_peaks_with_non_default_waveletsz:TestFindPeaksCwt.test_find_peaks_with_non_default_waveletsLs`���S�!������,�,�,�'�'���1�f�h�7�7�7��
�
�����#�����3�3�3�3�3r)c�:�ddg}d}t||��\}}tjdt|��d��}d}tj�d��|tj�|��dz
d|zzz
}|d	d
�xxdzcc<t||ddd
d
���}tj	t��5|j|jksJ�	d
d
d
��n#1swxYwYt||ddd
d���}|j|jksJ�d
S)zq
        Verify that window_size is passed correctly to private function and
        affects the result.
        r{r�r�g�������?皙�����?r�rr�i@r+r]N)r�r�r��window_sizerl)r2rrr5r�r�r�rr�r�AssertionErrorr�)rSr r�r�r�rr�r�s        r'�test_find_peaks_window_sizez,TestFindPeaksCwt.test_find_peaks_window_sizeSs���
�s����
�1�&�*�E�E��	�8���3��F���S�1�1���	�
�	���x� � � ��b�i�n�n�Z�0�0�3�6��9��E�E�	�	�#�c�'����a�����#�I�v�!�Q�/3��G�G�G�
�
�]�>�
*�
*�	4�	4��?�h�m�3�3�3�3�3�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4����	4�	4�	4�	4�$�I�v�!�Q�/3��E�E�E�
���(�-�/�/�/�/�/�/s�	C)�)C-�0C-c���tjdtjd��}tj|��}d}t	||��}tj�|d��dS)z]
        Verify that the `width` argument
        in `find_peaks_cwt` can be a float
        rr�r+� N)rr�pi�sinrr�r)rS�xsr�rr�s     r'�test_find_peaks_with_one_widthz/TestFindPeaksCwt.test_find_peaks_with_one_widthmsX��
�Y�q�"�%��
&�
&���F�2�J�J�	���#�I�v�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�0�4
0�
0�
0�
0�
0r)r})$r;�numpyr�
numpy.testingrrrrr�rr�scipy.signal._peak_findingr	r
rrr
rrr�scipy.signal.windowsr� scipy.signal._peak_finding_utilsrrr(r2rKrMr�r�r�r�r6r8r}r�r)r'�<module>r�s������������������������
�
�
� � � � � � � � �	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�*�)�)�)�)�)�R�R�R�R�R�R�R�R����!�!�!�($�($�($�V8#�8#�8#�8#�8#�8#�8#�8#�vYI�YI�YI�YI�YI�YI�YI�YI�xPN�PN�PN�PN�PN�PN�PN�PN�fr;�r;�r;�r;�r;�r;�r;�r;�jF6�F6�F6�F6�F6�F6�F6�F6�RH�H�H�8|/�|/�|/�|/�|/�|/�|/�|/�~]0�]0�]0�]0�]0�]0�]0�]0�]0�]0r)

Youez - 2016 - github.com/yon3zu
LinuXploit