
    Yh:                       d dl Z d dlZd dlmZmZmZmZmZm	Z	 d dl
Z
d dl
mZ d dlmZ d dlmZ d dlmZmZmZmZ d dl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$ d dl%m&Z' d dl%m(Z)  G d d          Z* G d d          Z+ G d d          Z, G d d          Z- G d d          Z. G d d          Z/ G d d          Z0 G d d          Z1dS )    N)assert_assert_allcloseassert_array_equalassert_equalassert_array_almost_equal_nulpsuppress_warnings)raises)signal)xp_assert_close)fftfreqrfftfreqfftirfft)	trapezoid)periodogramwelchlombscargle	coherencecsdspectrogram
check_COLA
check_NOLA)hann)_spectral_helper)stft_compare)istft_comparec                   >   e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zej                            ej        d
k    d          d             Zej                            ej        d
k    d          d             Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )TestPeriodogramc                     t          j        d          }d|d<   t          |          \  }}t          |t          j        ddd                     t          j        d          }d|d<   |dxx         dz  cc<   |dz  }t          ||           d S )	N      r         ?	          @   npzerosr   r   linspaceonesselfxfpqs        r/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/scipy/signal/tests/test_spectral.pytest_real_onesided_evenz'TestPeriodogram.test_real_onesided_even   s    HRLL!1~~12;q#q11222GAJJ!	"	Q1    c                    t          j        d          }d|d<   t          |          \  }}t          |t          j        d          dz             t          j        d          }d|d<   |dz  }t          ||d	           d S )
N   r!   r          @      .@r&   ?V瞯<atol)r(   r)   r   r   aranger+   r,   s        r2   test_real_onesided_oddz&TestPeriodogram.test_real_onesided_odd$   s~    HRLL!1~~129S>>$.///GAJJ!	X15))))))r4   c                     t          j        d          }d|d<   t          |d          \  }}t          |t	          dd                     t          j        dd          }d|d<   t          ||           d S )Nr    r!   r   Freturn_onesided      ?      ?)r(   r)   r   r   r   fullr,   s        r2   test_real_twosidedz"TestPeriodogram.test_real_twosided.   sx    HRLL!1e444172s++,,,GB!1r4   c                     t          j        d          }d|d<   t          |d          \  }}t          |d          \  }}t          |t          j        ddd                     t          ||d	z             d S )
Nr    r!   r   spectrumscalingdensityr"   r#   g      0@)r(   r)   r   r   r*   )r-   r.   r/   r0   gr1   s         r2   test_real_spectrumz"TestPeriodogram.test_real_spectrum7   s|    HRLL!1j11111i00012;q#q112221T6"""""r4   c                 .   t          j        dt                    }d|d<   t          |          \  }}t	          |t          j        ddd                     t          j        d          }d|d<   |dxx         dz  cc<   |d	z  }t	          ||           d S )
Nr    dtyper!   r   r"   r#   r$   r%   r&   )r(   r)   intr   r   r*   r+   r,   s        r2   test_integer_evenz!TestPeriodogram.test_integer_even?   s    HRs###!1~~12;q#q11222GAJJ!	"	Q1r4   c                    t          j        dt                    }d|d<   t          |          \  }}t	          |t          j        d          dz             t          j        d          }d|d<   |dz  }t	          ||d	
           d S )Nr6   rN   r!   r   r7   r8   r&   r9   r:   r;   )r(   r)   rP   r   r   r=   r+   r,   s        r2   test_integer_oddz TestPeriodogram.test_integer_oddJ   s    HRs###!1~~129S>>$.///GAJJ!	X15))))))r4   c                     t          j        dt                    }d|d<   t          |d          \  }}t	          |t          dd                     t          j        dd          }d|d<   t	          ||           d S )	Nr    rN   r!   r   Fr@   rB   rC   )r(   r)   rP   r   r   r   rD   r,   s        r2   test_integer_twosidedz%TestPeriodogram.test_integer_twosidedT   s    HRs###!1e444172s++,,,GB!1r4   c                    t          j        dt           j                  }d|d<   t          |d          \  }}t	          |t          dd                     t          j        dd          }d|d<   t	          ||           d S )Nr          ?       @r   Fr@   rB         ?)r(   r)   
complex128r   r   r   rD   r,   s        r2   test_complexzTestPeriodogram.test_complex]   s~    HR''!1e444172s++,,,GB!!!1r4   c                 z    t          t          t          t          j        dt          j                  d           d S )N   foorH   )assert_raises
ValueErrorr   r(   r)   rY   r-   s    r2   test_unk_scalingz TestPeriodogram.test_unk_scalingf   s:    j+rx2=/I/I	 	 	 	 	 	r4   l        zOn some 32-bit tolerance issue)reasonc                    t          j        dt           j                  }|                    d          }d|d d d d df<   t	          |          \  }}t          |j        d           t          |ddd d f         |ddd d f         d           t	          |ddd d f                   \  }}t          |t           j        d d f         |dd d f         d           d S )	N   rN      r!   
   rB   r   rf   r!      r!   <   )	r(   r)   float64reshaper   r   shaper   newaxisr-   r.   r/   r0   f0p0s         r2   test_nd_axis_m1zTestPeriodogram.test_nd_axis_m1j   s    
 HRrz***IIh!!!AAAa%1~~117I...&q1QQQx1Qqqq52>>>Qq111uX&&B&r"*QQQ,'71QQQ3DDDDDr4   c                    t          j        dt           j                  }|                    d          }d|dd d d d f<   t	          |d          \  }}t          |j        d           t          |d d ddf         |d d ddf         d	           t	          |d d ddf                   \  }}t          ||d d ddf                    d S )
Nrd   rN   rg   rf   r!   rB   r   axisri   rf   r!   r!   rj   )r(   r)   rk   rl   r   r   rm   r   ro   s         r2   test_nd_axis_0zTestPeriodogram.test_nd_axis_0x   s    
 HRrz***IIh!AAAaaa%11%%%117G,,,&q1Qx111Qq52>>>Qqqq1uX&&B&r1QQQqU844444r4   c                 V   t          j        d          }d|d<   t          |dd          \  }}t          j        dd          }t          |d|          \  }}t          ||           t          ||           t          j        dd          }t          t          t          |d|           d S )Nr    r!   r   rg   r       )r(   r)   r   r
   
get_windowr   r^   r_   r-   r.   r/   r0   winfepewin_errs           r2   test_window_externalz$TestPeriodogram.test_window_external   s    HRLL!1b&))1++QC((B&q"---&q"---#FB//j+q'	# 	# 	# 	# 	#r4   c                    t          j        d          }d|d<   t          |          \  }}t          |d          \  }}t          ||d d d                    t          ||d d d                    t	          |j        d           d S )Nr    r!   r   rz   nfftrf   )   )r(   r)   r   r   r   rm   )r-   r.   r/   r0   fppps         r2   test_padded_fftzTestPeriodogram.test_padded_fft   s    HRLL!1~~1QR(((B2ccc7###2ccc7###28U+++++r4   c                 $   t          g           \  }}t          |j        d           t          |j        d           dD ]P}t          t          j        |                    \  }}t          |j        |           t          |j        |           Qd S Nr   r      r   r      rf   )r   r   rm   r(   emptyr-   r/   r0   rm   s       r2   test_empty_inputz TestPeriodogram.test_empty_input   s    2117D)))17D)))+ 	/ 	/Erx//DAqqw...qw....	/ 	/r4   c                     dD ]R}t          t          j        |          d          \  }}t          |j        |           t          |j        |           Sd S Nr   r   r!   ru   )r   r(   r   r   rm   r-   rm   r/   r0   s       r2   test_empty_input_other_axisz+TestPeriodogram.test_empty_input_other_axis   s`    % 	/ 	/ErxQ777DAqqw...qw....	/ 	/r4   c                 $   t          j        d          }d|d<   t          |d          \  }}t          |t          j        ddd                     t          j        d          }d|d<   |dxx         d	z  cc<   |d
z  }t          ||           d S )N   r!   r   r    r   r"   r#   r$   r%   r&   r'   r,   s        r2   test_short_nfftzTestPeriodogram.test_short_nfft       HRLL!12&&&12;q#q11222GAJJ!	"	Q1r4   c                 $   t          j        d          }d|d<   t          |d          \  }}t          |t          j        ddd                     t          j        d          }d|d<   |dxx         dz  cc<   |d	z  }t          ||           d S )
Nr    r!   r   r   r"   r#   r$   r%   r&   r'   r,   s        r2   test_nfft_is_xshapez#TestPeriodogram.test_nfft_is_xshape   r   r4   c                 ^   t          j        dd          }d|d<   t          |          \  }}t          |t          j        ddd                     t          j        dd          }d|d<   |dxx         dz  cc<   |d	z  }t          ||           t          |j        |j        k               d S )
Nr    r/   r!   r   r"   r#   r$   r%   r&   )r(   r)   r   r   r*   r+   r   rO   r,   s        r2   test_real_onesided_even_32z*TestPeriodogram.test_real_onesided_even_32   s    HR!1~~12;q#q11222GAsOO!	"	Q117"#####r4   c                 D   t          j        dd          }d|d<   t          |          \  }}t          |t          j        d          dz             t          j        dd          }d|d<   |dz  }t          ||d	
           t          |j        |j        k               d S )Nr6   r/   r!   r   r7   r8   r&   r9   Hz>r;   )r(   r)   r   r   r=   r+   r   rO   r,   s        r2   test_real_onesided_odd_32z)TestPeriodogram.test_real_onesided_odd_32   s    HR!1~~129S>>$.///GAsOO!	X14((((17"#####r4   c                 .   t          j        dd          }d|d<   t          |d          \  }}t          |t	          dd                     t          j        ddd          }d|d<   t          ||           t          |j        |j        k               d S )	Nr    r/   r!   r   Fr@   rB   rC   r(   r)   r   r   r   rD   r   rO   r,   s        r2   test_real_twosided_32z%TestPeriodogram.test_real_twosided_32   s    HR!1e444172s++,,,GB$$!117"#####r4   c                 .   t          j        dd          }d|d<   t          |d          \  }}t          |t	          dd                     t          j        ddd	          }d|d<   t          ||           t          |j        |j        k               d S )
Nr    FrW   r   Fr@   rB   rX   r/   r   r,   s        r2   test_complex_32zTestPeriodogram.test_complex_32   s    HR!1e444172s++,,,GB#&&!117"#####r4   c                     t          j        d          }d|d<   t          j        dd          }d}t	          t
          |          5  t          ||           d d d            d S # 1 swxY w Y   d S )	Nr    r!   r   r   rg   zOthe size of the window must be the same size of the input on the specified axismatchwindow)r(   r)   r
   r{   r^   r_   r   )r-   r.   r}   expected_msgs       r2   test_shorter_window_errorz)TestPeriodogram.test_shorter_window_error   s    HRLL!++=:\::: 	' 	'#&&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   A&&A*-A*N)__name__
