Skip to content
This repository

Spectral plot unit tests #1906

Merged
merged 3 commits into from 12 months ago

4 participants

toddrjen Michael Droettboom Damon McDougall Phil Elson
toddrjen

Unit tests for the spectral plot types (specgram, psd, and csd) and corresponding mlab functions.

Michael Droettboom
Owner

Very nice and much needed pull request.

I wonder, however, whether we need to test all three of png, pdf and svg for these. The pdf and svg files in particular are quite large. (Yes, I know our test suite already has some files of that size, but all the more reason to avoid expanding further... :wink:). Maybe we should test PNG only (as those are the smallest files), unless there is some known bug that shows up only with the other formats. Note, we currently do this for the delaunay triangulation tests for the same reason.

Damon McDougall
Collaborator

Yes. Also, there still appears to be some text on some of the output files.

toddrjen

I've restricted it to only pngs and removed the text from the images

toddrjen

Fixed for python 2.6

Phil Elson
Collaborator

:+1:

Michael Droettboom
Owner

Looks good -- and thanks for amending the commit so the PDFs and SVGs don't make it into the history.

Merging.

Michael Droettboom mdboom merged commit f39cdb6 into from
Michael Droettboom mdboom closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
BIN  lib/matplotlib/tests/baseline_images/test_axes/csd_freqs.png
BIN  lib/matplotlib/tests/baseline_images/test_axes/csd_noise.png
BIN  lib/matplotlib/tests/baseline_images/test_axes/psd_freqs.png
BIN  lib/matplotlib/tests/baseline_images/test_axes/psd_noise.png
BIN  lib/matplotlib/tests/baseline_images/test_axes/specgram_freqs.png
BIN  lib/matplotlib/tests/baseline_images/test_axes/specgram_noise.png
218  lib/matplotlib/tests/test_axes.py
@@ -1280,6 +1280,224 @@ def test_mixed_collection():
1280 1280
     ax.set_ylim(0, 16)
1281 1281
 
1282 1282
 
  1283
+@image_comparison(baseline_images=['specgram_freqs'], remove_text=True,
  1284
+                  extensions=['png'])
  1285
+def test_specgram_freqs():
  1286
+    n = 10000
  1287
+    Fs = 100.
  1288
+
  1289
+    fstims1 = [Fs/4, Fs/5, Fs/11]
  1290
+    fstims2 = [Fs/4.7, Fs/5.6, Fs/11.9]
  1291
+
  1292
+    NFFT = int(1000 * Fs / min(fstims1 + fstims2))
  1293
+    noverlap = int(NFFT / 2)
  1294
+    pad_to = int(2 ** np.ceil(np.log2(NFFT)))
  1295
+
  1296
+    x = np.arange(0, n, 1/Fs)
  1297
+
  1298
+    y1 = np.zeros(x.size)
  1299
+    y2 = np.zeros(x.size)
  1300
+    for fstim1, fstim2 in zip(fstims1, fstims2):
  1301
+        y1 += np.sin(fstim1 * x * np.pi * 2)
  1302
+        y2 += np.sin(fstim2 * x * np.pi * 2)
  1303
+    y = np.hstack([y1, y2])
  1304
+
  1305
+    fig = plt.figure()
  1306
+    ax1 = fig.add_subplot(3, 1, 1)
  1307
+    ax2 = fig.add_subplot(3, 1, 2)
  1308
+    ax3 = fig.add_subplot(3, 1, 3)
  1309
+
  1310
+    spec1 = ax1.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1311
+                         sides='default')
  1312
+    spec2 = ax2.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1313
+                         sides='onesided')
  1314
+    spec3 = ax3.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1315
+                         sides='twosided')
  1316
+
  1317
+
  1318
+@image_comparison(baseline_images=['specgram_noise'], remove_text=True,
  1319
+                  extensions=['png'])
  1320
+def test_specgram_noise():
  1321
+    np.random.seed(0)
  1322
+
  1323
+    n = 10000
  1324
+    Fs = 100.
  1325
+
  1326
+    NFFT = int(1000 * Fs / 11)
  1327
+    noverlap = int(NFFT / 2)
  1328
+    pad_to = int(2 ** np.ceil(np.log2(NFFT)))
  1329
+
  1330
