File: test_fixes.py

package info (click to toggle)
python-mne 0.17%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 95,104 kB
  • sloc: python: 110,639; makefile: 222; sh: 15
file content (40 lines) | stat: -rw-r--r-- 1,342 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Authors: Emmanuelle Gouillart <emmanuelle.gouillart@normalesup.org>
#          Gael Varoquaux <gael.varoquaux@normalesup.org>
#          Alex Gramfort <alexandre.gramfort@telecom-paristech.fr>
# License: BSD

import numpy as np
from numpy.testing import assert_allclose
from scipy.signal import filtfilt
from scipy.special import sph_harm

from numpy.testing import assert_array_equal

from mne.utils import run_tests_if_main, requires_version
from mne.fixes import _sosfiltfilt as mne_sosfiltfilt, _sph_harm


def test_filtfilt():
    """Test SOS filtfilt replacement."""
    x = np.r_[1, np.zeros(100)]
    # Filter with an impulse
    y = filtfilt([1, 0], [1, 0], x, padlen=0)
    assert_array_equal(x, y)
    y = mne_sosfiltfilt(np.array([[1., 0., 0., 1, 0., 0.]]), x, padlen=0)
    assert_array_equal(x, y)


@requires_version('scipy', '0.17.1')
def test_spherical_harmonics():
    """Test spherical harmonic functions."""
    az, pol = np.meshgrid(np.linspace(0, 2 * np.pi, 30),
                          np.linspace(0, np.pi, 20))
    # Test our basic spherical harmonics
    for degree in range(1, 10):
        for order in range(0, degree + 1):
            sph = _sph_harm(order, degree, az, pol)
            sph_scipy = sph_harm(order, degree, az, pol)
            assert_allclose(sph, sph_scipy, atol=1e-7)


run_tests_if_main()