__module____qualname__r3   r>   rE   rL   rQ   rS   rU   rZ   ra   pytestmarkskipifsysmaxsizerr   rx   r   r   r   r   r   r   r   r   r   r   r    r4   r2   r   r      s       	 	 	* * *  # # #	 	 	* * *       [u/   E E	 E [u/   5 5	 5
# 
# 
#, , ,/ / // / /	 	 		 	 	
$ 
$ 
$	$ 	$ 	$$ $ $$ $ $' ' ' ' 'r4   r   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d"S )#	TestWelchc                    t          j        d          }d|d<   d|d<   t          |d          \  }}t          |t          j        ddd                     t          j        g d          }t          ||d	d	
           d S Nr    r!   r   r&   npersegr"   r   iKGUU?gS8?#q?r   #q?r   r<   rtolr(   r)   r   r   r*   arrayr,   s        r2   r3   z!TestWelch.test_real_onesided_even   s    HRLL!!Q"""12;q#q11222H " " " # #14d333333r4   c                    t          j        d          }d|d<   d|d<   t          |d          \  }}t          |t          j        d          dz             t          j        g d	          }t          ||d
d
           d S Nr    r!   r   r&   r#   r         @      "@g9?g?p0?r   r   r   r   )r(   r)   r   r   r=   r   r,   s        r2   r>   z TestWelch.test_real_onesided_odd   s    HRLL!!Q"""129S>>#-...H " " " # #14d333333r4   c                     t          j        d          }d|d<   d|d<   t          |dd          \  }}t          |t	          dd                     t          j        g d          }t          ||d	d	
           d S Nr    r!   r   r&   Fr   rA   rB   r   S8?r   r   r   r   r   r   r   r   )r(   r)   r   r   r   r   r,   s        r2   rE   zTestWelch.test_real_twosided
  s    HRLL!!Q5999171c??+++H F F F G G14d333333r4   c                    t          j        d          }d|d<   d|d<   t          |dd          \  }}t          |t          j        ddd                     t          j        g d	          }t          ||d
d
           d S Nr    r!   r   r&   rG   )r   rI   r"   r   )g      ?g-UU?.iqUU?r   g-UU?r   r   r   r,   s        r2   rL   zTestWelch.test_real_spectrum  s    HRLL!!Q:66612;q#q11222H " " " # #14d333333r4   c                    t          j        dt                    }d|d<   d|d<   t          |d          \  }}t	          |t          j        ddd                     t          j        g d	          }t	          ||d
d
           d S Nr    rN   r!   r   r&   r   r"   r   r   r   r   )r(   r)   rP   r   r   r*   r   r,   s        r2   test_integer_onesided_evenz$TestWelch.test_integer_onesided_even  s    HRs###!!Q"""12;q#q11222H " " " # #14d333333r4   c                    t          j        dt                    }d|d<   d|d<   t          |d          \  }}t	          |t          j        d          d	z             t          j        g d
          }t	          ||dd           d S Nr    rN   r!   r   r&   r#   r   r   r   r   r   r   )r(   r)   rP   r   r   r=   r   r,   s        r2   test_integer_onesided_oddz#TestWelch.test_integer_onesided_odd(  s    HRs###!!Q"""129S>>#-...H " " " # #14d333333r4   c                    t          j        dt                    }d|d<   d|d<   t          |dd          \  }}t	          |t          dd                     t          j        g d	          }t	          ||d
d
           d S Nr    rN   r!   r   r&   Fr   rB   r   r   r   )r(   r)   rP   r   r   r   r   r,   s        r2   rU   zTestWelch.test_integer_twosided2  s    HRs###!!Q5999171c??+++H F F F G G14d333333r4   c                    t          j        dt           j                  }d|d<   d|d<   t          |dd          \  }}t	          |t          dd                     t          j        g d          }t	          ||d	d	
           d S Nr    rW   r   r&   Fr   rB   )g&>?#q?n)t?r   r   r   r   r   r   r   )r(   r)   rY   r   r   r   r   r,   s        r2   rZ   zTestWelch.test_complex<  s    HR''!!Q5999171c??+++H F F F G G14d333333r4   c                 |    t          t          t          t          j        dt          j                  dd           d S Nr\   r]   )rI   r   )r^   r_   r   r(   r)   rY   r`   s    r2   ra   zTestWelch.test_unk_scalingF  s<    j%!R])C)C#Q	0 	0 	0 	0 	0 	0r4   c                     t          j        dt           j                  dz   }t          |dd          \  }}t	          |t          j        |          d           d S Nrg   rN   {Gz?linearr   detrendr:   r;   r(   r=   rk   r   r   
zeros_liker-   r.   r/   r0   s       r2   test_detrend_linearzTestWelch.test_detrend_linearJ  sZ    Ib
+++d2QH55512=++%888888r4   c                     t          j        dt           j                  dz   }t          |dd          \  }}t          |dd           \  }}t	          ||d           t	          ||d           d S )	Nrg   rN   r   Fr   c                     | S Nr   r.   s    r2   <lambda>z.TestWelch.test_no_detrending.<locals>.<lambda>R  s     r4   r:   r;   )r(   r=   rk   r   r   r-   r.   f1p1f2p2s         r2   test_no_detrendingzTestWelch.test_no_detrendingO  s    Ib
+++d2q"e444Bq"kk:::BBU++++BU++++++r4   c                     t          j        dt           j                  dz   }t          |dd           \  }}t	          |t          j        |          d           d S )Nrg   rN   r   c                 .    t          j        | d          S Nl)typer
   r   segs    r2   r   z1TestWelch.test_detrend_external.<locals>.<lambda>Y      #)F)F)F r4   r   r:   r;   r   r   s       r2   test_detrend_externalzTestWelch.test_detrend_externalV  sg    Ib
+++d2QFFH H H12=++%888888r4   c                     t          j        dt           j                  dz   }|                    d          }t	          |dd           \  }}t          |t          j        |          d	           d S )
N(   rN   r   rf   rf   rg   rg   c                 .    t          j        | d          S r   r   r   s    r2   r   z7TestWelch.test_detrend_external_nd_m1.<locals>.<lambda>`  r  r4   r   r:   r;   )r(   r=   rk   rl   r   r   r   r   s       r2   test_detrend_external_nd_m1z%TestWelch.test_detrend_external_nd_m1\  sx    Ib
+++d2IIhQFFH H H12=++%888888r4   c                    t          j        dt           j                  dz   }|                    d          }t          j        |dd          }t          |ddd 	          \  }}t          |t          j        |          d
           d S )Nrd   rN   r   re   rf   r   rg   c                 0    t          j        | dd          S Nr   r   )rv   r   r   r   s    r2   r   z6TestWelch.test_detrend_external_nd_0.<locals>.<lambda>h  s    !#)N)N)N r4   r   rv   r   r:   r;   )r(   r=   rk   rl   moveaxisr   r   r   r   s       r2   test_detrend_external_nd_0z$TestWelch.test_detrend_external_nd_0c  s    Ib
+++d2IIhK1a  QNNP P P12=++%888888r4   c                    t          j        dt           j                  dz   }|                    d          }t	          |d          \  }}t          |j        d           t          |ddd d f         |d	dd d f         d
d
           t	          |ddd d f         d          \  }}t          |t           j        d d f         |d	d d f         d
d
           d S Nrd   rN   r   re   rg   r   rh   r   r!   vIh%<=r   )	r(   r=   rk   rl   r   r   rm   r   rn   ro   s         r2   rr   zTestWelch.test_nd_axis_m1k  s    Ib
+++d2IIhQ###117I...!Aaaa%!AaE(UCCCCq1QQQx,,,B2:aaa<(!AaaaC&u5IIIIIIr4   c                    t          j        dt           j                  dz   }|                    d          }t	          |dd          \  }}t          |j        d           t          |d d ddf         |d d d	df         d
d
           t	          |d d ddf         d          \  }}t          ||d d d	df         d
d
           d S Nrd   rN   r   rt   rg   r   )r   rv   rw   r!   r  r   r   )r(   r=   rk   rl   r   r   rm   r   ro   s         r2   rx   zTestWelch.test_nd_axis_0t  s    Ib
+++d2IIhQ+++117G,,,!!!Aa%!AAAaE(UCCCCq1Qx,,,BAaaa!eH5u======r4   c                    t          j        d          }d|d<   d|d<   t          |ddd          \  }}t          j        dd          }t          |d|d           \  }}t          ||           t          ||           t          |j        d           t          |j        d           t          t          t          |d|d	           t          j        dd
          }t          t          t          |d|d            d S )Nr    r!   r   r&   rg   r   r   r   r\   rz   )
r(   r)   r   r
   r{   r   r   rm   r^   r_   r|   s           r2   r   zTestWelch.test_window_external}  s   HRLL!!QFA...1**q"c4000B&q"---&q"---28T***28T***j%#q	* 	* 	* 	*#FB//j%'4	1 	1 	1 	1 	1 	1r4   c                 $   t          g           \  }}t          |j        d           t          |j        d           dD ]P}t          t          j        |                    \  }}t          |j        |           t          |j        |           Qd S r   )r   r   rm   r(   r   r   s       r2   r   zTestWelch.test_empty_input  s    Ryy117D)))17D)))+ 	/ 	/E%))DAqqw...qw....	/ 	/r4   c                     dD ]R}t          t          j        |          d          \  }}t          |j        |           t          |j        |           Sd S r   )r   r(   r   r   rm   r   s       r2   r   z%TestWelch.test_empty_input_other_axis  s`    % 	/ 	/E%q111DAqqw...qw....	/ 	/r4   c                    t          j        d          }d|d<   t                      5 }|                    t          d           t          |d          \  }}t          |dd          \  }}d d d            n# 1 swxY w Y   t          |d	          \  }}t          ||           t          ||           t          ||           t          ||           d S )