+    y1 = np.random.standard_normal(n)
  1331
+    y2 = np.random.rand(n)
  1332
+    y = np.hstack([y1, y2])
  1333
+
  1334
+    fig = plt.figure()
  1335
+    ax1 = fig.add_subplot(3, 1, 1)
  1336
+    ax2 = fig.add_subplot(3, 1, 2)
  1337
+    ax3 = fig.add_subplot(3, 1, 3)
  1338
+
  1339
+    spec1 = ax1.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1340
+                         sides='default')
  1341
+    spec2 = ax2.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1342
+                         sides='onesided')
  1343
+    spec3 = ax3.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1344
+                         sides='twosided')
  1345
+
  1346
+
  1347
+@image_comparison(baseline_images=['psd_freqs'], remove_text=True,
  1348
+                  extensions=['png'])
  1349
+def test_psd_freqs():
  1350
+    n = 10000
  1351
+    Fs = 100.
  1352
+
  1353
+    fstims1 = [Fs/4, Fs/5, Fs/11]
  1354
+    fstims2 = [Fs/4.7, Fs/5.6, Fs/11.9]
  1355
+
  1356
+    NFFT = int(1000 * Fs / min(fstims1 + fstims2))
  1357
+    noverlap = int(NFFT / 2)
  1358
+    pad_to = int(2 ** np.ceil(np.log2(NFFT)))
  1359
+
  1360
+    x = np.arange(0, n, 1/Fs)
  1361
+
  1362
+    y1 = np.zeros(x.size)
  1363
+    y2 = np.zeros(x.size)
  1364
+    for fstim1, fstim2 in zip(fstims1, fstims2):
  1365
+        y1 += np.sin(fstim1 * x * np.pi * 2)
  1366
+        y2 += np.sin(fstim2 * x * np.pi * 2)
  1367
+    y = np.hstack([y1, y2])
  1368
+
  1369
+    fig = plt.figure()
  1370
+    ax1 = fig.add_subplot(3, 1, 1)
  1371
+    ax2 = fig.add_subplot(3, 1, 2)
  1372
+    ax3 = fig.add_subplot(3, 1, 3)
  1373
+
  1374
+    psd1 = ax1.psd(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1375
+                   sides='default')
  1376
+    psd2 = ax2.psd(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1377
+                   sides='onesided')
  1378
+    psd3 = ax3.psd(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1379
+                   sides='twosided')
  1380
+
  1381
+    ax1.set_xlabel('')
  1382
+    ax2.set_xlabel('')
  1383
+    ax3.set_xlabel('')
  1384
+    ax1.set_ylabel('')
  1385
+    ax2.set_ylabel('')
  1386
+    ax3.set_ylabel('')
  1387
+
  1388
+
  1389
+@image_comparison(baseline_images=['psd_noise'], remove_text=True,
  1390
+                  extensions=['png'])
  1391
+def test_psd_noise():
  1392
+    np.random.seed(0)
  1393
+
  1394
+    n = 10000
  1395
+    Fs = 100.
  1396
+
  1397
+    NFFT = int(1000 * Fs / 11)
  1398
+    noverlap = int(NFFT / 2)
  1399
+    pad_to = int(2 ** np.ceil(np.log2(NFFT)))
  1400
+
  1401
+    y1 = np.random.standard_normal(n)
  1402
+    y2 = np.random.rand(n)
  1403
+    y = np.hstack([y1, y2])
  1404
+
  1405
+    fig = plt.figure()
  1406
+    ax1 = fig.add_subplot(3, 1, 1)
  1407
+    ax2 = fig.add_subplot(3, 1, 2)
  1408
+    ax3 = fig.add_subplot(3, 1, 3)
  1409
+
  1410
+    psd1 = ax1.psd(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1411
+                   sides='default')
  1412
+    psd2 = ax2.psd(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1413
+                   sides='onesided')
  1414
+    psd3 = ax3.psd(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1415
+                   sides='twosided')
  1416
+
  1417
+    ax1.set_xlabel('')
  1418
+    ax2.set_xlabel('')
  1419
+    ax3.set_xlabel('')
  1420
+    ax1.set_ylabel('')
  1421
+    ax2.set_ylabel('')
  1422
+    ax3.set_ylabel('')
  1423
+
  1424
+
  1425
