code: def test_csd_degenerate(evoked_csd_sphere):
      """Test degenerate conditions."""
      evoked, csd, sphere = evoked_csd_sphere
      warn_evoked = evoked.copy()
      warn_evoked.info["bads"].append(warn_evoked.ch_names[3])
      with pytest.raises(
          ValueError, match="Either drop.*or interpolate"
      ):
          compute_current_source_density(warn_evoked)
  
      with pytest.raises(TypeError, match="must be an instance of"):
          compute_current_source_density(None)
  
      fail_evoked = evoked.copy()
      with pytest.raises(ValueError, match="Zero or infinite position"):
          for ch in fail_evoked.info["chs"]:
              ch["loc"][:3] = np.array([0, 0, 0])
          compute_current_source_density(fail_evoked, sphere=sphere)
  
      with pytest.raises(ValueError, match="Zero or infinite position"):
          fail_evoked.info["chs"][3]["loc"][:3] = np.inf
          compute_current_source_density(fail_evoked, sphere=sphere)
  
      with pytest.raises(ValueError, match="No EEG channels found."):
          fail_evoked = evoked.copy()
          fail_evoked.set_channel_types(
              {ch_name: "ecog" for ch_name in fail_evoked.ch_names}
          )
          compute_current_source_density(fail_evoked, sphere=sphere)
  
      with pytest.raises(TypeError, match="lambda2"):
          compute_current_source_density(
              evoked, lambda2="0", sphere=sphere
          )
  
      with pytest.raises(
          ValueError, match="lambda2 must be between 0 and 1"
      ):
          compute_current_source_density(
              evoked, lambda2=2, sphere=sphere
          )
  
      with pytest.raises(TypeError, match="stiffness must be"):
          compute_current_source_density(
              evoked, stiffness="0", sphere=sphere
          )
  
      with pytest.raises(
          ValueError, match="stiffness must be non-negative"
      ):
          compute_current_source_density(
              evoked, stiffness=-2, sphere=sphere
          )
  
      with pytest.raises(TypeError, match="n_legendre_terms must be"):
          compute_current_source_density(
              evoked, n_legendre_terms=0.1, sphere=sphere
          )
  
      with pytest.raises(
          ValueError,
          match=("n_legendre_terms must be " "greater than 0"),
      ):
          compute_current_source_density(
              evoked, n_legendre_terms=0, sphere=sphere
          )
  
      with pytest.raises(ValueError, match="sphere must be"):
          compute_current_source_density(evoked, sphere=-0.1)
  
      with pytest.raises(
          ValueError, match=("sphere radius must be " "greater than 0")
      ):
          compute_current_source_density(
              evoked, sphere=(-0.1, 0.0, 0.0, -1.0)
          )
  
      with pytest.raises(TypeError):
          compute_current_source_density(evoked, copy=2, sphere=sphere)
  
      # gh-7859
      raw = RawArray(evoked.data, evoked.info)
      epochs = Epochs(
          raw,
          [[0, 0, 1]],
          tmin=0,
          tmax=evoked.times[-1] - evoked.times[0],
          baseline=None,
          preload=False,
          proj=False,
      )
      epochs.drop_bad()
      assert len(epochs) == 1
      assert_allclose(epochs.get_data(item=[0])[0], evoked.data)
      with pytest.raises(
          RuntimeError, match="Computing CSD requires.*preload"
      ):
          compute_current_source_density(epochs)
      epochs.load_data()
      raw = compute_current_source_density(raw)
      assert not np.allclose(raw.get_data(), evoked.data)
      evoked = compute_current_source_density(evoked)
      assert_allclose(raw.get_data(), evoked.data)
      epochs = compute_current_source_density(epochs)
      assert_allclose(epochs.get_data(item=[0])[0], evoked.data)
  
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 3 for calling a global function with example usage: test_csd_degenerate(evoked_csd_sphere) without return types