MCPcopy
hub / github.com/mne-tools/mne-python / test_csd_matlab

Function test_csd_matlab

mne/preprocessing/tests/test_csd.py:63–81  ·  view source on GitHub ↗

Test replication of the CSD MATLAB toolbox.

(evoked_csd_sphere)

Source from the content-addressed store, hash-verified

61
62
63def test_csd_matlab(evoked_csd_sphere):
64 """Test replication of the CSD MATLAB toolbox."""
65 evoked, csd, sphere = evoked_csd_sphere
66 evoked_csd = compute_current_source_density(evoked, sphere=sphere)
67 assert_allclose(linalg.norm(csd), 0.00177, atol=1e-5)
68 # If we don't project onto the sphere, we get 1e-12 accuracy here,
69 # but it's a bad assumption for real data!
70 # Also, we divide by (radius ** 2) to get to units of V/m², unclear
71 # why this isn't done in the upstream implementation
72 evoked_csd_data = evoked_csd.data * sphere[-1] ** 2
73 assert_allclose(evoked_csd_data, csd, atol=2e-7)
74
75 with pytest.raises(
76 ValueError, match=("CSD already applied, should not be reapplied")
77 ):
78 compute_current_source_density(evoked_csd, sphere=sphere)
79
80 # 1e-5 here if we don't project...
81 assert_allclose(evoked_csd_data.sum(), 0.02455, atol=2e-3)
82
83
84def test_csd_degenerate(evoked_csd_sphere):

Callers

nothing calls this directly

Calls 3

normMethod · 0.80
sumMethod · 0.45

Tested by

no test coverage detected