<s> from __future__ import division , print_function , absolute_import <EOL> import warnings <EOL> import numpy as np <EOL> from numpy . testing import assert_raises , assert_approx_equal , assert_ , run_module_suite , TestCase , assert_allclose , assert_array_equal , assert_array_almost_equal_nulp , dec <EOL> from scipy import signal , fftpack <EOL> from scipy . _lib . _version import NumpyVersion <EOL> from scipy . signal import ( periodogram , welch , lombscargle , csd , coherence , <EOL> spectrogram ) <EOL> class TestPeriodogram ( TestCase ) : <EOL> def test_real_onesided_even ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> f , p = periodogram ( x ) <EOL> assert_allclose ( f , np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:9> ) ) <EOL> q = np . ones ( <NUM_LIT:9> ) <EOL> q [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> q [ - <NUM_LIT:1> ] /= <NUM_LIT> <EOL> q /= <NUM_LIT:8> <EOL> assert_allclose ( p , q ) <EOL> def test_real_onesided_odd ( self ) : <EOL> x = np . zeros ( <NUM_LIT:15> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> f , p = periodogram ( x ) <EOL> assert_allclose ( f , np . arange ( <NUM_LIT> ) / <NUM_LIT> ) <EOL> q = np . ones ( <NUM_LIT:8> ) <EOL> q [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> q *= <NUM_LIT> / <NUM_LIT> <EOL> assert_allclose ( p , q , atol = <NUM_LIT> ) <EOL> def test_real_twosided ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> f , p = periodogram ( x , return_onesided = False ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:16> , <NUM_LIT:1.0> ) ) <EOL> q = np . ones ( <NUM_LIT:16> ) / <NUM_LIT> <EOL> q [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> assert_allclose ( p , q ) <EOL> def test_real_spectrum ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> f , p = periodogram ( x , scaling = '<STR_LIT>' ) <EOL> g , q = periodogram ( x , scaling = '<STR_LIT>' ) <EOL> assert_allclose ( f , np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:9> ) ) <EOL> assert_allclose ( p , q / <NUM_LIT> ) <EOL> def test_integer_even ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , dtype = int ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> f , p = periodogram ( x ) <EOL> assert_allclose ( f , np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:9> ) ) <EOL> q = np . ones ( <NUM_LIT:9> ) <EOL> q [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> q [ - <NUM_LIT:1> ] /= <NUM_LIT> <EOL> q /= <NUM_LIT:8> <EOL> assert_allclose ( p , q ) <EOL> def test_integer_odd ( self ) : <EOL> x = np . zeros ( <NUM_LIT:15> , dtype = int ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> f , p = periodogram ( x ) <EOL> assert_allclose ( f , np . arange ( <NUM_LIT> ) / <NUM_LIT> ) <EOL> q = np . ones ( <NUM_LIT:8> ) <EOL> q [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> q *= <NUM_LIT> / <NUM_LIT> <EOL> assert_allclose ( p , q , atol = <NUM_LIT> ) <EOL> def test_integer_twosided ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , dtype = int ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> f , p = periodogram ( x , return_onesided = False ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:16> , <NUM_LIT:1.0> ) ) <EOL> q = np . ones ( <NUM_LIT:16> ) / <NUM_LIT> <EOL> q [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> assert_allclose ( p , q ) <EOL> def test_complex ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , np . complex128 ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1.0> + <NUM_LIT> <EOL> f , p = periodogram ( x ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:16> , <NUM_LIT:1.0> ) ) <EOL> q = <NUM_LIT> * np . ones ( <NUM_LIT:16> ) / <NUM_LIT> <EOL> q [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> assert_allclose ( p , q ) <EOL> def test_unk_scaling ( self ) : <EOL> assert_raises ( ValueError , periodogram , np . zeros ( <NUM_LIT:4> , np . complex128 ) , <EOL> scaling = '<STR_LIT:foo>' ) <EOL> def test_nd_axis_m1 ( self ) : <EOL> x = np . zeros ( <NUM_LIT:20> , dtype = np . float64 ) <EOL> x = x . reshape ( ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:10> ) ) <EOL> x [ : , : , <NUM_LIT:0> ] = <NUM_LIT:1.0> <EOL> f , p = periodogram ( x ) <EOL> assert_array_equal ( p . shape , ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:6> ) ) <EOL> assert_array_almost_equal_nulp ( p [ <NUM_LIT:0> , <NUM_LIT:0> , : ] , p [ <NUM_LIT:1> , <NUM_LIT:0> , : ] , <NUM_LIT> ) <EOL> f0 , p0 = periodogram ( x [ <NUM_LIT:0> , <NUM_LIT:0> , : ] ) <EOL> assert_array_almost_equal_nulp ( p0 [ np . newaxis , : ] , p [ <NUM_LIT:1> , : ] , <NUM_LIT> ) <EOL> def test_nd_axis_0 ( self ) : <EOL> x = np . zeros ( <NUM_LIT:20> , dtype = np . float64 ) <EOL> x = x . reshape ( ( <NUM_LIT:10> , <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> x [ <NUM_LIT:0> , : , : ] = <NUM_LIT:1.0> <EOL> f , p = periodogram ( x , axis = <NUM_LIT:0> ) <EOL> assert_array_equal ( p . shape , ( <NUM_LIT:6> , <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> assert_array_almost_equal_nulp ( p [ : , <NUM_LIT:0> , <NUM_LIT:0> ] , p [ : , <NUM_LIT:1> , <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> f0 , p0 = periodogram ( x [ : , <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> assert_array_almost_equal_nulp ( p0 , p [ : , <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> def test_window_external ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> f , p = periodogram ( x , <NUM_LIT:10> , '<STR_LIT>' ) <EOL> win = signal . get_window ( '<STR_LIT>' , <NUM_LIT:16> ) <EOL> fe , pe = periodogram ( x , <NUM_LIT:10> , win ) <EOL> assert_array_almost_equal_nulp ( p , pe ) <EOL> assert_array_almost_equal_nulp ( f , fe ) <EOL> def test_padded_fft ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> f , p = periodogram ( x ) <EOL> fp , pp = periodogram ( x , nfft = <NUM_LIT:32> ) <EOL> assert_allclose ( f , fp [ : : <NUM_LIT:2> ] ) <EOL> assert_allclose ( p , pp [ : : <NUM_LIT:2> ] ) <EOL> assert_array_equal ( pp . shape , ( <NUM_LIT> , ) ) <EOL> def test_empty_input ( self ) : <EOL> f , p = periodogram ( [ ] ) <EOL> assert_array_equal ( f . shape , ( <NUM_LIT:0> , ) ) <EOL> assert_array_equal ( p . shape , ( <NUM_LIT:0> , ) ) <EOL> for shape in [ ( <NUM_LIT:0> , ) , ( <NUM_LIT:3> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:2> ) ] : <EOL> f , p = periodogram ( np . empty ( shape ) ) <EOL> assert_array_equal ( f . shape , shape ) <EOL> assert_array_equal ( p . shape , shape ) <EOL> def test_empty_input_other_axis ( self ) : <EOL> for shape in [ ( <NUM_LIT:3> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:2> ) ] : <EOL> f , p = periodogram ( np . empty ( shape ) , axis = <NUM_LIT:1> ) <EOL> assert_array_equal ( f . shape , shape ) <EOL> assert_array_equal ( p . shape , shape ) <EOL> def test_short_nfft ( self ) : <EOL> x = np . zeros ( <NUM_LIT> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> f , p = periodogram ( x , nfft = <NUM_LIT:16> ) <EOL> assert_allclose ( f , np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:9> ) ) <EOL> q = np . ones ( <NUM_LIT:9> ) <EOL> q [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> q [ - <NUM_LIT:1> ] /= <NUM_LIT> <EOL> q /= <NUM_LIT:8> <EOL> assert_allclose ( p , q ) <EOL> def test_nfft_is_xshape ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> f , p = periodogram ( x , nfft = <NUM_LIT:16> ) <EOL> assert_allclose ( f , np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:9> ) ) <EOL> q = np . ones ( <NUM_LIT:9> ) <EOL> q [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> q [ - <NUM_LIT:1> ] /= <NUM_LIT> <EOL> q /= <NUM_LIT:8> <EOL> assert_allclose ( p , q ) <EOL> def test_real_onesided_even_32 ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , '<STR_LIT:f>' ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> f , p = periodogram ( x ) <EOL> assert_allclose ( f , np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:9> ) ) <EOL> q = np . ones ( <NUM_LIT:9> , '<STR_LIT:f>' ) <EOL> q [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> q [ - <NUM_LIT:1> ] /= <NUM_LIT> <EOL> q /= <NUM_LIT:8> <EOL> assert_allclose ( p , q ) <EOL> assert_ ( p . dtype == q . dtype ) <EOL> def test_real_onesided_odd_32 ( self ) : <EOL> x = np . zeros ( <NUM_LIT:15> , '<STR_LIT:f>' ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> f , p = periodogram ( x ) <EOL> assert_allclose ( f , np . arange ( <NUM_LIT> ) / <NUM_LIT> ) <EOL> q = np . ones ( <NUM_LIT:8> , '<STR_LIT:f>' ) <EOL> q [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> q *= <NUM_LIT> / <NUM_LIT> <EOL> assert_allclose ( p , q , atol = <NUM_LIT> ) <EOL> assert_ ( p . dtype == q . dtype ) <EOL> @ dec . skipif ( NumpyVersion ( np . __version__ ) < '<STR_LIT>' ) <EOL> def test_real_twosided_32 ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , '<STR_LIT:f>' ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> f , p = periodogram ( x , return_onesided = False ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:16> , <NUM_LIT:1.0> ) ) <EOL> q = np . ones ( <NUM_LIT:16> , '<STR_LIT:f>' ) / <NUM_LIT> <EOL> q [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> assert_allclose ( p , q ) <EOL> assert_ ( p . dtype == q . dtype ) <EOL> @ dec . skipif ( NumpyVersion ( np . __version__ ) < '<STR_LIT>' ) <EOL> def test_complex_32 ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , '<STR_LIT:F>' ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1.0> + <NUM_LIT> <EOL> f , p = periodogram ( x ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:16> , <NUM_LIT:1.0> ) ) <EOL> q = <NUM_LIT> * np . ones ( <NUM_LIT:16> , '<STR_LIT:f>' ) / <NUM_LIT> <EOL> q [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> assert_allclose ( p , q ) <EOL> assert_ ( p . dtype == q . dtype ) <EOL> class TestWelch ( TestCase ) : <EOL> def test_real_onesided_even ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:8> ) <EOL> assert_allclose ( f , np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:5> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_real_onesided_odd ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:9> ) <EOL> assert_allclose ( f , np . arange ( <NUM_LIT> ) / <NUM_LIT> ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_real_twosided ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:8> , return_onesided = False ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:8> , <NUM_LIT:1.0> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_real_spectrum ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:8> , scaling = '<STR_LIT>' ) <EOL> assert_allclose ( f , np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:5> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_integer_onesided_even ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , dtype = int ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:8> ) <EOL> assert_allclose ( f , np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:5> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_integer_onesided_odd ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , dtype = int ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:9> ) <EOL> assert_allclose ( f , np . arange ( <NUM_LIT> ) / <NUM_LIT> ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_integer_twosided ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , dtype = int ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:8> , return_onesided = False ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:8> , <NUM_LIT:1.0> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_complex ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , np . complex128 ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1.0> + <NUM_LIT> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1.0> + <NUM_LIT> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:8> ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:8> , <NUM_LIT:1.0> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_unk_scaling ( self ) : <EOL> assert_raises ( ValueError , welch , np . zeros ( <NUM_LIT:4> , np . complex128 ) , <EOL> scaling = '<STR_LIT:foo>' , nperseg = <NUM_LIT:4> ) <EOL> def test_detrend_linear ( self ) : <EOL> x = np . arange ( <NUM_LIT:10> , dtype = np . float64 ) + <NUM_LIT> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:10> , detrend = '<STR_LIT>' ) <EOL> assert_allclose ( p , np . zeros_like ( p ) , atol = <NUM_LIT> ) <EOL> def test_no_detrending ( self ) : <EOL> x = np . arange ( <NUM_LIT:10> , dtype = np . float64 ) + <NUM_LIT> <EOL> f1 , p1 = welch ( x , nperseg = <NUM_LIT:10> , detrend = False ) <EOL> f2 , p2 = welch ( x , nperseg = <NUM_LIT:10> , detrend = lambda x : x ) <EOL> assert_allclose ( f1 , f2 , atol = <NUM_LIT> ) <EOL> assert_allclose ( p1 , p2 , atol = <NUM_LIT> ) <EOL> def test_detrend_external ( self ) : <EOL> x = np . arange ( <NUM_LIT:10> , dtype = np . float64 ) + <NUM_LIT> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:10> , <EOL> detrend = lambda seg : signal . detrend ( seg , type = '<STR_LIT:l>' ) ) <EOL> assert_allclose ( p , np . zeros_like ( p ) , atol = <NUM_LIT> ) <EOL> def test_detrend_external_nd_m1 ( self ) : <EOL> x = np . arange ( <NUM_LIT> , dtype = np . float64 ) + <NUM_LIT> <EOL> x = x . reshape ( ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:10> ) ) <EOL> f , p = welch ( x , nperseg = <NUM_LIT:10> , <EOL> detrend = lambda seg : signal . detrend ( seg , type = '<STR_LIT:l>' ) ) <EOL> assert_allclose ( p , np . zeros_like ( p ) , atol = <NUM_LIT> ) <EOL> def test_detrend_external_nd_0 ( self ) : <EOL> x = np . arange ( <NUM_LIT:20> , dtype = np . float64 ) + <NUM_LIT> <EOL> x = x . reshape ( ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:10> ) ) <EOL> x = np . rollaxis ( x , <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> f , p = welch ( x , nperseg = <NUM_LIT:10> , axis = <NUM_LIT:0> , <EOL> detrend = lambda seg : signal . detrend ( seg , axis = <NUM_LIT:0> , type = '<STR_LIT:l>' ) ) <EOL> assert_allclose ( p , np . zeros_like ( p ) , atol = <NUM_LIT> ) <EOL> def test_nd_axis_m1 ( self ) : <EOL> x = np . arange ( <NUM_LIT:20> , dtype = np . float64 ) + <NUM_LIT> <EOL> x = x . reshape ( ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:10> ) ) <EOL> f , p = welch ( x , nperseg = <NUM_LIT:10> ) <EOL> assert_array_equal ( p . shape , ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:6> ) ) <EOL> assert_allclose ( p [ <NUM_LIT:0> , <NUM_LIT:0> , : ] , p [ <NUM_LIT:1> , <NUM_LIT:0> , : ] , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> f0 , p0 = welch ( x [ <NUM_LIT:0> , <NUM_LIT:0> , : ] , nperseg = <NUM_LIT:10> ) <EOL> assert_allclose ( p0 [ np . newaxis , : ] , p [ <NUM_LIT:1> , : ] , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_nd_axis_0 ( self ) : <EOL> x = np . arange ( <NUM_LIT:20> , dtype = np . float64 ) + <NUM_LIT> <EOL> x = x . reshape ( ( <NUM_LIT:10> , <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> f , p = welch ( x , nperseg = <NUM_LIT:10> , axis = <NUM_LIT:0> ) <EOL> assert_array_equal ( p . shape , ( <NUM_LIT:6> , <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> assert_allclose ( p [ : , <NUM_LIT:0> , <NUM_LIT:0> ] , p [ : , <NUM_LIT:1> , <NUM_LIT:0> ] , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> f0 , p0 = welch ( x [ : , <NUM_LIT:0> , <NUM_LIT:0> ] , nperseg = <NUM_LIT:10> ) <EOL> assert_allclose ( p0 , p [ : , <NUM_LIT:1> , <NUM_LIT:0> ] , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_window_external ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = welch ( x , <NUM_LIT:10> , '<STR_LIT>' , <NUM_LIT:8> ) <EOL> win = signal . get_window ( '<STR_LIT>' , <NUM_LIT:8> ) <EOL> fe , pe = welch ( x , <NUM_LIT:10> , win , <NUM_LIT:8> ) <EOL> assert_array_almost_equal_nulp ( p , pe ) <EOL> assert_array_almost_equal_nulp ( f , fe ) <EOL> def test_empty_input ( self ) : <EOL> f , p = welch ( [ ] ) <EOL> assert_array_equal ( f . shape , ( <NUM_LIT:0> , ) ) <EOL> assert_array_equal ( p . shape , ( <NUM_LIT:0> , ) ) <EOL> for shape in [ ( <NUM_LIT:0> , ) , ( <NUM_LIT:3> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:2> ) ] : <EOL> f , p = welch ( np . empty ( shape ) ) <EOL> assert_array_equal ( f . shape , shape ) <EOL> assert_array_equal ( p . shape , shape ) <EOL> def test_empty_input_other_axis ( self ) : <EOL> for shape in [ ( <NUM_LIT:3> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:2> ) ] : <EOL> f , p = welch ( np . empty ( shape ) , axis = <NUM_LIT:1> ) <EOL> assert_array_equal ( f . shape , shape ) <EOL> assert_array_equal ( p . shape , shape ) <EOL> def test_short_data ( self ) : <EOL> x = np . zeros ( <NUM_LIT:8> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> with warnings . catch_warnings ( ) : <EOL> warnings . simplefilter ( '<STR_LIT:ignore>' , UserWarning ) <EOL> f , p = welch ( x ) <EOL> f1 , p1 = welch ( x , nperseg = <NUM_LIT:8> ) <EOL> assert_allclose ( f , f1 ) <EOL> assert_allclose ( p , p1 ) <EOL> def test_window_long_or_nd ( self ) : <EOL> with warnings . catch_warnings ( ) : <EOL> warnings . simplefilter ( '<STR_LIT:ignore>' , UserWarning ) <EOL> assert_raises ( ValueError , welch , np . zeros ( <NUM_LIT:4> ) , <NUM_LIT:1> , <EOL> np . array ( [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] ) ) <EOL> assert_raises ( ValueError , welch , np . zeros ( <NUM_LIT:4> ) , <NUM_LIT:1> , <EOL> np . arange ( <NUM_LIT:6> ) . reshape ( ( <NUM_LIT:2> , <NUM_LIT:3> ) ) ) <EOL> def test_nondefault_noverlap ( self ) : <EOL> x = np . zeros ( <NUM_LIT:64> ) <EOL> x [ : : <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:16> , noverlap = <NUM_LIT:4> ) <EOL> q = np . array ( [ <NUM_LIT:0> , <NUM_LIT:1.> / <NUM_LIT> , <NUM_LIT:1.> / <NUM_LIT> , <NUM_LIT:1.> / <NUM_LIT> , <NUM_LIT:1.> / <NUM_LIT> , <NUM_LIT:1.> / <NUM_LIT> , <NUM_LIT:1.> / <NUM_LIT> , <NUM_LIT:1.> / <NUM_LIT> , <EOL> <NUM_LIT:1.> / <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> ) <EOL> def test_bad_noverlap ( self ) : <EOL> assert_raises ( ValueError , welch , np . zeros ( <NUM_LIT:4> ) , <NUM_LIT:1> , '<STR_LIT>' , <NUM_LIT:2> , <NUM_LIT:7> ) <EOL> def test_nfft_too_short ( self ) : <EOL> assert_raises ( ValueError , welch , np . ones ( <NUM_LIT:12> ) , nfft = <NUM_LIT:3> , nperseg = <NUM_LIT:4> ) <EOL> def test_real_onesided_even_32 ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , '<STR_LIT:f>' ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:8> ) <EOL> assert_allclose ( f , np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:5> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] , '<STR_LIT:f>' ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> assert_ ( p . dtype == q . dtype ) <EOL> def test_real_onesided_odd_32 ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , '<STR_LIT:f>' ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:9> ) <EOL> assert_allclose ( f , np . arange ( <NUM_LIT> ) / <NUM_LIT> ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] , '<STR_LIT:f>' ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> assert_ ( p . dtype == q . dtype ) <EOL> @ dec . skipif ( NumpyVersion ( np . __version__ ) < '<STR_LIT>' ) <EOL> def test_real_twosided_32 ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , '<STR_LIT:f>' ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:8> , return_onesided = False ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:8> , <NUM_LIT:1.0> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] , '<STR_LIT:f>' ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> assert_ ( p . dtype == q . dtype ) <EOL> @ dec . skipif ( NumpyVersion ( np . __version__ ) < '<STR_LIT>' ) <EOL> def test_complex_32 ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , '<STR_LIT:F>' ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1.0> + <NUM_LIT> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1.0> + <NUM_LIT> <EOL> f , p = welch ( x , nperseg = <NUM_LIT:8> ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:8> , <NUM_LIT:1.0> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , '<STR_LIT:f>' ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> assert_ ( p . dtype == q . dtype , <EOL> '<STR_LIT>' % ( p . dtype , q . dtype ) ) <EOL> def test_padded_freqs ( self ) : <EOL> x = np . zeros ( <NUM_LIT:12> ) <EOL> nfft = <NUM_LIT> <EOL> f = fftpack . fftfreq ( nfft , <NUM_LIT:1.0> ) [ : nfft // <NUM_LIT:2> + <NUM_LIT:1> ] <EOL> f [ - <NUM_LIT:1> ] *= - <NUM_LIT:1> <EOL> fodd , _ = welch ( x , nperseg = <NUM_LIT:5> , nfft = nfft ) <EOL> feven , _ = welch ( x , nperseg = <NUM_LIT:6> , nfft = nfft ) <EOL> assert_allclose ( f , fodd ) <EOL> assert_allclose ( f , feven ) <EOL> nfft = <NUM_LIT> <EOL> f = fftpack . fftfreq ( nfft , <NUM_LIT:1.0> ) [ : ( nfft + <NUM_LIT:1> ) // <NUM_LIT:2> ] <EOL> fodd , _ = welch ( x , nperseg = <NUM_LIT:5> , nfft = nfft ) <EOL> feven , _ = welch ( x , nperseg = <NUM_LIT:6> , nfft = nfft ) <EOL> assert_allclose ( f , fodd ) <EOL> assert_allclose ( f , feven ) <EOL> class TestCSD : <EOL> def test_pad_shorter_x ( self ) : <EOL> x = np . zeros ( <NUM_LIT:8> ) <EOL> y = np . zeros ( <NUM_LIT:12> ) <EOL> f = np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:7> ) <EOL> c = np . zeros ( <NUM_LIT:7> , dtype = np . complex128 ) <EOL> f1 , c1 = csd ( x , y , nperseg = <NUM_LIT:12> ) <EOL> assert_allclose ( f , f1 ) <EOL> assert_allclose ( c , c1 ) <EOL> def test_pad_shorter_y ( self ) : <EOL> x = np . zeros ( <NUM_LIT:12> ) <EOL> y = np . zeros ( <NUM_LIT:8> ) <EOL> f = np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:7> ) <EOL> c = np . zeros ( <NUM_LIT:7> , dtype = np . complex128 ) <EOL> f1 , c1 = csd ( x , y , nperseg = <NUM_LIT:12> ) <EOL> assert_allclose ( f , f1 ) <EOL> assert_allclose ( c , c1 ) <EOL> def test_real_onesided_even ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:8> ) <EOL> assert_allclose ( f , np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:5> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_real_onesided_odd ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:9> ) <EOL> assert_allclose ( f , np . arange ( <NUM_LIT> ) / <NUM_LIT> ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_real_twosided ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:8> , return_onesided = False ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:8> , <NUM_LIT:1.0> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_real_spectrum ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:8> , scaling = '<STR_LIT>' ) <EOL> assert_allclose ( f , np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:5> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_integer_onesided_even ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , dtype = int ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:8> ) <EOL> assert_allclose ( f , np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:5> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_integer_onesided_odd ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , dtype = int ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:9> ) <EOL> assert_allclose ( f , np . arange ( <NUM_LIT> ) / <NUM_LIT> ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_integer_twosided ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , dtype = int ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:8> , return_onesided = False ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:8> , <NUM_LIT:1.0> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_complex ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , np . complex128 ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1.0> + <NUM_LIT> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1.0> + <NUM_LIT> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:8> ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:8> , <NUM_LIT:1.0> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_unk_scaling ( self ) : <EOL> assert_raises ( ValueError , csd , np . zeros ( <NUM_LIT:4> , np . complex128 ) , <EOL> np . ones ( <NUM_LIT:4> , np . complex128 ) , scaling = '<STR_LIT:foo>' , nperseg = <NUM_LIT:4> ) <EOL> def test_detrend_linear ( self ) : <EOL> x = np . arange ( <NUM_LIT:10> , dtype = np . float64 ) + <NUM_LIT> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:10> , detrend = '<STR_LIT>' ) <EOL> assert_allclose ( p , np . zeros_like ( p ) , atol = <NUM_LIT> ) <EOL> def test_no_detrending ( self ) : <EOL> x = np . arange ( <NUM_LIT:10> , dtype = np . float64 ) + <NUM_LIT> <EOL> f1 , p1 = csd ( x , x , nperseg = <NUM_LIT:10> , detrend = False ) <EOL> f2 , p2 = csd ( x , x , nperseg = <NUM_LIT:10> , detrend = lambda x : x ) <EOL> assert_allclose ( f1 , f2 , atol = <NUM_LIT> ) <EOL> assert_allclose ( p1 , p2 , atol = <NUM_LIT> ) <EOL> def test_detrend_external ( self ) : <EOL> x = np . arange ( <NUM_LIT:10> , dtype = np . float64 ) + <NUM_LIT> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:10> , <EOL> detrend = lambda seg : signal . detrend ( seg , type = '<STR_LIT:l>' ) ) <EOL> assert_allclose ( p , np . zeros_like ( p ) , atol = <NUM_LIT> ) <EOL> def test_detrend_external_nd_m1 ( self ) : <EOL> x = np . arange ( <NUM_LIT> , dtype = np . float64 ) + <NUM_LIT> <EOL> x = x . reshape ( ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:10> ) ) <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:10> , <EOL> detrend = lambda seg : signal . detrend ( seg , type = '<STR_LIT:l>' ) ) <EOL> assert_allclose ( p , np . zeros_like ( p ) , atol = <NUM_LIT> ) <EOL> def test_detrend_external_nd_0 ( self ) : <EOL> x = np . arange ( <NUM_LIT:20> , dtype = np . float64 ) + <NUM_LIT> <EOL> x = x . reshape ( ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:10> ) ) <EOL> x = np . rollaxis ( x , <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:10> , axis = <NUM_LIT:0> , <EOL> detrend = lambda seg : signal . detrend ( seg , axis = <NUM_LIT:0> , type = '<STR_LIT:l>' ) ) <EOL> assert_allclose ( p , np . zeros_like ( p ) , atol = <NUM_LIT> ) <EOL> def test_nd_axis_m1 ( self ) : <EOL> x = np . arange ( <NUM_LIT:20> , dtype = np . float64 ) + <NUM_LIT> <EOL> x = x . reshape ( ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:10> ) ) <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:10> ) <EOL> assert_array_equal ( p . shape , ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:6> ) ) <EOL> assert_allclose ( p [ <NUM_LIT:0> , <NUM_LIT:0> , : ] , p [ <NUM_LIT:1> , <NUM_LIT:0> , : ] , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> f0 , p0 = csd ( x [ <NUM_LIT:0> , <NUM_LIT:0> , : ] , x [ <NUM_LIT:0> , <NUM_LIT:0> , : ] , nperseg = <NUM_LIT:10> ) <EOL> assert_allclose ( p0 [ np . newaxis , : ] , p [ <NUM_LIT:1> , : ] , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_nd_axis_0 ( self ) : <EOL> x = np . arange ( <NUM_LIT:20> , dtype = np . float64 ) + <NUM_LIT> <EOL> x = x . reshape ( ( <NUM_LIT:10> , <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:10> , axis = <NUM_LIT:0> ) <EOL> assert_array_equal ( p . shape , ( <NUM_LIT:6> , <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> assert_allclose ( p [ : , <NUM_LIT:0> , <NUM_LIT:0> ] , p [ : , <NUM_LIT:1> , <NUM_LIT:0> ] , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> f0 , p0 = csd ( x [ : , <NUM_LIT:0> , <NUM_LIT:0> ] , x [ : , <NUM_LIT:0> , <NUM_LIT:0> ] , nperseg = <NUM_LIT:10> ) <EOL> assert_allclose ( p0 , p [ : , <NUM_LIT:1> , <NUM_LIT:0> ] , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> def test_window_external ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = csd ( x , x , <NUM_LIT:10> , '<STR_LIT>' , <NUM_LIT:8> ) <EOL> win = signal . get_window ( '<STR_LIT>' , <NUM_LIT:8> ) <EOL> fe , pe = csd ( x , x , <NUM_LIT:10> , win , <NUM_LIT:8> ) <EOL> assert_array_almost_equal_nulp ( p , pe ) <EOL> assert_array_almost_equal_nulp ( f , fe ) <EOL> def test_empty_input ( self ) : <EOL> f , p = csd ( [ ] , np . zeros ( <NUM_LIT:10> ) ) <EOL> assert_array_equal ( f . shape , ( <NUM_LIT:0> , ) ) <EOL> assert_array_equal ( p . shape , ( <NUM_LIT:0> , ) ) <EOL> f , p = csd ( np . zeros ( <NUM_LIT:10> ) , [ ] ) <EOL> assert_array_equal ( f . shape , ( <NUM_LIT:0> , ) ) <EOL> assert_array_equal ( p . shape , ( <NUM_LIT:0> , ) ) <EOL> for shape in [ ( <NUM_LIT:0> , ) , ( <NUM_LIT:3> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:2> ) ] : <EOL> f , p = csd ( np . empty ( shape ) , np . empty ( shape ) ) <EOL> assert_array_equal ( f . shape , shape ) <EOL> assert_array_equal ( p . shape , shape ) <EOL> f , p = csd ( np . ones ( <NUM_LIT:10> ) , np . empty ( ( <NUM_LIT:5> , <NUM_LIT:0> ) ) ) <EOL> assert_array_equal ( f . shape , ( <NUM_LIT:5> , <NUM_LIT:0> ) ) <EOL> assert_array_equal ( p . shape , ( <NUM_LIT:5> , <NUM_LIT:0> ) ) <EOL> f , p = csd ( np . empty ( ( <NUM_LIT:5> , <NUM_LIT:0> ) ) , np . ones ( <NUM_LIT:10> ) ) <EOL> assert_array_equal ( f . shape , ( <NUM_LIT:5> , <NUM_LIT:0> ) ) <EOL> assert_array_equal ( p . shape , ( <NUM_LIT:5> , <NUM_LIT:0> ) ) <EOL> def test_empty_input_other_axis ( self ) : <EOL> for shape in [ ( <NUM_LIT:3> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:2> ) ] : <EOL> f , p = csd ( np . empty ( shape ) , np . empty ( shape ) , axis = <NUM_LIT:1> ) <EOL> assert_array_equal ( f . shape , shape ) <EOL> assert_array_equal ( p . shape , shape ) <EOL> f , p = csd ( np . empty ( ( <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:3> ) ) , np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:1> ) ) , axis = <NUM_LIT:1> ) <EOL> assert_array_equal ( f . shape , ( <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:3> ) ) <EOL> assert_array_equal ( p . shape , ( <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:3> ) ) <EOL> f , p = csd ( np . empty ( ( <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:1> ) ) , np . zeros ( ( <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:3> ) ) , axis = <NUM_LIT:1> ) <EOL> assert_array_equal ( f . shape , ( <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:3> ) ) <EOL> assert_array_equal ( p . shape , ( <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:3> ) ) <EOL> def test_short_data ( self ) : <EOL> x = np . zeros ( <NUM_LIT:8> ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> with warnings . catch_warnings ( ) : <EOL> warnings . simplefilter ( '<STR_LIT:ignore>' , UserWarning ) <EOL> f , p = csd ( x , x ) <EOL> f1 , p1 = csd ( x , x , nperseg = <NUM_LIT:8> ) <EOL> assert_allclose ( f , f1 ) <EOL> assert_allclose ( p , p1 ) <EOL> def test_window_long_or_nd ( self ) : <EOL> with warnings . catch_warnings ( ) : <EOL> warnings . simplefilter ( '<STR_LIT:ignore>' , UserWarning ) <EOL> assert_raises ( ValueError , csd , np . zeros ( <NUM_LIT:4> ) , np . ones ( <NUM_LIT:4> ) , <NUM_LIT:1> , <EOL> np . array ( [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] ) ) <EOL> assert_raises ( ValueError , csd , np . zeros ( <NUM_LIT:4> ) , np . ones ( <NUM_LIT:4> ) , <NUM_LIT:1> , <EOL> np . arange ( <NUM_LIT:6> ) . reshape ( ( <NUM_LIT:2> , <NUM_LIT:3> ) ) ) <EOL> def test_nondefault_noverlap ( self ) : <EOL> x = np . zeros ( <NUM_LIT:64> ) <EOL> x [ : : <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:16> , noverlap = <NUM_LIT:4> ) <EOL> q = np . array ( [ <NUM_LIT:0> , <NUM_LIT:1.> / <NUM_LIT> , <NUM_LIT:1.> / <NUM_LIT> , <NUM_LIT:1.> / <NUM_LIT> , <NUM_LIT:1.> / <NUM_LIT> , <NUM_LIT:1.> / <NUM_LIT> , <NUM_LIT:1.> / <NUM_LIT> , <NUM_LIT:1.> / <NUM_LIT> , <EOL> <NUM_LIT:1.> / <NUM_LIT> ] ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> ) <EOL> def test_bad_noverlap ( self ) : <EOL> assert_raises ( ValueError , csd , np . zeros ( <NUM_LIT:4> ) , np . ones ( <NUM_LIT:4> ) , <NUM_LIT:1> , '<STR_LIT>' , <EOL> <NUM_LIT:2> , <NUM_LIT:7> ) <EOL> def test_nfft_too_short ( self ) : <EOL> assert_raises ( ValueError , csd , np . ones ( <NUM_LIT:12> ) , np . zeros ( <NUM_LIT:12> ) , nfft = <NUM_LIT:3> , <EOL> nperseg = <NUM_LIT:4> ) <EOL> def test_real_onesided_even_32 ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , '<STR_LIT:f>' ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:8> ) <EOL> assert_allclose ( f , np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:5> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] , '<STR_LIT:f>' ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> assert_ ( p . dtype == q . dtype ) <EOL> def test_real_onesided_odd_32 ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , '<STR_LIT:f>' ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:9> ) <EOL> assert_allclose ( f , np . arange ( <NUM_LIT> ) / <NUM_LIT> ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] , '<STR_LIT:f>' ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> assert_ ( p . dtype == q . dtype ) <EOL> @ dec . skipif ( NumpyVersion ( np . __version__ ) < '<STR_LIT>' ) <EOL> def test_real_twosided_32 ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , '<STR_LIT:f>' ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:8> , return_onesided = False ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:8> , <NUM_LIT:1.0> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] , '<STR_LIT:f>' ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> assert_ ( p . dtype == q . dtype ) <EOL> @ dec . skipif ( NumpyVersion ( np . __version__ ) < '<STR_LIT>' ) <EOL> def test_complex_32 ( self ) : <EOL> x = np . zeros ( <NUM_LIT:16> , '<STR_LIT:F>' ) <EOL> x [ <NUM_LIT:0> ] = <NUM_LIT:1.0> + <NUM_LIT> <EOL> x [ <NUM_LIT:8> ] = <NUM_LIT:1.0> + <NUM_LIT> <EOL> f , p = csd ( x , x , nperseg = <NUM_LIT:8> ) <EOL> assert_allclose ( f , fftpack . fftfreq ( <NUM_LIT:8> , <NUM_LIT:1.0> ) ) <EOL> q = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , '<STR_LIT:f>' ) <EOL> assert_allclose ( p , q , atol = <NUM_LIT> , rtol = <NUM_LIT> ) <EOL> assert_ ( p . dtype == q . dtype , <EOL> '<STR_LIT>' % ( p . dtype , q . dtype ) ) <EOL> def test_padded_freqs ( self ) : <EOL> x = np . zeros ( <NUM_LIT:12> ) <EOL> y = np . ones ( <NUM_LIT:12> ) <EOL> nfft = <NUM_LIT> <EOL> f = fftpack . fftfreq ( nfft , <NUM_LIT:1.0> ) [ : nfft // <NUM_LIT:2> + <NUM_LIT:1> ] <EOL> f [ - <NUM_LIT:1> ] *= - <NUM_LIT:1> <EOL> fodd , _ = csd ( x , y , nperseg = <NUM_LIT:5> , nfft = nfft ) <EOL> feven , _ = csd ( x , y , nperseg = <NUM_LIT:6> , nfft = nfft ) <EOL> assert_allclose ( f , fodd ) <EOL> assert_allclose ( f , feven ) <EOL> nfft = <NUM_LIT> <EOL> f = fftpack . fftfreq ( nfft , <NUM_LIT:1.0> ) [ : ( nfft + <NUM_LIT:1> ) // <NUM_LIT:2> ] <EOL> fodd , _ = csd ( x , y , nperseg = <NUM_LIT:5> , nfft = nfft ) <EOL> feven , _ = csd ( x , y , nperseg = <NUM_LIT:6> , nfft = nfft ) <EOL> assert_allclose ( f , fodd ) <EOL> assert_allclose ( f , feven ) <EOL> class TestCoherence : <EOL> def test_identical_input ( self ) : <EOL> x = np . random . randn ( <NUM_LIT:20> ) <EOL> y = np . copy ( x ) <EOL> f = np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:6> ) <EOL> C = np . ones ( <NUM_LIT:6> ) <EOL> f1 , C1 = coherence ( x , y , nperseg = <NUM_LIT:10> ) <EOL> assert_allclose ( f , f1 ) <EOL> assert_allclose ( C , C1 ) <EOL> def test_phase_shifted_input ( self ) : <EOL> x = np . random . randn ( <NUM_LIT:20> ) <EOL> y = - x <EOL> f = np . linspace ( <NUM_LIT:0> , <NUM_LIT:0.5> , <NUM_LIT:6> ) <EOL> C = np . ones ( <NUM_LIT:6> ) <EOL> f1 , C1 = coherence ( x , y , nperseg = <NUM_LIT:10> ) <EOL> assert_allclose ( f , f1 ) <EOL> assert_allclose ( C , C1 ) <EOL> class TestSpectrogram : <EOL> def test_average_all_segments ( self ) : <EOL> x = np . random . randn ( <NUM_LIT> ) <EOL> fs = <NUM_LIT:1.0> <EOL> window = ( '<STR_LIT>' , <NUM_LIT> ) <EOL> nperseg = <NUM_LIT:16> <EOL> noverlap = <NUM_LIT:2> <EOL> f , _ , P = spectrogram ( x , fs , window , nperseg , noverlap ) <EOL> fw , Pw = welch ( x , fs , window , nperseg , noverlap ) <EOL> assert_allclose ( f , fw ) <EOL> assert_allclose ( np . mean ( P , axis = - <NUM_LIT:1> ) , Pw ) <EOL> class TestLombscargle : <EOL> def test_frequency ( self ) : <EOL> """<STR_LIT>""" <EOL> ampl = <NUM_LIT> <EOL> w = <NUM_LIT:1.> <EOL> phi = <NUM_LIT:0.5> * np . pi <EOL> nin = <NUM_LIT:100> <EOL> nout = <NUM_LIT:1000> <EOL> p = <NUM_LIT> <EOL> np . random . seed ( <NUM_LIT> ) <EOL> r = np . random . rand ( nin ) <EOL> t = np . linspace ( <NUM_LIT> * np . pi , <NUM_LIT> * np . pi , nin ) [ r >= p ] <EOL> x = ampl * np . sin ( w * t + phi ) <EOL> f = np . linspace ( <NUM_LIT> , <NUM_LIT> , nout ) <EOL> P = lombscargle ( t , x , f ) <EOL> delta = f [ <NUM_LIT:1> ] - f [ <NUM_LIT:0> ] <EOL> assert_ ( w - f [ np . argmax ( P ) ] < ( delta / <NUM_LIT> ) ) <EOL> def test_amplitude ( self ) : <EOL> """<STR_LIT>""" <EOL> ampl = <NUM_LIT> <EOL> w = <NUM_LIT:1.> <EOL> phi = <NUM_LIT:0.5> * np . pi <EOL> nin = <NUM_LIT:100> <EOL> nout = <NUM_LIT:1000> <EOL> p = <NUM_LIT> <EOL> np . random . seed ( <NUM_LIT> ) <EOL> r = np . random . rand ( nin ) <EOL> t = np . linspace ( <NUM_LIT> * np . pi , <NUM_LIT> * np . pi , nin ) [ r >= p ] <EOL> x = ampl * np . sin ( w * t + phi ) <EOL> f = np . linspace ( <NUM_LIT> , <NUM_LIT> , nout ) <EOL> pgram = lombscargle ( t , x , f ) <EOL> pgram = np . sqrt ( <NUM_LIT:4> * pgram / t . shape [ <NUM_LIT:0> ] ) <EOL> assert_approx_equal ( np . max ( pgram ) , ampl , significant = <NUM_LIT:2> ) <EOL> def test_wrong_shape ( self ) : <EOL> t = np . linspace ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> x = np . linspace ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> f = np . linspace ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> assert_raises ( ValueError , lombscargle , t , x , f ) <EOL> def test_zero_division ( self ) : <EOL> t = np . zeros ( <NUM_LIT:1> ) <EOL> x = np . zeros ( <NUM_LIT:1> ) <EOL> f = np . zeros ( <NUM_LIT:1> ) <EOL> assert_raises ( ZeroDivisionError , lombscargle , t , x , f ) <EOL> def test_lombscargle_atan_vs_atan2 ( self ) : <EOL> t = np . linspace ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:1000> , endpoint = False ) <EOL> x = np . sin ( <NUM_LIT:4> * t ) <EOL> f = np . linspace ( <NUM_LIT:0> , <NUM_LIT:50> , <NUM_LIT> , endpoint = False ) + <NUM_LIT:0.1> <EOL> q = lombscargle ( t , x , f * <NUM_LIT:2> * np . pi ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> run_module_suite ( ) </s>