Nr&   r!   r   z$nperseg=256 is greater than signal.*r   r      r   r   r   )r(   r)   r   filterUserWarningr   r   	r-   r.   supr/   r0   r   r   r   r   s	            r2   test_short_datazTestWelch.test_short_data  s   HQKK!    	9CJJ{$JKKK&)))DAq1FC888FB	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 q!$$$B22BBs   AA99A= A=c           
      4   t          t          t          t          j        d          dt          j        g d                     t          t          t          t          j        d          dt          j        d                              d                     d S Nr\   r!   )r!   r!   r!   r!   r!   ri   )rf   r   )r^   r_   r   r(   r)   r   r=   rl   r`   s    r2   test_window_long_or_ndz TestWelch.test_window_long_or_nd  ss    j%!a+++9N9NOOOj%!aill**511	3 	3 	3 	3 	3r4   c                     t          j        d          }d|d d d<   t          |dd          \  }}t          j        g d          }t	          ||d	           d S 
N@   r!   r&   r    r\   r   noverlap)	r   gUUUUUU?UUUUUU?皙?r'  r(  r'  r(  gUUUUUU?g-q=r;   )r(   r)   r   r   r   r,   s        r2   test_nondefault_noverlapz"TestWelch.test_nondefault_noverlap  sq    HRLL##A#QQ///1H     15))))))r4   c           	      h    t          t          t          t          j        d          dddd           d S Nr\   r!   r   rf      )r^   r_   r   r(   r)   r`   s    r2   test_bad_noverlapzTestWelch.test_bad_noverlap  s*    j%!aAFFFFFr4   c                 f    t          t          t          t          j        d          dd           d S N   r   r\   )r   r   )r^   r_   r   r(   r+   r`   s    r2   test_nfft_too_shortzTestWelch.test_nfft_too_short  s)    j%1aHHHHHHr4   c                 B   t          j        dd          }d|d<   d|d<   t          |d          \  }}t          |t          j        ddd                     t          j        g d	d          }t          ||d
d
           t          |j        |j        k               d S Nr    r/   r!   r   r&   r   r"   r   r   r   r   )r(   r)   r   r   r*   r   r   rO   r,   s        r2   r   z$TestWelch.test_real_onesided_even_32  s    HR!!Q"""12;q#q11222H " " "#&( (14d333317"#####r4   c                 D   t          j        dd          }d|d<   d|d<   t          |d          \  }}t          |t          j        d          d	z             t          j        g d
d          }t          ||dd           t          |j        |j        k               d S Nr    r/   r!   r   r&   r#   r   r   r   )gx:?gyѲI?r   gw0?r   r   r   )r(   r)   r   r   r=   r   r   rO   r,   s        r2   r   z#TestWelch.test_real_onesided_odd_32  s    HR!!Q"""129S>>#-...H " " "#&( (14d333317"#####r4   c                 8   t          j        dd          }d|d<   d|d<   t          |dd          \  }}t          |t	          dd                     t          j        g d	d          }t          ||d
d
           t          |j        |j        k               d S Nr    r/   r!   r   r&   Fr   rB   r   r   r   r(   r)   r   r   r   r   r   rO   r,   s        r2   r   zTestWelch.test_real_twosided_32  s    HR!!Q5999171c??+++H " " "#&( ( 	14d333317"#####r4   c                 Z   t          j        dd          }d|d<   d|d<   t          |dd          \  }}t          |t	          dd                     t          j        g d	d
          }t          ||dd           t          |j        |j        k    d|j         d|j                    d S Nr    r   rW   r   r&   Fr   rB   )g%?A2q?d^?r<  g~?r<  r<  r;  r/   r   r   zdtype mismatch, , r8  r,   s        r2   r   zTestWelch.test_complex_32  s    HR!!Q5999171c??+++H F F FGJL L14d333317"71777ag77	9 	9 	9 	9 	9r4   c                    t          j        d          }d}t          |d          d |dz  dz            }|dxx         dz  cc<   t          |d|          \  }}t          |d	|          \  }}t	          ||           t	          ||           d
}t          |d          d |dz   dz           }t          |d|          \  }}t          |d	|          \  }}t	          ||           t	          ||           d S Nr0     rB   rf   r!   r$   r   r   r   ri      )r(   r)   r   r   r   )r-   r.   r   r/   fodd_fevens          r2   test_padded_freqszTestWelch.test_padded_freqs  s   HRLLD#za	z*	"14000aAD111q4   5!!!D#~A~.14000aAD111q4   5!!!!!r4   c           	         d}d}t          |dz            }d}t          ||z  |z            }t          j        |          |z  }|t          j        dt          j        z  |z  |z            z  }dD ]}t          ||||d          \  }	}
t          ||||d	          \  }}t          |
|         |dz  d
z             t          t          j        t          ||                    |t          j        d          z  dz  d           d S )Nrd   g     @rg   ,  rf   )r   bartlett)tukey皙?flattoprG   )fsr   r   rI   rJ   r%   gMbP?r   )	rP   r(   r=   sinpir   r   sqrtr   )r-   ArM  r   fsigiittr.   r   rD  p_specfreqp_denss                r2   test_window_correctionz TestWelch.test_window_correction  s.   b"f++gr!""Yr]]2bfQruWT\"_%%%E 
	' 
	'FaB&02 2 2IAv r76)24 4 4LD& F2J1S111BGIfd$;$;<<a

l1n!%' ' ' ' '
	' 
	'r4   c                 
   t           j                            d           t           j                            d          }t	          |          \  }}t          d          D ]}dgdz  }d||<   |                    |          }t	          ||          \  }}t	          |||j        z
            \  }}t          ||	                                |           t          ||	                                ||j        z
             d S )N     r   r!   r$   ru   err_msg)
r(   randomseedrandnr   rangerl   ndimr   squeeze)	r-   x_flatrD  p_flatanewshaper.   p_plusp_minuss	            r2   test_axis_rollingzTestWelch.test_axis_rolling  s    
	t&&&MM	6q 		F 		FAtAvHHQKx((Aaa(((IAvqqx000JAw!1!11====!2!2AafHEEEEE		F 		Fr4   c                 B   t          j        d          }d|d<   d|d<   t          |dd          \  }}t          |t          j        ddd                     t          j        g d	          }t          ||d
d
           t          t          t          |dd           d S )Nr    r!   r   r&   median)r   averager"   r   )rK  皙?        g&E    9rp  r   r   zunrecognised-average)r(   r)   r   r   r*   r   r^   r_   r,   s        r2   test_averagezTestWelch.test_average&  s    HRLL!!Q844412;q#q11222H6667714d3333j%A4	6 	6 	6 	6 	6 	6r4   c                 h   t          j        g d          t          j        d          d}}}t          ||dd          }t	          |fddi|d	         }t	          |fdd
i|d	         }t          |dz            |z  t          t          |                    dz  z  }t          ||z  |           dS )zvVerify the factor of ``sum(abs(window)**2)*fs / abs(sum(window))**2``
        used in the `welch`  and `csd` docstrs. )rB   r   r   r   r\   r0  FN)rM  r   rA   r   rI   rJ   r!   rG   rf   )r(   r   r+   dictr   sumabsr   )r-   r.   r}   rM  paramsrX  rV  p_facs           r2   test_ratio_scale_tozTestWelch.test_ratio_scale_to2  s     Xmmm,,bgajj"3CMMMq66)6v66q9q77*777:CFBSXX!11/////r4   N)$r   r   r   r3   r>   rE   rL   r   r   rU   rZ   ra   r   r   r  r  r  rr   rx   r   r   r   r  r!  r)  r-  r1  r   r   r   r   rF  rY  rk  rq  rx  r   r4   r2   r   r      s       4 4 44 4 44 4 44 4 44 4 44 4 44 4 44 4 40 0 09 9 9
, , ,9 9 99 9 99 9 9J J J> > >1 1 1"/ / // / /     3 3 3
* * *G G GI I I	$ 	$ 	$	$ 	$ 	$
$ 
$ 
$
9 
9 
9" " "$' ' ',F F F"
6 
6 
60 0 0 0 0r4   r   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$S )%TestCSDc                 ,   t          j        d          }t          j        d          }t          j        ddd          }t          j        dt           j                  }t	          ||d          \  }}t          ||           t          ||           d S )Nr&   r0  r   r"   r,  rN   r   r(   r)   r*   rY   r   r   r-   r.   yr/   cr   c1s          r2   test_pad_shorter_xzTestCSD.test_pad_shorter_x=  s    HQKKHRLLK3""HQR]+++Q2&&&B22r4   c                 ,   t          j        d          }t          j        d          }t          j        ddd          }t          j        dt           j                  }t	          ||d          \  }}t          ||           t          ||           d S )Nr0  r&   r   r"   r,  rN   r   r|  r}  s          r2   test_pad_shorter_yzTestCSD.test_pad_shorter_yH  s    HRLLHQKKK3""HQR]+++Q2&&&B22r4   c                    t          j        g dd          }t          t          |          dd          }t	          j        |t          j        |          fi |d         }t	          j        ||dd         fi |d         }t	          j        |dd         |fi |d         }t          ||dz             t          ||dz             dS )	zTest zero-padding for input `x.shape[axis] != y.shape[axis]` for 1d arrays.

        This test ensures that issue 23036 is fixed.
        )r\   r   r   r\   boxcar)rM  r   r   r!   Nr&   rf   )r(   tilers  lenr
   r   copyr   )r-   r.   kwX0X1X2s         r2   test_unequal_length_input_1Dz$TestCSD.test_unequal_length_input_1DS  s    
 GMMM1%%SVVHa888Z271::,,,,Q/Z1RaR5''B''*Z"1"q''B''*BF###BF#####r4   c                    d}t          j        d|z                                d|d          }||dddddf<   t          |d|dd	          }t	          j        ||                                fi |d         }t	          j        ||ddddddf         fi |d         }t	          j        |ddddddf         |fi |d         }t          ||           t          ||           dS )
zTest zero-padding for input `x.shape[axis] != y.shape[axis]` for 3d arrays.

        This test ensures that issue 23036 is fixed.
        r&   ri   rf   r   Nr   r  r!   )rM  r   r   r   rv   )r(   r)   rl   rs  r
   r   r  r   )r-   nr.   r  r  r  r  s          r2   test_unequal_length_input_3Dz$TestCSD.test_unequal_length_input_3Da  s   
 HUQY''1a00!!!Q'
QxDqIIIZ16688**r**1-Z1QQQAAAX;--"--a0Z!!!RaR(Q--"--a0BBr4   c                    t          j        d          }d|d<   d|d<   t          ||d          \  }}t          |t          j        ddd                     t          j        g d          }t          ||d	d	
           d S r   r(   r)   r   r   r*   r   r,   s        r2   r3   zTestCSD.test_real_onesided_evenq  s    HRLL!!1a###12;q#q11222H " " " # #14d333333r4   c                    t          j        d          }d|d<   d|d<   t          ||d          \  }}t          |t          j        d          dz             t          j        g d	          }t          ||d
d
           d S r   )r(   r)   r   r   r=   r   r,   s        r2   r>   zTestCSD.test_real_onesided_odd{  s    HRLL!!1a###129S>>#-...H " " " # #14d333333r4   c                     t          j        d          }d|d<   d|d<   t          ||dd          \  }}t          |t	          dd                     t          j        g d          }t          ||d	d	
           d S r   )r(   r)   r   r   r   r   r,   s        r2   rE   zTestCSD.test_real_twosided  s    HRLL!!1aE:::171c??+++H F F F G G14d333333r4   c                    t          j        d          }d|d<   d|d<   t          ||dd          \  }}t          |t          j        ddd                     t          j        g d	          }t          ||d
d
           d S r   r  r,   s        r2   rL   zTestCSD.test_real_spectrum  s    HRLL!!1aJ77712;q#q11222H " " " # #14d333333r4   c                    t          j        dt                    }d|d<   d|d<   t          ||d          \  }}t	          |t          j        ddd                     t          j        g d	          }t	          ||d
d
           d S r   )r(   r)   rP   r   r   r*   r   r,   s        r2   r   z"TestCSD.test_integer_onesided_even  s    HRs###!!1a###12;q#q11222H " " " # #14d333333r4   c                    t          j        dt                    }d|d<   d|d<   t          ||d          \  }}t	          |t          j        d          d	z             t          j        g d
          }t	          ||dd           d S r   )r(   r)   rP   r   r   r=   r   r,   s        r2   r   z!TestCSD.test_integer_onesided_odd  s    HRs###!!1a###129S>>#-...H " " " # #14d333333r4   c                 
   t          j        dt                    }d|d<   d|d<   t          ||dd          \  }}t	          |t          dd                     t          j        g d	          }t	          ||d
d
           d S r   )r(   r)   rP   r   r   r   r   r,   s        r2   rU   zTestCSD.test_integer_twosided  s    HRs###!!1aE:::171c??+++H F F F G G14d333333r4   c                    t          j        dt           j                  }d|d<   d|d<   t          ||dd          \  }}t	          |t          dd                     t          j        g d          }t	          ||d	d	
           d S r   )r(   r)   rY   r   r   r   r   r,   s        r2   rZ   zTestCSD.test_complex  s    HR''!!1aE:::171c??+++H F F F G G14d333333r4   c           	          t          t          t          t          j        dt          j                  t          j        dt          j                  dd           d S r   )r^   r_   r   r(   r)   rY   r+   r`   s    r2   ra   zTestCSD.test_unk_scaling  sR    j#rx2='A'Aga//	K 	K 	K 	K 	K 	Kr4   c                     t          j        dt           j                  dz   }t          ||dd          \  }}t	          |t          j        |          d           d S r   r(   r=   rk   r   r   r   r   s       r2   r   zTestCSD.test_detrend_linear  s\    Ib
+++d21aX66612=++%888888r4   c                     t          j        dt           j                  dz   }t          ||dd          \  }}t          ||dd           \  }}t	          ||d           t	          ||d           d S )	Nrg   rN   r   Fr   c                     | S r   r   r   s    r2   r   z,TestCSD.test_no_detrending.<locals>.<lambda>  s     r4   r:   r;   )r(   r=   rk   r   r   r   s         r2   r   zTestCSD.test_no_detrending  s    Ib
+++d2Q2u555BQ2{{;;;BBU++++BU++++++r4   c                     t          j        dt           j                  dz   }t          ||dd           \  }}t	          |t          j        |          d           d S )Nrg   rN   r   c                 .    t          j        | d          S r   r   r   s    r2   r   z/TestCSD.test_detrend_external.<locals>.<lambda>      v~c'D'D'D r4   r   r:   r;   r  r   s       r2   r  zTestCSD.test_detrend_external  si    Ib
+++d21aDDF F F12=++%888888r4   c                     t          j        dt           j                  dz   }|                    d          }t	          ||dd           \  }}t          |t          j        |          d	           d S )
Nr  rN   r   r  rg   c                 .    t          j        | d          S r   r   r   s    r2   r   z5TestCSD.test_detrend_external_nd_m1.<locals>.<lambda>  r  r4   r   r:   r;   )r(   r=   rk   rl   r   r   r   r   s       r2   r  z#TestCSD.test_detrend_external_nd_m1  sz    Ib
+++d2IIh1aDDF F F12=++%888888r4   c                    t          j        dt           j                  dz   }|                    d          }t          j        |dd          }t          ||ddd 	          \  }}t          |t          j        |          d
           d S )Nrd   rN   r   re   rf   r   rg   c                 0    t          j        | dd          S r
  r   r   s    r2   r   z4TestCSD.test_detrend_external_nd_0.<locals>.<lambda>  s    v~c'L'L'L r4   r  r:   r;   )r(   r=   rk   rl   r  r   r   r   r   s       r2   r  z"TestCSD.test_detrend_external_nd_0  s    Ib
