code: def test_csd_matlab(evoked_csd_sphere):
      """Test replication of the CSD MATLAB toolbox."""
      evoked, csd, sphere = evoked_csd_sphere
      evoked_csd = compute_current_source_density(evoked, sphere=sphere)
      assert_allclose(linalg.norm(csd), 0.00177, atol=1e-5)
      # If we don't project onto the sphere, we get 1e-12 accuracy here,
      # but it's a bad assumption for real data!
      # Also, we divide by (radius ** 2) to get to units of V/m², unclear
      # why this isn't done in the upstream implementation
      evoked_csd_data = evoked_csd.data * sphere[-1] ** 2
      assert_allclose(evoked_csd_data, csd, atol=2e-7)
  
      with pytest.raises(
          ValueError,
          match=("CSD already applied, " "should not be reapplied"),
      ):
          compute_current_source_density(evoked_csd, sphere=sphere)
  
      # 1e-5 here if we don't project...
      assert_allclose(evoked_csd_data.sum(), 0.02455, atol=2e-3)
  
file_path: mne-python/mne/preprocessing/tests/test_csd.py
imports: from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose
  from scipy import linalg
  from scipy.io import loadmat
  from mne import Epochs, EvokedArray, create_info, find_events, pick_types, read_epochs
  from mne._fiff.constants import FIFF
  from mne.channels import make_dig_montage
  from mne.datasets import testing
  from mne.io import RawArray, read_raw_fif
  from mne.preprocessing import compute_bridged_electrodes, compute_current_source_density
  from mne.utils import object_diff
label_desc: Use image node_id 2 for calling a global function with example usage: test_csd_matlab(evoked_csd_sphere) without return types