+@image_comparison(baseline_images=['csd_freqs'], remove_text=True,
  1426
+                  extensions=['png'])
  1427
+def test_csd_freqs():
  1428
+    n = 10000
  1429
+    Fs = 100.
  1430
+
  1431
+    fstims1 = [Fs/4, Fs/5, Fs/11]
  1432
+    fstims2 = [Fs/4.7, Fs/5.6, Fs/11.9]
  1433
+
  1434
+    NFFT = int(1000 * Fs / min(fstims1 + fstims2))
  1435
+    noverlap = int(NFFT / 2)
  1436
+    pad_to = int(2 ** np.ceil(np.log2(NFFT)))
  1437
+
  1438
+    x = np.arange(0, n, 1/Fs)
  1439
+
  1440
+    y1 = np.zeros(x.size)
  1441
+    y2 = np.zeros(x.size)
  1442
+    for fstim1, fstim2 in zip(fstims1, fstims2):
  1443
+        y1 += np.sin(fstim1 * x * np.pi * 2)
  1444
+        y2 += np.sin(fstim2 * x * np.pi * 2)
  1445
+
  1446
+    fig = plt.figure()
  1447
+    ax1 = fig.add_subplot(3, 1, 1)
  1448
+    ax2 = fig.add_subplot(3, 1, 2)
  1449
+    ax3 = fig.add_subplot(3, 1, 3)
  1450
+
  1451
+    csd1 = ax1.csd(y1, y2, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1452
+                   sides='default')
  1453
+    csd2 = ax2.csd(y1, y2, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1454
+                   sides='onesided')
  1455
+    csd3 = ax3.csd(y1, y2, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1456
+                   sides='twosided')
  1457
+
  1458
+    ax1.set_xlabel('')
  1459
+    ax2.set_xlabel('')
  1460
+    ax3.set_xlabel('')
  1461
+    ax1.set_ylabel('')
  1462
+    ax2.set_ylabel('')
  1463
+    ax3.set_ylabel('')
  1464
+
  1465
+
  1466
+@image_comparison(baseline_images=['csd_noise'], remove_text=True,
  1467
+                  extensions=['png'])
  1468
+def test_csd_noise():
  1469
+    np.random.seed(0)
  1470
+
  1471
+    n = 10000
  1472
+    Fs = 100.
  1473
+
  1474
+    NFFT = int(1000 * Fs / 11)
  1475
+    noverlap = int(NFFT / 2)
  1476
+    pad_to = int(2 ** np.ceil(np.log2(NFFT)))
  1477
+
  1478
+    y1 = np.random.standard_normal(n)
  1479
+    y2 = np.random.rand(n)
  1480
+
  1481
+    fig = plt.figure()
  1482
+    ax1 = fig.add_subplot(3, 1, 1)
  1483
+    ax2 = fig.add_subplot(3, 1, 2)
  1484
+    ax3 = fig.add_subplot(3, 1, 3)
  1485
+
  1486
+    csd1 = ax1.csd(y1, y2, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1487
+                   sides='default')
  1488
+    csd2 = ax2.csd(y1, y2, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1489
+                   sides='onesided')
  1490
+    csd3 = ax3.csd(y1, y2, NFFT=NFFT, Fs=Fs, noverlap=noverlap, pad_to=pad_to,
  1491
+                   sides='twosided')
  1492
+
  1493
+    ax1.set_xlabel('')
  1494
+    ax2.set_xlabel('')
  1495
+    ax3.set_xlabel('')
  1496
+    ax1.set_ylabel('')
  1497
+    ax2.set_ylabel('')
  1498
+    ax3.set_ylabel('')
  1499
+
  1500
+
1283 1501
 if __name__ == '__main__':
1284 1502
     import nose
1285 1503
     nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
247  lib/matplotlib/tests/test_mlab.py
... ...
@@ -1,69 +1,192 @@
1  
-from __future__ import print_function
  1
+from __future__ import division, print_function
2 2
 
3 3
 import sys
4 4
 
5 5
 import numpy as np
6 6
 import matplotlib.mlab as mlab
7 7
 import tempfile