+++d2IIhK1a  1a!LLN N N12=++%888888r4   c                    t          j        dt           j                  dz   }|                    d          }t	          ||d          \  }}t          |j        d           t          |ddd d f         |d	dd d f         d
d
           t	          |ddd d f         |ddd d f         d          \  }}t          |t           j        d d f         |d	d d f         d
d
           d S r  )	r(   r=   rk   rl   r   r   rm   r   rn   ro   s         r2   rr   zTestCSD.test_nd_axis_m1  s    Ib
+++d2IIh1a$$$117I...!Aaaa%!AaE(UCCCCQq111uXq1QQQx444B2:aaa<(!AaaaC&u5IIIIIIr4   c                    t          j        dt           j                  dz   }|                    d          }t	          ||dd          \  }}t          |j        d           t          |d d ddf         |d d d	df         d
d
           t	          |d d ddf         |d d ddf         d          \  }}t          ||d d d	df         d
d
           d S r  )r(   r=   rk   rl   r   r   rm   r   ro   s         r2   rx   zTestCSD.test_nd_axis_0  s    Ib
+++d2IIh1a!,,,117G,,,!!!Aa%!AAAaE(UCCCCQqqq1uXq1Qx444BAaaa!eH5u======r4   c           	         t          j        d          }d|d<   d|d<   t          ||ddd          \  }}t          j        dd          }t          ||d|d           \  }}t          ||           t          ||           t          |j        d           t          |j        d           t          t          t          ||d|d	           t          j        dd
          }t          t          t          ||d|d            t          j        t          d          5  t          ||dd           d d d            d S # 1 swxY w Y   d S )Nr    r!   r   r&   rg   r   r   r  r  rz   zParameter nperseg=0.*r   )r(   r)   r   r
   r{   r   r   rm   r^   r_   r   r	   r|   s           r2   r   zTestCSD.test_window_external  s   HRLL!!1aVQ''1**Q2sD111B&q"---&q"---28T***28T***j#q!#s	, 	, 	, 	,#FB//j#q!'4	) 	) 	) 	)]:-DEEE 	$ 	$1a####	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   D<<E E c                    t          g t          j        d                    \  }}t          |j        d           t          |j        d           t          t          j        d          g           \  }}t          |j        d           t          |j        d           dD ]c}t          t          j        |          t          j        |                    \  }}t          |j        |           t          |j        |           dt          t          j        d          t          j        d                    \  }}t          |j        d           t          |j        d           t          t          j        d          t          j        d                    \  }}t          |j        d           t          |j        d           d S )Nrg   r   r   )r   r   )r   r(   r)   r   rm   r   r+   r   s       r2   r   zTestCSD.test_empty_input  sm   2bhrll##117D)))17D)))28B<<##117D)))17D)))+ 	/ 	/Erx88DAqqw...qw....272;;00117E***17E***28E??BGBKK00117E***17E*****r4   c                 b   dD ]e}t          t          j        |          t          j        |          d          \  }}t          |j        |           t          |j        |           ft          t          j        d          t          j        d          d          \  }}t          |j        d           t          |j        d           t          t          j        d          t          j        d          d          \  }}t          |j        d           t          |j        d           d S )Nr   r!   ru   )rg   rg   r   )rg   r   r!   )rg   r   r   )r   r(   r   r   rm   r)   r   s       r2   r   z#TestCSD.test_empty_input_other_axis!  s   % 	/ 	/Erxa@@@DAqqw...qw....28I&&(:(:CCC117H---17H---28H%%rx	':':CCC117H---17H-----r4   c                    t          j        d          }d|d<   t                      5 }|                    t          d           t          ||d          \  }}t          ||dd          \  }}d d d            n# 1 swxY w Y   t          ||d	          \  }}t          ||           t          ||           t          ||           t          ||           d S )
Nr&   r!   r   z+nperseg=256 is greater than signal length.*r   r   r  r  r   )r(   r)   r   r  r  r   r   r  s	            r2   r  zTestCSD.test_short_data/  s   HQKK!    	;CJJ{$QRRRq!F+++DAqAfc:::FB	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; Q1%%%B22BBs   AA;;A?A?c                    t          t          t          t          j        d          t          j        d          dt          j        g d                     t          t          t          t          j        d          t          j        d          dt          j        d                              d                     d S r   )	r^   r_   r   r(   r)   r+   r   r=   rl   r`   s    r2   r!  zTestCSD.test_window_long_or_nd?  s    j#rx{{BGAJJh{{{++	- 	- 	-j#rx{{BGAJJill**511	3 	3 	3 	3 	3r4   c                     t          j        d          }d|d d d<   t          ||dd          \  }}t          j        g d          }t	          ||d	           d S r#  )r(   r)   r   r   r   r,   s        r2   r)  z TestCSD.test_nondefault_noverlapE  ss    HRLL##A#1aa0001H     15))))))r4   c           
          t          t          t          t          j        d          t          j        d          dddd           d S r+  )r^   r_   r   r(   r)   r+   r`   s    r2   r-  zTestCSD.test_bad_noverlapM  s?    j#rx{{BGAJJ6	 	 	 	 	r4   c                     t          t          t          t          j        d          t          j        d          dd           d S r/  )r^   r_   r   r(   r+   r)   r`   s    r2   r1  zTestCSD.test_nfft_too_shortQ  s@    j#rwr{{BHRLLq	! 	! 	! 	! 	! 	!r4   c                     t          j        t          d          5  t          t	          j        d          t	          j        d          d           d d d            d S # 1 swxY w Y   d S )Nzx and y cannot be broadcast.*r   )r!   r&   r!   )rf   r&   r\   r   )r   r	   r_   r   r(   r+   r`   s    r2   test_incompatible_inputsz TestCSD.test_incompatible_inputsU  s    ]:-LMMM 	@ 	@	""BGFOOQ????	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s   7A  A$'A$c                 D   t          j        dd          }d|d<   d|d<   t          ||d          \  }}t          |t          j        ddd                     t          j        g d	d          }t          ||d
d
           t          |j        |j        k               d S r3  )r(   r)   r   r   r*   r   r   rO   r,   s        r2   r   z"TestCSD.test_real_onesided_even_32Z  s    HR!!1a###12;q#q11222H " " "#&( (14d333317"#####r4   c                 F   t          j        dd          }d|d<   d|d<   t          ||d          \  }}t          |t          j        d          d	z             t          j        g d
d          }t          ||dd           t          |j        |j        k               d S r5  )r(   r)   r   r   r=   r   r   rO   r,   s        r2   r   z!TestCSD.test_real_onesided_odd_32e  s    HR!!1a###129S>>#-...H " " "#&( (14d333317"#####r4   c                 :   t          j        dd          }d|d<   d|d<   t          ||dd          \  }}t          |t	          dd                     t          j        g d	d          }t          ||d
d
           t          |j        |j        k               d S r7  r(   r)   r   r   r   r   r   rO   r,   s        r2   r   zTestCSD.test_real_twosided_32p  s    HR!!1aE:::171c??+++H " " "#&( ( 	14d333317"#####r4   c                 \   t          j        dd          }d|d<   d|d<   t          ||dd          \  }}t          |t	          dd                     t          j        g d	d
          }t          ||dd           t          |j        |j        k    d|j         d|j                    d S r:  r  r,   s        r2   r   zTestCSD.test_complex_32|  s    HR!!1aE:::171c??+++H F F FGJL L14d333317"71777ag77	9 	9 	9 	9 	9r4   c                 &   t          j        d          }t          j        d          }d}t          |d          d |dz  dz            }|dxx         dz  cc<   t	          ||d|          \  }}t	          ||d	|          \  }}t          ||           t          ||           d
}t          |d          d |dz   dz           }t	          ||d|          \  }}t	          ||d	|          \  }}t          ||           t          ||           d S r?  )r(   r)   r+   r   r   r   )r-   r.   r~  r   r/   rC  rD  rE  s           r2   rF  zTestCSD.test_padded_freqs  s)   HRLLGBKKD#za	z*	"aAD111aq!QT222q4   5!!!D#~A~.aAD111aq!QT222q4   5!!!!!r4   c                 d   t           j                            d          }|                                }t	          ||ddd          \  }}t	          ||ddd          \  }}t          ||           t	          ||ddd          \  }}t	          ||ddd          \  }}t          ||           d S )Nr$  r&   meanF)r   rn  rA   rm  )r(   r_  ra  r  r   r   )r-   r.   r~  rD  p_samep_copieds         r2   test_copied_datazTestCSD.test_copied_data  s    IOOBFFHH1a(-/ / /	6!Q6*/1 1 18)))1a(-/ / /	6!Q8*/1 1 18)))))r4   N)&r   r   r   r  r  r  r  r3   r>   rE   rL   r   r   rU   rZ   ra   r   r   r  r  r  rr   rx   r   r   r   r  r!  r)  r-  r1  r  r   r   r   r   rF  r  r   r4   r2   rz  rz  <  s*       	 	 		 	 	$ $ $      4 4 44 4 44 4 44 4 44 4 44 4 44 4 44 4 4K K K9 9 9
, , ,9 9 99 9 99 9 9J J J> > >$ $ $&+ + +,. . .      3 3 3* * *  ! ! !@ @ @
	$ 	$ 	$	$ 	$ 	$
