code: def test_volume_source_space(tmp_path):
      """Test setting up volume source spaces."""
      pytest.importorskip("nibabel")
      src = read_source_spaces(fname_vol)
      temp_name = tmp_path / "temp-src.fif"
      surf = read_bem_surfaces(
          fname_bem, s_id=FIFF.FIFFV_BEM_SURF_ID_BRAIN
      )
      surf["rr"] *= 1e3  # convert to mm
      bem_sol = read_bem_solution(fname_bem_3_sol)
      bem = read_bem_solution(fname_bem_sol)
      # The one in the testing dataset (uses bem as bounds)
      for this_bem, this_surf in zip(
          (bem, fname_bem, fname_bem_3, bem_sol, fname_bem_3_sol, None),
          (None, None, None, None, None, surf),
      ):
          src_new = setup_volume_source_space(
              "sample",
              pos=7.0,
              bem=this_bem,
              surface=this_surf,
              subjects_dir=subjects_dir,
          )
          write_source_spaces(temp_name, src_new, overwrite=True)
          src[0][
              "subject_his_id"
          ] = "sample"  # XXX: to make comparison pass
          _compare_source_spaces(src, src_new, mode="approx")
          del src_new
          src_new = read_source_spaces(temp_name)
          _compare_source_spaces(src, src_new, mode="approx")
      with pytest.raises(OSError, match="surface file.*not exist"):
          setup_volume_source_space(
              "sample",
              surface="foo",
              mri=fname_mri,
              subjects_dir=subjects_dir,
          )
      bem["surfs"][-1]["coord_frame"] = FIFF.FIFFV_COORD_HEAD
      with pytest.raises(
          ValueError, match="BEM is not in MRI coord.* got head"
      ):
          setup_volume_source_space(
              "sample",
              bem=bem,
              mri=fname_mri,
              subjects_dir=subjects_dir,
          )
      bem["surfs"] = bem["surfs"][:-1]  # no inner skull surf
      with pytest.raises(
          ValueError, match="Could not get inner skul.*from BEM"
      ):
          setup_volume_source_space(
              "sample",
              bem=bem,
              mri=fname_mri,
              subjects_dir=subjects_dir,
          )
      del bem
      assert repr(src) == repr(src_new)
      assert " MB" in repr(src)
      assert src.kind == "volume"
      # Spheres
      sphere = make_sphere_model(
          r0=(0.0, 0.0, 0.0),
          head_radius=0.1,
          relative_radii=(0.9, 1.0),
          sigmas=(0.33, 1.0),
      )
      src = setup_volume_source_space(
          pos=10, sphere=(0.0, 0.0, 0.0, 0.09)
      )
      src_new = setup_volume_source_space(pos=10, sphere=sphere)
      _compare_source_spaces(src, src_new, mode="exact")
      with pytest.raises(ValueError, match="sphere, if str"):
          setup_volume_source_space(sphere="foo")
      # Need a radius
      sphere = make_sphere_model(head_radius=None)
      with pytest.raises(
          ValueError, match="be spherical with multiple layers"
      ):
          setup_volume_source_space(sphere=sphere)
  
imports: from pathlib import Path
  from shutil import copytree
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_array_less, assert_equal
  import mne
  from mne import SourceEstimate, add_source_space_distances, compute_source_morph, get_volume_labels_from_src, make_sphere_model, morph_source_spaces, pick_types, read_bem_solution, read_bem_surfaces, read_freesurfer_lut, read_source_spaces, read_trans, setup_source_space, setup_volume_source_space, write_source_spaces
  from mne._fiff.constants import FIFF
  from mne._fiff.pick import _picks_to_idx
  from mne.datasets import testing
  from mne.fixes import _get_img_fdata
  from mne.source_estimate import _get_src_type
  from mne.source_space import compute_distance_to_sensors, get_decimated_surfaces
  from mne.source_space._source_space import _compare_source_spaces
  from mne.surface import _accumulate_normals, _triangle_neighbors
  from mne.utils import _record_warnings, requires_mne, run_subprocess
label_desc: Use image node_id 8 for calling a global function with example usage: test_volume_source_space(tmp_path) without return types