8  
-from nose.tools import raises
9  
-
10  
-def test_colinear_pca():
11  
-    a = mlab.PCA._get_colinear()
12  
-    pca = mlab.PCA(a)
13  
-
14  
-    assert(np.allclose(pca.fracs[2:], 0.))
15  
-    assert(np.allclose(pca.Y[:,2:], 0.))
16  
-
17  
-def test_recarray_csv_roundtrip():
18  
-    expected = np.recarray((99,),
19  
-                          [('x',np.float),('y',np.float),('t',np.float)])
20  
-    # initialising all values: uninitialised memory sometimes produces floats
21  
-    # that do not round-trip to string and back.
22  
-    expected['x'][:] = np.linspace(-1e9, -1, 99)
23  
-    expected['y'][:] = np.linspace(1, 1e9, 99)
24  
-    expected['t'][:] = np.linspace(0, 0.01, 99)
25  
-    if sys.version_info[0] == 2:
26  
-        fd = tempfile.TemporaryFile(suffix='csv', mode="wb+")
27  
-    else:
28  
-        fd = tempfile.TemporaryFile(suffix='csv', mode="w+", newline='')
29  
-    mlab.rec2csv(expected,fd)
30  
-    fd.seek(0)
31  
-    actual = mlab.csv2rec(fd)
32  
-    fd.close()
33  
-    assert np.allclose( expected['x'], actual['x'] )
34  
-    assert np.allclose( expected['y'], actual['y'] )
35  
-    assert np.allclose( expected['t'], actual['t'] )
36  
-
37  
-@raises(ValueError)
38  
-def test_rec2csv_bad_shape():
39  
-    try:
40  
-        bad = np.recarray((99,4),[('x',np.float),('y',np.float)])
41  
-        fd = tempfile.TemporaryFile(suffix='csv')
42  
-    
  8
+import unittest
  9
+
  10
+
  11
+class general_test(unittest.TestCase):
  12
+    def test_colinear_pca(self):
  13
+        a = mlab.PCA._get_colinear()
  14
+        pca = mlab.PCA(a)
  15
+
  16
+        np.testing.assert_allclose(pca.fracs[2:], 0., atol=1e-8)
  17
+        np.testing.assert_allclose(pca.Y[:, 2:], 0., atol=1e-8)
  18
+
  19
+    def test_prctile(self):
  20
+        # test odd lengths
  21
+        x = [1, 2, 3]
  22
+        self.assertEqual(mlab.prctile(x, 50), np.median(x))
  23
+
  24
+        # test even lengths
  25
+        x = [1, 2, 3, 4]
  26
+        self.assertEqual(mlab.prctile(x, 50), np.median(x))
  27
+
  28
+        # derived from email sent by jason-sage to MPL-user on 20090914
  29
+        ob1 = [1, 1, 2, 2, 1, 2, 4, 3, 2, 2, 2, 3,
  30
+               4, 5, 6, 7, 8, 9, 7, 6, 4, 5, 5]
  31
+        p = [0, 75, 100]
  32
+        expected = [1, 5.5, 9]
  33
+
  34
+        # test vectorized
  35
+        actual = mlab.prctile(ob1, p)
  36
+        np.testing.assert_allclose(expected, actual)
  37
+
  38
+        # test scalar
  39
+        for pi, expectedi in zip(p, expected):
  40
+            actuali = mlab.prctile(ob1, pi)
  41
+            np.testing.assert_allclose(expectedi, actuali)
  42
+
  43
+
  44
+class csv_testcase(unittest.TestCase):
  45
+    def setUp(self):
  46
+        if sys.version_info[0] == 2:
  47
+            self.fd = tempfile.TemporaryFile(suffix='csv', mode="wb+")
  48
+        else:
  49
+            self.fd = tempfile.TemporaryFile(suffix='csv', mode="w+",
  50
+                                             newline='')
  51
+
  52
+    def tearDown(self):
  53
+        self.fd.close()
  54
+
  55
+    def test_recarray_csv_roundtrip(self):
  56
+        expected = np.recarray((99,),
  57
+                               [('x', np.float),
  58
+                                ('y', np.float),
  59
+                                ('t', np.float)])
  60
+        # initialising all values: uninitialised memory sometimes produces
  61
+        # floats that do not round-trip to string and back.
  62
+        expected['x'][:] = np.linspace(-1e9, -1, 99)
  63
+        expected['y'][:] = np.linspace(1, 1e9, 99)
  64