$ 
$ 
$
9 
9 
9" " "&* * * * *r4   rz  c                       e Zd Zd Zd ZdS )TestCoherencec                 *   t           j                            d          }t          j        |          }t          j        ddd          }t          j        d          }t          ||d          \  }}t          ||           t          ||           d S Nrd   r   r"   ri   rg   r   )r(   r_  ra  r  r*   r+   r   r   r-   r.   r~  r/   Cr   C1s          r2   test_identical_inputz"TestCoherence.test_identical_input  s    IOOBGAJJK3""GAJJ1a,,,B22r4   c                    t           j                            d          }| }t          j        ddd          }t          j        d          }t          ||d          \  }}t          ||           t          ||           d S r  )r(   r_  ra  r*   r+   r   r   r  s          r2   test_phase_shifted_inputz&TestCoherence.test_phase_shifted_input  sz    IOOBBK3""GAJJ1a,,,B22r4   N)r   r   r   r  r  r   r4   r2   r  r    s2        	 	 		 	 	 	 	r4   r  c                        e Zd Zd Zd Zd ZdS )TestSpectrogramc                    t           j                            d          }d}d}d}d}t          |||||          \  }}}t	          |||||          \  }	}
t          ||	           t          t          j        |d          |
           d S )Nr\  rB   rJ  g      ?r    rf   r$   ru   )r(   r_  ra  r   r   r   r  )r-   r.   rM  r   r   r&  r/   rD  PfwPws              r2   test_average_all_segmentsz)TestSpectrogram.test_average_all_segments  s    IOOD!! aVWh??1aq"fgx88B2+++R00000r4   c                    t           j                            d          }d}d}d}d}t          |||||          \  }}}t	          j        dd          }	t          |||	d d          \  }
}}t          |
j        d           t          |j        d           t          t          t          |||	d	
           t	          j        dd          }t          t          t          |||d 
           d S )Nr\  rB   r  r    rf   r%  )r#   )r#   I   r&   r   i   )
r(   r_  ra  r   r
   r{   r   rm   r^   r_   )r-   r.   rM  r   r   r&  r/   rD  r  r}   r~   Per   s                r2   r   z$TestSpectrogram.test_window_external  s    IOOD!! aVWh??1a442sD1EEE	Ar28T***28V,,,j+q#q	* 	* 	* 	*#OT::j+q'4	1 	1 	1 	1 	1 	1r4   c                    t           j                            d          }d}t          ||d          \  }}}t	                      5 }|                    t          d           t          ||dd          \  }}}d d d            n# 1 swxY w Y   t          ||d	          \  }	}}
t          ||d	          \  }}}t          ||	           t          ||
           t          ||           t          ||           d S )
Nr\  rB   r  r   zInperseg = 1025 is greater than input length  = 1024, using nperseg = 1024i  r  r  r   )r(   r_  ra  r   r   r  r  r   )r-   r.   rM  r/   rD  r0   r  r   r   r   r   f3p3s                r2   r  zTestSpectrogram.test_short_data  sR   IOOD!! aN;;;1a   	2CJJ{.0 0 0 $Ar.,02 2 2IB2		2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2  2s333	Ar2t444	Ar22BBs   3BB	B	N)r   r   r   r  r   r  r   r4   r2   r  r    sA        1 1 11 1 1&         r4   r  c                   n    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd ZdS )TestLombscarglec           	         d}d}dt           j        z  }d}d}d}t           j                            d          }|                    |          }t          j        dt           j        z  d	t           j        z  |          ||k             }	|t          j        ||	z  |z             z  }
t          j        dd	|          }t          |	|
|          }|d
         |d         z
  }||t          j        |                   z
  |dz  k     sJ t          |	|
|t          j	        |	|j
                            }|d
         |d         z
  }||t          j        |                   z
  |dz  k     sJ dS )zgTest if frequency location of peak corresponds to frequency of
        generated input signal.
        r%   rB   r"   d     ffffff?# {Gz?      $@r!   r   rN   weightsN)r(   rP  r_  RandomStaterandr*   rO  r   argmax	ones_likerO   )r-   amplwphininnoutr0   rngrtr~  r/   r  deltas                 r2   test_frequencyzTestLombscargle.test_frequency  s]    BEk i##G,,HHSMMKRU
CIs33AF; 26!A#)$$$ Kc4(( 1a   !qt1RYq\\?"eBh//// 1aaqw)G)G)GHHH !qt1RYq\\?"eBh//////r4   c                    d}d}dt           j        z  }d}d}d}t           j                            d          }|                    |          }t          j        dt           j        z  dt           j        z  |          ||k             }	|t          j        ||	z  |z             z  }
t          j        dd|          }t          |	|
|          }t          j        d	|z  |	j	        d
         z            }t          |||k             |d           d S )Nr%   rB   r"   r  r  r  r  r  g      @r   ro  rN  )r(   rP  r_  r  r  r*   rO  r   rQ  rm   r   )r-   r  r  r  r  r  r0   r  r  r  r~  r/   pgrams                r2   test_amplitudezTestLombscargle.test_amplitude#  s   
 BEk i##G,,HHSMMKRU
CIs33AF; 26!A#)$$$ Kc4(( Aq!$$ eagaj011 	adT555555r4   c                    d}d}dt           j        z  }d}d}d}d}t           j                            d          }|                    |          }	t          j        d	t           j        z  d
t           j        z  |          |	|k             }
|t          j        ||
z  |z             z  |z   }t          j        d	d
|          }t          |
||d          }t          |
||                                z
  |d          }t          ||           t          |
||dd          }t          |
||                                z
  |dd          }t          ||           d S )Nr%   rB   r"   r  r  r  g333333?r  r  r  T)	precenterF)r  floating_mean)
r(   rP  r_  r  r  r*   rO  r   r  r   )r-   r  r  r  r  r  r0   offsetr  r  r  r~  r/   r  pgram2s                  r2   test_precenterzTestLombscargle.test_precenterD  sV   
 BEk i##G,,HHSMMKRU
CIs33AF; 26!A#)$$$v- Kc4(( Aq!t444QAFFHHa5AAA 	v&&&
 Aq!t4HHHQAFFHHa5PTUUU 	v&&&&&r4   c                    d}d}dt           j        z  }d}d}d}t           j                            d          }|                    |          }t          j        dt           j        z  d	t           j        z  |          ||k             }	|t          j        ||	z  |z             z  }
t          j        dd	|          }t          |	|
|          }t          |	|
|d
          }t          j        |	          t          |	j
        d                   z  }||
z  |
z                                  }|}d||	j
        d         z  z  }t          ||z  |           t          t          j        |          d           d S )Nr%   rB   r"   r  r  r  r  r  r  T	normalizer   rf   )r(   rP  r_  r  r  r*   rO  r   r  floatrm   rt  r   max)r-   r  r  r  r  r  r0   r  r  r  r~  r/   r  r  r  YY_hatYYscale_to_uses                     r2   test_normalizezTestLombscargle.test_normalizel  s[    BEk i##G,,HHSMMKRU
CIs33AF; 26!A#)$$$ Kc4(( Aq!$$Q1555 ,q//%
"3"33A+/&&(("QWQZ-( 	,f555v,,,,,r4   c           	      J   t          j        ddd          }t          j        ddd          }t          j        ddd          dz   }t          t          t          |||           t          j        t          j        t          j        ddd          d          dd          }t          j        ddd          }t          j        ddd          dz   }t          t          t          |||           t          j        ddd          }t          j        t          j        t          j        ddd          d          dd          }t          j        ddd          dz   }t          t          t          |||           t          j        ddd          }t          j        ddd          }t          j        t          j        t          j        ddd          d          dz   dd          }t          t          t          |||           t          j        ddd          }t          j        ddd          }t          j        ddd          dz   }t          j        t          j        t          j        ddd          d          dd          }t          t          t          ||||           d S )Nr   r!   rf   r   rK  ru   r  )r(   r*   r^   r_   r   repeatexpand_dimsr-   r  r~  r/   r  s        r2   test_wrong_shapez TestLombscargle.test_wrong_shape  sB    K1a  K1a  K1a  3&j+q!Q777 IbnR[Aq%9%91==qqIIIK1a  K1a  3&j+q!Q777 K1a  IbnR[Aq%9%91==qqIIIK1a  3&j+q!Q777 K1a  K1a  IbnR[Aq%9%91==CQQOOOj+q!Q777 K1a  K1a  K1a  3&)BN2;q!Q+?+?CCQQOOOj+q!QHHHHHHr4   c                     t          j        dddd          }t          j        d|z            }t          j        dddd          d	z   }t          |||d
z  t           j        z             d S )Nr   rg   r  F)endpointr\   2   i  rK  rf   )r(   r*   rO  r   rP  )r-   r  r~  r/   s       r2   test_lombscargle_atan_vs_atan2z.TestLombscargle.test_lombscargle_atan_vs_atan2  sl     K2te444F1Q3KKK2sU333c9Aq!A#be)$$$$$r4   c                     t          j        ddd          }t          j        ddd          }t          j        ddd          dz   }t          j        ddd          }t          t          t          ||||           d S )Nr   r!   r   rK  rf   r  )r(   r*   r^   r_   r   r  s        r2   test_wrong_shape_weightsz(TestLombscargle.test_wrong_shape_weights  sv     K1a  K1a  K1a  3&+aA&&j+q!QHHHHHHr4   c                     t          j        d          }t          j        d          }t          j        d          }t          j        d          }t          t          t
          ||||           d S Nr!   r  r(   r)   r+   r^   r_   r   r  s        r2   test_zero_division_weightsz*TestLombscargle.test_zero_division_weights  sY     HQKKHQKKGAJJ(1++j+q!QHHHHHHr4   c                 j   d}d}d}d}d}d}t           j                            d          }|                    |          }t          j        dt           j        z  d	t           j        z  |          ||k             }	|t          j        ||	z  |z             z  }
t          j        dd	|          }t          |	|
|d
          }t          |	|
|d          }t          |	|
|d          }t          |	|
|d          }t          |	|
|d          }t          ||           t          ||           t          j	        |
          t          |
