Test replication of the CSD MATLAB toolbox.
(evoked_csd_sphere)
| 61 | |
| 62 | |
| 63 | def 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 | |
| 84 | def test_csd_degenerate(evoked_csd_sphere): |
nothing calls this directly
no test coverage detected