+        expected['t'][:] = np.linspace(0, 0.01, 99)
  65
+
  66
+        mlab.rec2csv(expected, self.fd)
  67
+        self.fd.seek(0)
  68
+        actual = mlab.csv2rec(self.fd)
  69
+
  70
+        np.testing.assert_allclose(expected['x'], actual['x'])
  71
+        np.testing.assert_allclose(expected['y'], actual['y'])
  72
+        np.testing.assert_allclose(expected['t'], actual['t'])
  73
+
  74
+    def test_rec2csv_bad_shape_ValueError(self):
  75
+        bad = np.recarray((99, 4), [('x', np.float), ('y', np.float)])
  76
+
43 77
         # the bad recarray should trigger a ValueError for having ndim > 1.
44  
-        mlab.rec2csv(bad,fd)
45  
-    finally:
46  
-        fd.close()
47  
-
48  
-def test_prctile():
49  
-    # test odd lengths
50  
-    x=[1,2,3]
51  
-    assert mlab.prctile(x,50)==np.median(x)
52  
-
53  
-    # test even lengths
54  
-    x=[1,2,3,4]
55  
-    assert mlab.prctile(x,50)==np.median(x)
56  
-
57  
-    # derived from email sent by jason-sage to MPL-user on 20090914
58  
-    ob1=[1,1,2,2,1,2,4,3,2,2,2,3,4,5,6,7,8,9,7,6,4,5,5]
59  
-    p        = [0,   75, 100]
60  
-    expected = [1,  5.5,   9]
61  
-
62  
-    # test vectorized
63  
-    actual = mlab.prctile(ob1,p)
64  
-    assert np.allclose( expected, actual )
65  
-
66  
-    # test scalar
67  
-    for pi, expectedi in zip(p,expected):
68  
-        actuali = mlab.prctile(ob1,pi)
69  
-        assert np.allclose( expectedi, actuali )
  78
+        self.assertRaises(ValueError, mlab.rec2csv, bad, self.fd)
  79
+
  80
+
  81
+class spectral_testcase(unittest.TestCase):
  82
+    def setUp(self):
  83
+        self.Fs = 100.
  84
+
  85
+        self.fstims = [self.Fs/4, self.Fs/5, self.Fs/10]
  86
+
  87
+        self.x = np.arange(0, 10000, 1/self.Fs)
  88
+        self.NFFT = 1000*int(1/min(self.fstims) * self.Fs)
  89
+        self.noverlap = int(self.NFFT/2)
  90
+        self.pad_to = int(2**np.ceil(np.log2(self.NFFT)))
  91
+
  92