j        d                   z  }||
z  |
z                                  }|}t          |dz  t          |	j        d                   |z  z  |           t          j        ||k              d         d         }t          t          j        ||                   |           t          t           t          |	|
|d           t          t           t          |	|
|d           d S )Nr%   rB   r   r  r  r  r  r  r  Fr  Tpowerr  	amplitudelombrf   )r(   r_  r  r  r*   rP  rO  r   r   r  r  rm   rt  whereru  r^   r_   )r-   r  r  r  r  r  r0   r  r  r  r~  r/   pgram_false
pgram_truepgram_power
pgram_norm	pgram_ampr  r  r  f_is                        r2   test_normalize_parameterz(TestLombscargle.test_normalize_parameter  s     i##G,,HHSMMKRU
CIs33AF; 26!A#)$$$ Kc4(( "!QU;;; AqD999
!!QW=== AqK@@@
1a;???	 	[111
J/// ,q//%
"3"33A+/&&((c)U171:->->-CDjQQQ hq!tnnQ"y~..555 	j+q!Q&IIIIj+q!Q!DDDDDDr4   c                    d}d}dt           j        z  }d}d}d}d}t           j                            d          }|                    |          }	t          j        d	t           j        z  d
t           j        z  |          |	|k             }
|t          j        ||
z  |z             z  }t          j        d	d
|          }t          |
||d          }t          |
||z   |d          }t          ||           d S )Nr%   rB   r"   r  r  r  333333@r  r  r  T)r  )	r(   rP  r_  r  r  r*   rO  r   r   r-   r  r  r  r  r  r0   r  r  r  r  r~  r/   r  pgram_offsets                  r2   test_offset_removalz#TestLombscargle.test_offset_removal  s    
 BEk i##G,,HHSMMKRU
CIs33AF; 26!A#)$$$ Kc4(( Aq!4888"1a&j!4HHH 	|,,,,,r4   c                    d}d}d}d}d}d}d}t           j                            d          }|                    |          }	t          j        dt           j        z  d	t           j        z  |          |	|k             }
|t          j        ||
z  |z             z  }t          j        dd	|          }t          |
||d
d          }t          |
||z   |d
d          }|d         dk     sJ |d         dk    sJ d S )Nr%   rB   r   r  r  rf   r  r  r  TFr  r  r"   r(   r_  r  r  r*   rP  cosr   r  s                  r2   test_floating_mean_falsez(TestLombscargle.test_floating_mean_false  s     i##G,,HHSMMKRU
CIs33AF; 26!A#)$$$ Kc4(( Aq!t5III"1a&j!t168 8 8
 Qx$A$$$$$$r4   c                 |   d}d}d}d}d}d}d}t           j                            d          }|                    |          }	t          j        d	t           j        z  d
t           j        z  |          |	|k             }
|t          j        ||
z  |z             z  |z   }t          j        d	d
|          }t          j        ||k              d         d         }t          |
||dd          }t          t          j
        ||                   |           t          t          j        ||                    |           d S )Nr%   rB   Q?r  r  r  r  r  r  r  r   r  Tr"  )r(   r_  r  r  r*   rP  r$  r  r   r   ru  angle)r-   r  r  r  r  r  r0   r  r  r  r  r~  r/   f_indxr  s                  r2   test_amplitude_is_correctz)TestLombscargle.test_amplitude_is_correct=  s-     i##G,,HHSMMKRU
CIs33AF; 26!A#)$$$v- Kc4(( !Q$"1% Aq!{$OOO 	uV}--t444 	%-000#66666r4   c                     t          j        d          }t          j        d          }t          j        d          }t          j        d           }t          t          t
          ||||           d S r  r  r  s        r2   test_negative_weightz$TestLombscargle.test_negative_weighta  s[     HQKKHQKKGAJJ71::+j+q!QHHHHHHr4   c                     g d}g d}t          j        ddd          }dt           j        z  |z  }t          |||dd           d S )	N)yg   ˈAg   ˈAg   ̈Ag   ͈Ag   ΈAg   ψAg   ЈAg   шAg   ҈Ag   ӈAg   ԈAg   ՈAg   ֈAg   ׈Ag   ؈Ag   وAg   ڈAg   ۈAg   ܈Ag   ݈Ag   Ag   Ag   Ag   Ag   Ag    Ag   Ag   Ag   Ag   Ag   Ag   Ag   Ag   Ag   Ag   Ag   Ag    Ag   Ag   Ag   "Ag   Ag   Ag   Ag   
Ag   Ag   Ag   Ag    Ag   !Ag   "Ag   #Ag   $Ag   %Ag   &Ag   'Ag   (Ag   )Ag   *Ag   +Ag   ZcAg   TdAg   NeAg   HfAg   BgAg   <hAg   6iAg   0jAg   *kAg   $lAg   mAg   nAg   oAg   pAg   qAg    rAg   rAg   sAg   tAg   uAg   wAg   xAg   yAg   zAg   {Ag   |Ag   }Ag   ~Ag   Ag   Ag   Ag   Ag   Ag   Ag   Ag   Ag   |Ag   vAg   pAg   jAg   Ag   
Ag   Ag   Ag   Ag   Ag   잉Ag   柉Ag   ࠉAg   ڡAg   ԢAg   ΣAg   ȤAg   ¥Ag   Ag   Ag   Ag   Ag   Ag   Ag   A)yg     @@g     ܨ@g     J@g     @g     9@g     @g     @g     2@g    @g     @g     i@g     @g    j@g    @g     @g    @g     @g     @g    ?@g    @g     n@g     ײ@g     .@g     @g     h@g     @g     ޫ@g     Ӱ@g     >@g     @g     @g     b@g     @g    H@g    @g     @g    @g    d@g     @g    @g     p@g     ̳@g     m@g     D@g     ҧ@g     @g     @g     @g     G@g     @g     @g     _@g     @g    @g    @g     "@g    @g    @g     M@g     n@g    @g     @g     0@g     @g      @g    D@g     w@g     9@g     y@g     µ@g     6@g     @g     \@g     F@g     @g     Ь@g     k@g     @g     @g     V@g     @g     @g     D@g    @g    J@g    @g     @g     @g    @g    @g    3@g    @g    @g    @g     @g     @g    s@g    @g    :@g    b@g     @g     @g     p@g     @g     @g     @g     Q@g     @g     \@g     !@g     @g    j@g     @g    F@g    @g    @g    @g     e@g    @g     @g    @i  x   r  rf   T)r  r  )r(   r*   rP  r   )r-   r  r~  periodsangular_freqs        r2   test_list_inputzTestLombscargle.test_list_inputj  si      >  @ +c3--25y7*Aq,$$GGGGGGr4   c                    d}d}d}d}d}d}d}t           j                            d          }|                    |          }	t          j        d	t           j        z  d
t           j        z  |          |	|k             }
|t          j        ||
z  |z             z  |z   }t          j        dd
|          }t          |
||dd          }|d         dk     sJ d S )Nr%   rB   r'  r  i  r  r   r  r  r  Tr"  -C6?r#  )r-   r  r  r  r  r  r0   r  r  r  r  r~  r/   r  s                 r2   test_zero_freqzTestLombscargle.test_zero_freq  s    
  i##G,,HHSMMKRU
CIs33AF; 26!A#)$$$v- K3%% Aq!t4HHH Qx$r4   c                    d t          dd          D             }t          j        t          |                    }dt          j        z  gdz  }t          |||           d t          dd          D             }t          j        t          |                    }t          j        dz  gdz  }t          |||           d S )Nc                     g | ]}|d z   S )r!   r   .0r  s     r2   
<listcomp>z8TestLombscargle.test_simple_div_zero.<locals>.<listcomp>  s    )))qQU)))r4   r   rz   r%   rf   c                     g | ]
}|d z  dz   S )r\   r!   r   r7  s     r2   r9  z8TestLombscargle.test_simple_div_zero.<locals>.<listcomp>  s     +++QqS1W+++r4   )rb  r(   r+   r  rP  r   )r-   r  r~  freqss       r2   test_simple_div_zeroz$TestLombscargle.test_simple_div_zero  s    
 *)E!RLL)))GCFFOORUaAq%    ,+eArll+++GCFFOOsaAq%     r4   N)r   r   r   r  r  r  r   r  r	  r  r  r  r   r%  r*  r,  r1  r4  r<  r   r4   r2   r  r    s"       &1 &1 &1R6 6 6B&' &' &'P"- "- "-HI I IB% % %I I II I I/E /E /Eb- - -> &  &  &D"7 "7 "7HI I IFH FH FHP     >! ! ! ! !r4   r  c                   `   e Zd Zej        j        d             Zd Zd Zd Z	d Z
ej                            dddg          d	             Zej        j        d
             Zd Zd Zej        j        ej                            dddg          d                         Zd Zd Zd Zd Zd ZdS )TestSTFTc                    d } |d          5  t          ddd           d d d            n# 1 swxY w Y    |d          5  t          ddd           d d d            n# 1 swxY w Y    |d	          5  t          t          j        d
          dd           d d d            n# 1 swxY w Y    |d          5  t          t          j        d          dd           d d d            n# 1 swxY w Y    |d          5  t          ddd           d d d            n# 1 swxY w Y    |d          5  t          ddd           d d d            n# 1 swxY w Y    |d	          5  t          t          j        d
          dd           d d d            n# 1 swxY w Y    |d          5  t          t          j        d          dd           d d d            n# 1 swxY w Y    |d          5  t          ddd           d d d            n# 1 swxY w Y   t          j        d          }t          |          d         } |d	          5  t          |t          j        d
                     d d d            n# 1 swxY w Y    |d          5  t          |t          j        d          d           d d d            n# 1 swxY w Y    |d          5  t          |d           d d d            n# 1 swxY w Y    |d          5  t          |dd           d d d            n# 1 swxY w Y    |d          5  t          |dd           d d d            n# 1 swxY w Y    |d          5  t          |           d d d            n# 1 swxY w Y    |d	          5  t          |t          j        d
                     d d d            n# 1 swxY w Y    |d          5  t          |t          j        d          d           d d d            n# 1 swxY w Y    |d          5  t          |d           d d d            n# 1 swxY w Y    |d          5  t          |dd           d d d            n# 1 swxY w Y    |d          5  t          |dd           d d d            n# 1 swxY w Y   t          j        t          d          5  t          |ddd            d d d            n# 1 swxY w Y    |d!          5  t          |dd"           d d d            n# 1 swxY w Y    |d#          5  t          ||d$%           d d d            n# 1 swxY w Y    |d&          5  t          |d d'         |d'd          d(%           d d d            n# 1 swxY w Y    |d)          5  t          ||d$*           d d d            n# 1 swxY w Y   d+} |d,|d-          5  t          ||.           d d d            n# 1 swxY w Y    |d,|d-          5  t          ||.           d d d            d S # 1 swxY w Y   d S )/Nc                 8    t          j        t          |           S )zAssert for a ValueError matching regexp `match`.

            This little wrapper allows a more concise code layout.
            r   )r   r	   r_   r   s    r2   chk_VEz.TestSTFT.test_input_validation.<locals>.chk_VE  s    
 =59999r4   z"nperseg must be a positive integerr   ir   z#noverlap must be less than nperseg.rg   rd   zwindow must be 1-D)rf   rf   z"window must have length of npersegz"noverlap must be less than npersegz&noverlap must be a nonnegative integerr$  ir\  rf   r   z>value specified for nperseg is different from length of windowr  r  i r   r%  z.nfft must be greater than or equal to nperseg.r&   rA  zInput stft must be at least 2d!zwindow must have length of 256z1NOLA condition failed, STFT may not be invertibler   r   r&  r   z/Must specify differing time and frequency axes!	time_axis	freq_axisz=Unknown value for mode foo, must be one of: \{'psd', 'stft'\}r]   )modez'x and y must be equal if mode is 'stft'   stftz[Unknown boundary option 'foo', must be one of: \['even', 'odd', 'constant', 'zeros', None\])boundary	not_validzParameter scaling=z not in \['spectrum', 'psd'\]!rH   )r   r(   r+   r   r)   rH  istftr   warnsr  r   )r-   rA  r.   zrI   s        r2   test_input_validationzTestSTFT.test_input_validation  s   	: 	: 	: V899 	' 	'vsA&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'V9:: 	' 	'vr2&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'V()) 	/ 	/rwvA...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/V899 	+ 	+rwr{{B***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ V899 	' 	'vsA&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'V899 	' 	'vr2&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'V()) 	/ 	/rwvA...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/V899 	+ 	+rwr{{B***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+V<== 	( 	(vr3'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( HTNNGGAJ V()) 	, 	,276??++++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,V , - - 	5 	5272;;4444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 V899 	" 	"D!!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"V9:: 	0 	0C$////	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0VDEE 	) 	)Ca((((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) V566 	 	!HHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	V()) 	- 	-!BGFOO,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-V455 	6 	6!BGBKK5555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6V899 	# 	#!T""""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#V9:: 	1 	1!S40000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1VDEE 	* 	*!Sq))))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*\+ .7 8 8 8 	= 	=!S1V<<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= VEFF 	/ 	/!qA....	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ V ) * * 	/ 	/Q....	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ V=>> 	< 	<QttWagF;;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<V D E E 	3 	3QE2222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 VJ'JJJKK 	% 	%G$$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%VJ'JJJKK 	& 	&!W%%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s  -11A!!A%(A%7$B''B+.B+=$C--C14C1D!!D%(D%7EEE+$FF"F1$G!!G%(G%7HHH$JJJ%KKK!K??LLL44L8;L8
