18
18
'''
19
19
20
20
21
+ def _stride_repeat (* args , ** kwargs ):
22
+ with pytest .warns (MatplotlibDeprecationWarning ):
23
+ return mlab .stride_repeat (* args , ** kwargs )
24
+
25
+
21
26
class TestStride (object ):
22
27
def get_base (self , x ):
23
28
y = x
@@ -61,26 +66,26 @@ def test_stride_windows_invalid_params(self, n, noverlap):
61
66
def test_stride_repeat_invalid_input_shape (self , shape ):
62
67
x = np .arange (np .prod (shape )).reshape (shape )
63
68
with pytest .raises (ValueError ):
64
- mlab . stride_repeat (x , 5 )
69
+ _stride_repeat (x , 5 )
65
70
66
71
@pytest .mark .parametrize ('axis' , [- 1 , 2 ],
67
72
ids = ['axis less than 0' ,
68
73
'axis greater than input shape' ])
69
74
def test_stride_repeat_invalid_axis (self , axis ):
70
75
x = np .array (0 )
71
76
with pytest .raises (ValueError ):
72
- mlab . stride_repeat (x , 5 , axis = axis )
77
+ _stride_repeat (x , 5 , axis = axis )
73
78
74
79
def test_stride_repeat_n_lt_1_ValueError (self ):
75
80
x = np .arange (10 )
76
81
with pytest .raises (ValueError ):
77
- mlab . stride_repeat (x , 0 )
82
+ _stride_repeat (x , 0 )
78
83
79
84
@pytest .mark .parametrize ('axis' , [0 , 1 ], ids = ['axis0' , 'axis1' ])
80
85
@pytest .mark .parametrize ('n' , [1 , 5 ], ids = ['n1' , 'n5' ])
81
86
def test_stride_repeat (self , n , axis ):
82
87
x = np .arange (10 )
83
- y = mlab . stride_repeat (x , n , axis = axis )
88
+ y = _stride_repeat (x , n , axis = axis )
84
89
85
90
expected_shape = [10 , 10 ]
86
91
expected_shape [axis ] = n
@@ -137,7 +142,7 @@ def test_stride_ensure_integer_type(self):
137
142
# even previous to #3845 could not find any problematic
138
143
# configuration however, let's be sure it's not accidentally
139
144
# introduced
140
- y_strided = mlab . stride_repeat (y , n = 33.815 )
145
+ y_strided = _stride_repeat (y , n = 33.815 )
141
146
assert_array_equal (y_strided , 0.3 )
142
147
143
148
@@ -187,6 +192,11 @@ def test_csv2rec_dates(tempcsv, input, kwargs):
187
192
assert_array_equal (array ['a' ].tolist (), expected )
188
193
189
194
195
+ def _apply_window (* args , ** kwargs ):
196
+ with pytest .warns (MatplotlibDeprecationWarning ):
197
+ return mlab .apply_window (* args , ** kwargs )
198
+
199
+
190
200
class TestWindow (object ):
191
201
def setup (self ):
192
202
np .random .seed (0 )
@@ -238,31 +248,31 @@ def test_apply_window_1D_axis1_ValueError(self):
238
248
x = self .sig_rand
239
249
window = mlab .window_hanning
240
250
with pytest .raises (ValueError ):
241
- mlab . apply_window (x , window , axis = 1 , return_window = False )
251
+ _apply_window (x , window , axis = 1 , return_window = False )
242
252
243
253
def test_apply_window_1D_els_wrongsize_ValueError (self ):
244
254
x = self .sig_rand
245
255
window = mlab .window_hanning (np .ones (x .shape [0 ]- 1 ))
246
256
with pytest .raises (ValueError ):
247
- mlab . apply_window (x , window )
257
+ _apply_window (x , window )
248
258
249
259
def test_apply_window_0D_ValueError (self ):
250
260
x = np .array (0 )
251
261
window = mlab .window_hanning
252
262
with pytest .raises (ValueError ):
253
- mlab . apply_window (x , window , axis = 1 , return_window = False )
263
+ _apply_window (x , window , axis = 1 , return_window = False )
254
264
255
265
def test_apply_window_3D_ValueError (self ):
256
266
x = self .sig_rand [np .newaxis ][np .newaxis ]
257
267
window = mlab .window_hanning
258
268
with pytest .raises (ValueError ):
259
- mlab . apply_window (x , window , axis = 1 , return_window = False )
269
+ _apply_window (x , window , axis = 1 , return_window = False )
260
270
261
271
def test_apply_window_hanning_1D (self ):
262
272
x = self .sig_rand
263
273
window = mlab .window_hanning
264
274
window1 = mlab .window_hanning (np .ones (x .shape [0 ]))
265
- y , window2 = mlab . apply_window (x , window , return_window = True )
275
+ y , window2 = _apply_window (x , window , return_window = True )
266
276
yt = window (x )
267
277
assert yt .shape == y .shape
268
278
assert x .shape == y .shape
@@ -272,7 +282,7 @@ def test_apply_window_hanning_1D(self):
272
282
def test_apply_window_hanning_1D_axis0 (self ):
273
283
x = self .sig_rand
274
284
window = mlab .window_hanning
275
- y = mlab . apply_window (x , window , axis = 0 , return_window = False )
285
+ y = _apply_window (x , window , axis = 0 , return_window = False )
276
286
yt = window (x )
277
287
assert yt .shape == y .shape
278
288
assert x .shape == y .shape
@@ -282,7 +292,7 @@ def test_apply_window_hanning_els_1D_axis0(self):
282
292
x = self .sig_rand
283
293
window = mlab .window_hanning (np .ones (x .shape [0 ]))
284
294
window1 = mlab .window_hanning
285
- y = mlab . apply_window (x , window , axis = 0 , return_window = False )
295
+ y = _apply_window (x , window , axis = 0 , return_window = False )
286
296
yt = window1 (x )
287
297
assert yt .shape == y .shape
288
298
assert x .shape == y .shape
@@ -291,7 +301,7 @@ def test_apply_window_hanning_els_1D_axis0(self):
291
301
def test_apply_window_hanning_2D_axis0 (self ):
292
302
x = np .random .standard_normal ([1000 , 10 ]) + 100.
293
303
window = mlab .window_hanning
294
- y = mlab . apply_window (x , window , axis = 0 , return_window = False )
304
+ y = _apply_window (x , window , axis = 0 , return_window = False )
295
305
yt = np .zeros_like (x )
296
306
for i in range (x .shape [1 ]):
297
307
yt [:, i ] = window (x [:, i ])
@@ -303,7 +313,7 @@ def test_apply_window_hanning_els1_2D_axis0(self):
303
313
x = np .random .standard_normal ([1000 , 10 ]) + 100.
304
314
window = mlab .window_hanning (np .ones (x .shape [0 ]))
305
315
window1 = mlab .window_hanning
306
- y = mlab . apply_window (x , window , axis = 0 , return_window = False )
316
+ y = _apply_window (x , window , axis = 0 , return_window = False )
307
317
yt = np .zeros_like (x )
308
318
for i in range (x .shape [1 ]):
309
319
yt [:, i ] = window1 (x [:, i ])
@@ -315,7 +325,7 @@ def test_apply_window_hanning_els2_2D_axis0(self):
315
325
x = np .random .standard_normal ([1000 , 10 ]) + 100.
316
326
window = mlab .window_hanning
317
327
window1 = mlab .window_hanning (np .ones (x .shape [0 ]))
318
- y , window2 = mlab . apply_window (x , window , axis = 0 , return_window = True )
328
+ y , window2 = _apply_window (x , window , axis = 0 , return_window = True )
319
329
yt = np .zeros_like (x )
320
330
for i in range (x .shape [1 ]):
321
331
yt [:, i ] = window1 * x [:, i ]
@@ -328,8 +338,8 @@ def test_apply_window_hanning_els3_2D_axis0(self):
328
338
x = np .random .standard_normal ([1000 , 10 ]) + 100.
329
339
window = mlab .window_hanning
330
340
window1 = mlab .window_hanning (np .ones (x .shape [0 ]))
331
- y , window2 = mlab . apply_window (x , window , axis = 0 , return_window = True )
332
- yt = mlab . apply_window (x , window1 , axis = 0 , return_window = False )
341
+ y , window2 = _apply_window (x , window , axis = 0 , return_window = True )
342
+ yt = _apply_window (x , window1 , axis = 0 , return_window = False )
333
343
assert yt .shape == y .shape
334
344
assert x .shape == y .shape
335
345
assert_allclose (yt , y , atol = 1e-06 )
@@ -338,7 +348,7 @@ def test_apply_window_hanning_els3_2D_axis0(self):
338
348
def test_apply_window_hanning_2D_axis1 (self ):
339
349
x = np .random .standard_normal ([10 , 1000 ]) + 100.
340
350
window = mlab .window_hanning
341
- y = mlab . apply_window (x , window , axis = 1 , return_window = False )
351
+ y = _apply_window (x , window , axis = 1 , return_window = False )
342
352
yt = np .zeros_like (x )
343
353
for i in range (x .shape [0 ]):
344
354
yt [i , :] = window (x [i , :])
@@ -350,7 +360,7 @@ def test_apply_window_hanning_2D__els1_axis1(self):
350
360
x = np .random .standard_normal ([10 , 1000 ]) + 100.
351
361
window = mlab .window_hanning (np .ones (x .shape [1 ]))
352
362
window1 = mlab .window_hanning
353
- y = mlab . apply_window (x , window , axis = 1 , return_window = False )
363
+ y = _apply_window (x , window , axis = 1 , return_window = False )
354
364
yt = np .zeros_like (x )
355
365
for i in range (x .shape [0 ]):
356
366
yt [i , :] = window1 (x [i , :])
@@ -362,7 +372,7 @@ def test_apply_window_hanning_2D_els2_axis1(self):
362
372
x = np .random .standard_normal ([10 , 1000 ]) + 100.
363
373
window = mlab .window_hanning
364
374
window1 = mlab .window_hanning (np .ones (x .shape [1 ]))
365
- y , window2 = mlab . apply_window (x , window , axis = 1 , return_window = True )
375
+ y , window2 = _apply_window (x , window , axis = 1 , return_window = True )
366
376
yt = np .zeros_like (x )
367
377
for i in range (x .shape [0 ]):
368
378
yt [i , :] = window1 * x [i , :]
@@ -375,8 +385,8 @@ def test_apply_window_hanning_2D_els3_axis1(self):
375
385
x = np .random .standard_normal ([10 , 1000 ]) + 100.
376
386
window = mlab .window_hanning
377
387
window1 = mlab .window_hanning (np .ones (x .shape [1 ]))
378
- y = mlab . apply_window (x , window , axis = 1 , return_window = False )
379
- yt = mlab . apply_window (x , window1 , axis = 1 , return_window = False )
388
+ y = _apply_window (x , window , axis = 1 , return_window = False )
389
+ yt = _apply_window (x , window1 , axis = 1 , return_window = False )
380
390
assert yt .shape == y .shape
381
391
assert x .shape == y .shape
382
392
assert_allclose (yt , y , atol = 1e-06 )
@@ -385,7 +395,7 @@ def test_apply_window_stride_windows_hanning_2D_n13_noverlapn3_axis0(self):
385
395
x = self .sig_rand
386
396
window = mlab .window_hanning
387
397
yi = mlab .stride_windows (x , n = 13 , noverlap = 2 , axis = 0 )
388
- y = mlab . apply_window (yi , window , axis = 0 , return_window = False )
398
+ y = _apply_window (yi , window , axis = 0 , return_window = False )
389
399
yt = self .check_window_apply_repeat (x , window , 13 , 2 )
390
400
assert yt .shape == y .shape
391
401
assert x .shape != y .shape
@@ -395,45 +405,45 @@ def test_apply_window_hanning_2D_stack_axis1(self):
395
405
ydata = np .arange (32 )
396
406
ydata1 = ydata + 5
397
407
ydata2 = ydata + 3.3
398
- ycontrol1 = mlab . apply_window (ydata1 , mlab .window_hanning )
408
+ ycontrol1 = _apply_window (ydata1 , mlab .window_hanning )
399
409
ycontrol2 = mlab .window_hanning (ydata2 )
400
410
ydata = np .vstack ([ydata1 , ydata2 ])
401
411
ycontrol = np .vstack ([ycontrol1 , ycontrol2 ])
402
412
ydata = np .tile (ydata , (20 , 1 ))
403
413
ycontrol = np .tile (ycontrol , (20 , 1 ))
404
- result = mlab . apply_window (ydata , mlab .window_hanning , axis = 1 ,
405
- return_window = False )
414
+ result = _apply_window (ydata , mlab .window_hanning , axis = 1 ,
415
+ return_window = False )
406
416
assert_allclose (ycontrol , result , atol = 1e-08 )
407
417
408
418
def test_apply_window_hanning_2D_stack_windows_axis1 (self ):
409
419
ydata = np .arange (32 )
410
420
ydata1 = ydata + 5
411
421
ydata2 = ydata + 3.3
412
- ycontrol1 = mlab . apply_window (ydata1 , mlab .window_hanning )
422
+ ycontrol1 = _apply_window (ydata1 , mlab .window_hanning )
413
423
ycontrol2 = mlab .window_hanning (ydata2 )
414
424
ydata = np .vstack ([ydata1 , ydata2 ])
415
425
ycontrol = np .vstack ([ycontrol1 , ycontrol2 ])
416
426
ydata = np .tile (ydata , (20 , 1 ))
417
427
ycontrol = np .tile (ycontrol , (20 , 1 ))
418
- result = mlab . apply_window (ydata , mlab .window_hanning , axis = 1 ,
419
- return_window = False )
428
+ result = _apply_window (ydata , mlab .window_hanning , axis = 1 ,
429
+ return_window = False )
420
430
assert_allclose (ycontrol , result , atol = 1e-08 )
421
431
422
432
def test_apply_window_hanning_2D_stack_windows_axis1_unflatten (self ):
423
433
n = 32
424
434
ydata = np .arange (n )
425
435
ydata1 = ydata + 5
426
436
ydata2 = ydata + 3.3
427
- ycontrol1 = mlab . apply_window (ydata1 , mlab .window_hanning )
437
+ ycontrol1 = _apply_window (ydata1 , mlab .window_hanning )
428
438
ycontrol2 = mlab .window_hanning (ydata2 )
429
439
ydata = np .vstack ([ydata1 , ydata2 ])
430
440
ycontrol = np .vstack ([ycontrol1 , ycontrol2 ])
431
441
ydata = np .tile (ydata , (20 , 1 ))
432
442
ycontrol = np .tile (ycontrol , (20 , 1 ))
433
443
ydata = ydata .flatten ()
434
444
ydata1 = mlab .stride_windows (ydata , 32 , noverlap = 0 , axis = 0 )
435
- result = mlab . apply_window (ydata1 , mlab .window_hanning , axis = 0 ,
436
- return_window = False )
445
+ result = _apply_window (ydata1 , mlab .window_hanning , axis = 0 ,
446
+ return_window = False )
437
447
assert_allclose (ycontrol .T , result , atol = 1e-08 )
438
448
439
449
@@ -1546,9 +1556,9 @@ def test_psd_window_hanning(self):
1546
1556
ydata = np .arange (self .NFFT_density )
1547
1557
ydata1 = ydata + 5
1548
1558
ydata2 = ydata + 3.3
1549
- ycontrol1 , windowVals = mlab . apply_window (ydata1 ,
1550
- mlab .window_hanning ,
1551
- return_window = True )
1559
+ ycontrol1 , windowVals = _apply_window (ydata1 ,
1560
+ mlab .window_hanning ,
1561
+ return_window = True )
1552
1562
ycontrol2 = mlab .window_hanning (ydata2 )
1553
1563
ydata = np .vstack ([ydata1 , ydata2 ])
1554
1564
ycontrol = np .vstack ([ycontrol1 , ycontrol2 ])
@@ -1593,9 +1603,9 @@ def test_psd_window_hanning_detrend_linear(self):
1593
1603
ydata2 = ydata + 3.3
1594
1604
ycontrol1 = ycontrol
1595
1605
ycontrol2 = ycontrol
1596
- ycontrol1 , windowVals = mlab . apply_window (ycontrol1 ,
1597
- mlab .window_hanning ,
1598
- return_window = True )
1606
+ ycontrol1 , windowVals = _apply_window (ycontrol1 ,
1607
+ mlab .window_hanning ,
1608
+ return_window = True )
1599
1609
ycontrol2 = mlab .window_hanning (ycontrol2 )
1600
1610
ydata = np .vstack ([ydata1 , ydata2 ])
1601
1611
ycontrol = np .vstack ([ycontrol1 , ycontrol2 ])
0 commit comments