+        self.freqss = np.linspace(0, self.Fs/2, num=self.pad_to//2+1)
  93
+        self.freqsd = np.linspace(-self.Fs/2, self.Fs/2, num=self.pad_to,
  94
+                                  endpoint=False)
  95
+
  96
+        self.t = self.x[self.NFFT//2::self.NFFT-self.noverlap]
  97
+
  98
+        self.y = [np.zeros(self.x.size)]
  99
+        for i, fstim in enumerate(self.fstims):
  100
+            self.y.append(np.sin(fstim * self.x * np.pi * 2))
  101
+        self.y.append(np.sum(self.y, axis=0))
  102
+
  103
+        # get the list of frequencies in each test
  104
+        self.fstimsall = [[]] + [[f] for f in self.fstims] + [self.fstims]
  105
+
  106
+    def test_psd(self):
  107
+        for y, fstims in zip(self.y, self.fstimsall):
  108
+            Pxx1, freqs1 = mlab.psd(y, NFFT=self.NFFT,
  109
+                                    Fs=self.Fs,
  110
+                                    noverlap=self.noverlap,
  111
+                                    pad_to=self.pad_to,
  112
+                                    sides='default')
  113
+            np.testing.assert_array_equal(freqs1, self.freqss)
  114
+            for fstim in fstims:
  115
+                i = np.abs(freqs1 - fstim).argmin()
  116
+                self.assertTrue(Pxx1[i] > Pxx1[i+1])
  117
+                self.assertTrue(Pxx1[i] > Pxx1[i-1])
  118
+
  119
+            Pxx2, freqs2 = mlab.psd(y, NFFT=self.NFFT,
  120
+                                    Fs=self.Fs,
  121
+                                    noverlap=self.noverlap,
  122
+                                    pad_to=self.pad_to,
  123
+                                    sides='onesided')
  124
+            np.testing.assert_array_equal(freqs2, self.freqss)
  125
+            for fstim in fstims:
  126
+                i = np.abs(freqs2 - fstim).argmin()
  127
+                self.assertTrue(Pxx2[i] > Pxx2[i+1])
  128
+                self.assertTrue(Pxx2[i] > Pxx2[i-1])
  129
+
  130
+            Pxx3, freqs3 = mlab.psd(y, NFFT=self.NFFT,
  131
+                                    Fs=self.Fs,
  132
+                                    noverlap=self.noverlap,
  133
+                                    pad_to=self.pad_to,
  134
+                                    sides='twosided')
  135
+            np.testing.assert_array_equal(freqs3, self.freqsd)
  136
+            for fstim in fstims:
  137
+                i = np.abs(freqs3 - fstim).argmin()
  138
+                self.assertTrue(Pxx3[i] > Pxx3[i+1])
  139
+                self.assertTrue(Pxx3[i] > Pxx3[i-1])
  140
+
  141
+    def test_specgram(self):
  142
+        for y, fstims in zip(self.y, self.fstimsall):
  143
+            Pxx1, freqs1, t1 = mlab.specgram(y, NFFT=self.NFFT,
  144
+                                             Fs=self.Fs,
  145
+                                             noverlap=self.noverlap,
  146
+                                             pad_to=self.pad_to,
  147
+                                             sides='default')
  148
+            Pxx1m = np.mean(Pxx1, axis=1)
  149
+            np.testing.assert_array_equal(freqs1, self.freqss)
  150
+            np.testing.assert_array_equal(t1, self.t)
  151
+            # since we are using a single freq, all time slices should be
  152
+            # about the same
  153
+            np.testing.assert_allclose(np.diff(Pxx1, axis=1).max(), 0,
  154
+                                       atol=1e-08)
  155
+            for fstim in fstims:
  156
+                i = np.abs(freqs1 - fstim).argmin()
  157
+                self.assertTrue(Pxx1m[i] > Pxx1m[i+1])
  158
+                self.assertTrue(Pxx1m[i] > Pxx1m[i-1])
  159
+
  160
+            Pxx2, freqs2, t2 = mlab.specgram(y, NFFT=self.NFFT,
  161
+                                             Fs=self.Fs,
  162
+                                             noverlap=self.noverlap,
  163
+                                             pad_to=self.pad_to,
  164
+                                             sides='onesided')
  165
+            Pxx2m = np.mean(Pxx2, axis=1)
  166
+            np.testing.assert_array_equal(freqs2, self.freqss)
  167
+            np.testing.assert_array_equal(t2, self.t)
  168
+            np.testing.assert_allclose(np.diff(Pxx2, axis=1).max(), 0,
  169
+                                       atol=1e-08)
  170
+            for fstim in fstims:
  171
+                i = np.abs(freqs2 - fstim).argmin()
  172
+                self.assertTrue(Pxx2m[i] > Pxx2m[i+1])
  173
+                self.assertTrue(Pxx2m[i] > Pxx2m[i-1])
  174
+
  175
+            Pxx3, freqs3, t3 = mlab.specgram(y, NFFT=self.NFFT,
  176
+                                             Fs=self.Fs,
  177
+                                             noverlap=self.noverlap,
  178
+                                             pad_to=self.pad_to,
  179
+                                             sides='twosided')
  180
+            Pxx3m = np.mean(Pxx3, axis=1)
  181
+            np.testing.assert_array_equal(freqs3, self.freqsd)
  182
+            np.testing.assert_array_equal(t3, self.t)
  183
+            np.testing.assert_allclose(np.diff(Pxx3, axis=1).max(), 0,
  184
+                                       atol=1e-08)
  185
+            for fstim in fstims:
  186
+                i = np.abs(freqs3 - fstim).argmin()
  187
+                self.assertTrue(Pxx3m[i] > Pxx3m[i+1])
  188
+                self.assertTrue(Pxx3m[i] > Pxx3m[i-1])
  189
+
  190
+
  191
+if __name__ == '__main__':
  192
+    unittest.main()
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.