M))M-0M-?NN"N1$O!!O%(O%7%P((P,/P,>QQ #Q 2RRR'SS
S
,TTT"UUUU66U:=U:#V;;V?V?W00W47W4X**X.1X.Y##Y'*Y'c                 ^    g d}|D ]%} dj         | }t          dt          | |           &d S )N)r  rg   r   r  rg   r#   rI  3      r   r     r   r     blackmanrH     rJ  r"   r  r$  r   r     
{}, {}, {}Tr]  )formatr   r   )r-   settingssettingmsgs       r2   test_check_COLAzTestSTFT.test_check_COLA7  s^    	 	 	   	B 	BG%,%w/Cz73SAAAAA	B 	Br4   c                 .   g d}|D ]%} dj         | }t          dt          | |           &t          j        d          }d|d d d<   |t          |          t          |          dz  fdg}|D ]%} dj         | }t          d	t          | |           &d S )
N)rP  rQ  )r  rg   r,  rR  )rI  rS  rg   rU  rW  )r   r  %   rY  )rZ  rH  {   r\  )r]  r  &   r^  )r   r  '   r`  Tr]  r    r   rf   )r   r$  r   F)ra  r   r   r(   r+   r  )r-   settings_passrc  rd  w_failsettings_fails         r2   test_check_NOLAzTestSTFT.test_check_NOLAG  s        % 	B 	BG%,%w/Cz73SAAAAAsssS[[#f++*:;#
 % 	C 	CG%,%w/C
G 4cBBBBB	C 	Cr4   c           
      z   t           j                            d          }|                    d          }d}d}d}d}t	          |||||ddd           \  }}}	t          |||||dd	d
          \  }
}t          ||
           t          t          j        t          j        |	          dz  d          |           d S )Nr[  r\  rB   r   r    r&   F)paddedrA   rI  rG   )rA   rI   r   rf   r$   ru   )	r(   r_  r  ra  rH  r   r   r  ru  )r-   r  r.   rM  r   r   r&  r/   rD  Zr  r  s               r2   r  z"TestSTFT.test_average_all_segmentsf  s    i##D))IIdOO
 q"fgx',t= = =1aq"fgx)5: : :B 	2q		12666;;;;;r4   c           	      >   t           j                            d          }|                    d          }d}d}d}d}t	          |||||          \  }}}	t	          |                    d          ||||d	          \  }
}}t          |	||||          \  }}t          |j        ||||dd
          \  }}t          ||
           t          ||           t          ||           t          |	|d d ddd d f                    t          ||d d ddf                    d S )Nr[  r\  rB   r   r    r&   )r$   r!   r!   r   ru   r$   rC  )	r(   r_  r  ra  rH  rl   rK  Tr   )r-   r  r.   rM  r   r   r&  r   t1Z1r   t2Z2t3x1t4x2s                    r2   test_permute_axeszTestSTFT.test_permute_axesz  sF   i##D))IIdOO!R(;;
B!))J//VWh " " "
B r2vw99BrtR(a!#% % %B 	BBBBqqq!QzN+++Bqqq!QwK(((((r4   rI   rG   psdc           
      z   t           j                            d          }g d}|D ]\  }}}}t          j        |          }d|                    |j                  z  }	t          |	|||d d|          \  }
}
}t          |||||          \  }}| d| }t          |||           t          |	||           d S )	Nr[  r  r  rg   r   r  r  rg   r#   )rI  e   rS  rT  r   r\  r  rV  )r]    r  r$  )r   r\  r  r_  rg   F)r   r&  r   r   rp  rI   )r   r&  r   rI   r=  r]  	r(   r_  r  r=   ra  sizerH  rK  r   )r-   rI   r  rb  r   Nr   r&  r  r.   rD  zztrxrrd  s                  r2   test_roundtrip_realzTestSTFT.test_roundtrip_real  s   i##D))   -5 	0 	0(FAw	!A399QV$$$AAw#)4$+- - -HAq" 2w"('; ; ;FB ))x))CAr3////Ar3/////	0 	0r4   c           
      (   t           j                            d          }t          j        d          }d|d d d<   |dt	          |          t	          |          dz  fdg}|D ]-\  }}}}| d| d| d| }t          |||          r
J |            t          j        |          }	d|                    |	j                  z  }
t          |
|||d d	d
          \  }}}t          j        t          d          5  t          ||||d	          \  }}d d d            n# 1 swxY w Y   t          j        |	|d t	          |	                             s
J |            t          j        |
|d t	          |
                             r
J |            /d S )Nr[  r    r   rf   r  )r   r  r$  r   r=  rg   Tr)   r   r&  r   r   rp  rI  NOLAr   r   r&  r   rI  )r(   r_  r  r+   r  r   r=   ra  r  rH  r   rL  r  rK  allclose)r-   r  rl  rb  r   r  r   r&  rd  r  r.   rD  r  r  r  s                  r2   test_roundtrip_not_nolaz TestSTFT.test_roundtrip_not_nola  s    i##D))sssS#f++s6{{a/?@(

 -5 	8 	8(FAw99q99G99x99C!&'8<<AAcAAA	!ASYYqv&&&AAw#)4%,. . .HAq" k888 = =r7X&,t= = =B= = = = = = = = = = = = = = = ;q"Wc!ffW+..33333{1b#a&&k2277C7777	8 	8s   9DD!	$D!	c           
      N   t           j                            d          }g d}|D ]\  }}}}| d| d| }t          |||          s
J |            t	          |||          r
J |            t          j        |          }d|                    |j                  z  }	t          |	|||d dd          \  }
}
}t          ||||d          \  }}| d| }t          ||d t          |                   |	           t          |	|d t          |	                   |	           d S )
Nr[  ))r  r  rg   r   )rI  r  rS  rg  )r   r\  r     )r]  r  r     )r   r\  r  r   r=  rg   Tr)   r  r  r]  )r(   r_  r  r   r   r=   ra  r  rH  rK  r   r  )r-   r  rb  r   r  r   r&  rd  r  r.   rD  r  r  r  s                 r2   test_roundtrip_nola_not_colaz%TestSTFT.test_roundtrip_nola_not_cola  sy   i##D))   -5 	9 	9(FAw44w44(44Cfgx88==#===!&'8<<AAcAAA	!ASYYqv&&&AAw#)4%,. . .HAq" 2w"(49 9 9FB ))x))CAr'3q66'{C8888Ar'3q66'{C88888#	9 	9r4   c           	         t           j                            d          }dg}|D ]\  }}}}t          j        |          }d|                    |j                  z  }|                    t           j                  }t          ||||d d          \  }	}	}
t          |
|||          \  }}| d| }t          |||           t          |||d	d
           t          |j        |j        k               d S )Nr[  r  rg   Fr   r&  r   r   rp  rB  r=  r]  r3  gh㈵>)r^  r   r<   )r(   r_  r  r=   ra  r  astypefloat32rH  rK  r   r   rO   r-   r  rb  r   r  r   r&  r  r.   rD  r  r  r  rd  s                 r2   test_roundtrip_float32zTestSTFT.test_roundtrip_float32  s#   i##D)),-,4 	) 	)(FAw	!A399QV$$$A$$AAw#)4G G GHAq" 2w"(* * *FB ))x))CAq#....Ar3TEEEEAGrx'((((	) 	)r4   c                    t           j                            d          }g d}|D ]\  }}}}t          j        |          }d|                    |j                  z  d|                    |j                  z  z   }	t          |	|||d dd|          \  }
}
}t          ||||d|          \  }}| d| d| }t          |||	           t          |	||	           t                      5 }|
                    t          d
           t          |	|||d dd|          \  }
}
}d d d            n# 1 swxY w Y   t          ||||d|          \  }}| d| d| }t          |||	           t          |	||	           d S )Nr[  r  rg   y              $@F)r   r&  r   r   rp  rA   rI   )r   r&  r   input_onesidedrI   r=  r]  z9Input data is complex, switching to return_onesided=FalseT)r(   r_  r  r=   ra  r  rH  rK  r   r   r  r  )r-   rI   r  rb  r   r  r   r&  r  r.   rD  r  r  r  rd  r  s                   r2   test_roundtrip_complexzTestSTFT.test_roundtrip_complex  sV    i##D))   -5 	0 	0(FAw	!A399QV$$$s399QV+<+<'<<AAw#)4,17D D DHAq" 2w"(#*, , ,FB 44w44(44CAr3////Ar3/////    	CCJJ{RT T TAw#)4,0'C C CHAq"	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C r7X$UGM M MB 00700h002s++++2s++++++s   ,7D//D36D3c                    t           j                            d          }ddg}|D ]\  }}}}t          j        |          }d|                    |j                  z  }t          ||||d dd           \  }	}	}
t          |
||d          \  }	}d	D ]`}t          ||||d d|          \  }	}	}t          |||d          \  }	}| d
| d
| }t          |||           t          |||           ad S )Nr[  r  r  rg   Tr  F)r&  r   rI  )evenoddconstantr)   r=  r]  r  )r-   r  rb  r   r  r   r&  r  r.   rD  r  r  rI  zz_extxr_extrd  s                   r2   !test_roundtrip_boundary_extensionz*TestSTFT.test_roundtrip_boundary_extension)  s`   i##D)) +*
 -5 	8 	8(FAw	!A399QV$$$AAw"($t$(* * *HAq" "xOOOEAr@ 
8 
8#Aw'-tD)1 3  3  31f "&8F)-/ / /	6  99899x992s33336377777
8	8 	8r4   c           	         t           j                            d          }ddg}|D ]\  }}}}t          j        |          }d|                    |j                  z  }t          ||||d d          \  }	}	}
t          |
||          \  }}| d| }t          ||d |j                 |	           t          ||d |j                 |	           d S )
Nr[  )r  r  rg   r   )r   r  r  rV  rg   Tr  )r&  r   r=  r]  r  r  s                 r2   test_roundtrip_padded_signalz%TestSTFT.test_roundtrip_padded_signalJ  s   i##D)) +,
 -5 	9 	9(FAw	!A399QV$$$AAw#)4F F FHAq" 2@@@FB))x))CAr'16'{C8888Ar'16'{C88888	9 	9r4   c                 X   t           j                            d          }g d}|D ]\  }}}}}t          j        |          }d|                    |j                  z  }	|	t          j        dt           j        z  dz            z  }
t          |	||||d d          \  }}}t          |
||||d dd	          \  }}}t          |||||
          \  }}t          |||||d          \  }}| d| }t          |||           t          |	||           t          |
||           d S )Nr[  ))r   r\  r  rV  rG  )r   r\  r  rV  i  )r  r  rg   r   !   )r]  r  r  r$  r\  rg   y              ?r\   T)r   r&  r   r   r   rp  F)r   r&  r   r   r   rp  rA   )r   r&  r   r   )r   r&  r   r   r  r=  r]  )r(   r_  r  r=   ra  r  exprP  rH  rK  r   )r-   r  rb  r   r  r   r&  r   r  r.   xcrD  rM  zcr  r  xcrrd  s                     r2   test_roundtrip_padded_FFTz"TestSTFT.test_roundtrip_padded_FFT`  s   i##D))   3; 	2 	2.FAw$	!A399QV$$$A26"RU(1*%%%B 1gt#)4F F FGAq! B(#)4,13 3 3HAq" 1gt"(* * *FB B(#)%A A AGB ))x))CAr3////Ar3////BS11111/	2 	2r4   c                    t           j                            d          }|                    d          }t	          |          \  }}}t          d          D ]}dgdz  }d||<   |                    |          }t	          ||          \  }}}t	          |||j        z
            \  }}}	t          ||	                                |           t          ||		                                ||j        z
             t          |j        dd	          \  }}
t          |j        d
d	          \  }}t          ||
d           t          ||d           d S )Nr[  r\  r   r!   r$   ru   r]  rC  r   zistft transpose minuszistft transpose plus)r(   r_  r  ra  rH  rb  rl   rc  r   rd  rK  rs  r   )r-   r  re  rD  z_flatrg  rh  r.   z_plusz_minusx_transpose_mx_transpose_ps               r2   rk  zTestSTFT.test_axis_rolling  sW   i##D))4F||1fq 		F 		FAtAvHHQKx((A???LAq& 16222MAq'!1!11====!2!2AafHEEEEE
 !R2FFF= Q!DDD=7NOOOO7MNNNNNNr4   c                    t          j        dt                    }d|d<   t           j                            |          }t          |dz            t          |          z  }t          |dd          d         }t          |d	d          d
         }t          ||           t          t          |dddf                   d           t          t          |dddf                   d
           t          t          |dddf                   d           d|ddddf<   t          |ddddf         dt          j        |j                  j                   t          |ddd          d         }t          j        |j        dz  |j        dz  z   d          |j        d         z  }t          ||           t          |dd	d          d
         }t          ||           t          |d	dd          d         }t          j        |dddddf                   }	t          |ddddf         |           t          |ddddf         |	           t          j        |j        dz  |j        dz  z   d          t          j        |	j        dz  |	j        dz  z   d          z   }
|
|j        d         |	j        d         z   z  }t          ||           t          |d	d	d          d
         }t          ||           dS )z&Verify behavior of scaling parameter. i  rN   r\  r  rf   r  rG   )rI  rI   Tr!   ?   Nr$   r"   r$  A   r   B   r;   Fr}  )rA   rI  rI   ru   )r  rI  rI   r     )r(   r)   complexr   r   rt  r  rH  rK  r   ru  finforO   
resolutionrealimagrm   conj)r-   Xr.   power_xZsry  Zppsd_ZpZp0Zp1s2psd_Zp01s               r2   test_roundtrip_scalingzTestSTFT.test_roundtrip_scaling  s    HS(((#FLLOOad))c!ff$ !fj999!< 2j999!<A 	Br3B3wK((#...Br3B3wK((!,,,Br3B3wK((#...2b5#2#:111crc6
ABHRX,>,>,IJJJJ !UVUKKKAN 
RWaZ/a88828A;F((( 2edEJJJ1MA 1dVUKKKAN gc"Qr'111*o&&4C47S)))3447S))) fSX]SX]2;;;fSX]SX]2;;;<1	!45'*** 3tdEJJJ1MAr4   N)r   r   r   r   r   thread_unsaferN  re  rn  r  r|  parametrizer  r  r  r  r  r  r  r  rk  r  r   r4   r2   r>  r>    s       [P& P& P&dB B B C C C>< < <() ) ). [YU(;<<0 0 =<06 [8 8 869 9 9<) ) )* [[YU(;<<), ), =< ),V8 8 8B9 9 9,!2 !2 !2FO O O4? ? ? ? ?r4   r>  c                       e Zd ZU dZdZeed<   dZeed<   dZ	eed<   dZ
eed<   ej        ed	<   ej        ed
<   eed<   eed<   d Zedefd            Zedefd            Zd Zd ZdS )"TestSampledSpectralRepresentationsa  Check energy/power relations from `Spectral Analysis` section in the user guide.

    A 32 sample cosine signal is used to compare the numerical to the expected results
    stated in :ref:`tutorial_SpectralAnalysis` in
    file ``doc/source/tutorial/signal.rst``
    rz   r  rC   rs  r   a_refl_ax_refX_refE_refP_refc                 V   t          | j        | j                  }t          j        |          }d| _        | j        dz  | j        z  || j        <   t          |          | _        t          | j                  | _
        | j        | j        dz  z  dz  | _        | j        dz  dz  | _        dS )z5Create Cosine signal with amplitude a from spectrum. r   rf   N)r   r  rs  r(   r   r  r  r   r  r   r  taur  r  )r-   r/   r  s      r2   setup_methodz/TestSampledSpectralRepresentations.setup_method  s    TVTV$$a  *Q,/dh5\\
__
 X
A-1
Z]Q&


r4   returnc                      | j         | j        z  S )zDuration of signal. r  rs  r`   s    r2   r  z&TestSampledSpectralRepresentations.tau  s     vr4   c                 &    d| j         | j        z  z  S )z
Bin width r!   r  r`   s    r2   delta_fz*TestSampledSpectralRepresentations.delta_f  s     DFTVO$$r4   c                    t          d| j        z  t          j        | j                  d           t          | j        t          | j        dz            z  | j                   t          | j        j	        dz  | j        j
        dz  z             }t          | j        | j        z  |z  | j                   t          d| j        dz  z  |z  | j                   dS )z Test energy and power formulas. rf   rK  rN  r!   N)r   r  r(   ptpr  rs  rt  r  r  r  r  r  r  )r-   sum_X_ref_squareds     r2   test_reference_signalz8TestSampledSpectralRepresentations.test_reference_signal  s     	$*bfTZ&8&8sCCCCTZ1_!5!55tzBBB  
 2TZ_a5G GHHtv(994:FFF$&!)&77DDDDDr4   c                    t          | j        d          }t          t          |                    t	          j        t          |j        dz  |j        dz  z                       }}t          | j	        |z            }t          | j        || j                 z  |z  | j        | j        z  dz             t          || j                 |z  | j        dz             | j        | j        z  t          ||z            dz  z  }| j        t          ||z            dz  z  }t          | j        t          |          z  | j                   t          | j        t          |          z  | j                   t%          d| j        z  |dd          }t'          | j	        fddi|\  }}	t'          | j	        fddi|\  }}
t	          j        |	j                  j        }t          |	t          ||z            dz  |t/          |	          z  	           t          |
||t/          |
          z  	           t%          dt1          | j	                  d
d|}t          t3          | j	        fddi|d         |	|t/          |	          z  	           t          t3          | j	        fddi|d         |
|t/          |
          z  	           dS )zVerify spectral representations of windowed DFT.

        Furthermore, the scalings of `periodogram` and `welch` are verified.
        F)symrf   r!   )rM  r   r   rA   rI   rG   rJ   r;   r   r%  Nr   )r   r  ru  rt  r(   rQ  r  r  r   r  r   r  r  r  rs  r  r  r  rs  r   r  rO   r  r  r  r   )r-   r  c_ampc_rmsXwX_ESDX_PSDr  rD  P_magP_psd	float_ress               r2   test_windowed_DFTz4TestSampledSpectralRepresentations.test_windowed_DFT  s   
 U###3q66{{BGC	AFAI0E,F,F$G$GuA 	2dh</%7dh9NQR9RSSS48u,djl;;; 46!CU
OOQ$66R%Z!++s5zz14:>>>s5zz14:>>> QtvXaNNNtzDD:DDD5tzCC9CCC5 HU[))4	s2e8}}a/iE

6JKKKKu9SZZ+?@@@@ <#dj//A<<<<djCC*CCCAF&s5zz1	3 	3 	3 	3djBB)BrBB1Eu&s5zz1	3 	3 	3 	3 	3 	3r4   N)r   r   r   __doc__r  rP   __annotations__rs  r  r  r  r(   ndarrayr  propertyr  r  r  r  r   r4   r2   r  r    s          AsKKKAuOOOE5CLLL::LLLLLL' ' ' U    X % % % % X%
E 
E 
E$3 $3 $3 $3 $3r4   r  )2r   numpyr(   numpy.testingr   r   r   r   r   r   r   r	   r^   scipyr
   scipy._lib._array_apir   	scipy.fftr   r   r   r   scipy.integrater   scipy.signalr   r   r   r   r   r   r   r   scipy.signal.windowsr   scipy.signal._spectral_pyr   ,scipy.signal.tests._scipy_spectral_test_shimr   rH  r   rK  r   r   rz  r  r  r  r>  r  r   r4   r2   <module>r     s"   



    N N N N N N N N N N N N N N N N  * * * * * *       1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 % % % % % %? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? % % % % % % 6 6 6 6 6 6 N M M M M M O O O O O OZ' Z' Z' Z' Z' Z' Z' Z'zE0 E0 E0 E0 E0 E0 E0 E0N
m* m* m* m* m* m* m* m*`       03  3  3  3  3  3  3  3 jg! g! g! g! g! g! g! g!Ty y y y y y y yxX3 X3 X3 X3 X3 X3 X3 X3 X3 X3r4   