code: def test_source_space_from_label(tmp_path, pass_ids):
      """Test generating a source space from volume label."""
      pytest.importorskip("nibabel")
      aseg_short = "aseg.mgz"
      atlas_ids, _ = read_freesurfer_lut()
      volume_label = "Left-Cerebellum-Cortex"
  
      # Test pos as dict
      pos = dict()
      with pytest.raises(
          ValueError, match="mri must be None if pos is a dict"
      ):
          setup_volume_source_space(
              "sample",
              pos=pos,
              volume_label=volume_label,
              mri=aseg_short,
              subjects_dir=subjects_dir,
          )
  
      # Test T1.mgz provided
      with pytest.raises(
          RuntimeError, match=r"Must use a \*aseg.mgz file"
      ):
          setup_volume_source_space(
              "sample",
              mri="T1.mgz",
              volume_label=volume_label,
              subjects_dir=subjects_dir,
          )
  
      # Test invalid volume label
      mri = aseg_short
      with pytest.raises(
          ValueError, match="'Left-Cerebral' not found.*Did you"
      ):
          setup_volume_source_space(
              "sample",
              volume_label="Left-Cerebral",
              mri=mri,
              subjects_dir=subjects_dir,
          )
  
      # These should be equivalent
      if pass_ids:
          use_volume_label = {volume_label: atlas_ids[volume_label]}
      else:
          use_volume_label = volume_label
  
      # ensure it works even when not provided (detect that it should be aseg)
      src = setup_volume_source_space(
          "sample",
          volume_label=use_volume_label,
          add_interpolator=False,
          subjects_dir=subjects_dir,
      )
      assert_equal(volume_label, src[0]["seg_name"])
      assert src[0]["nuse"] == 404  # for our given pos and label
  
      # test reading and writing
      out_name = tmp_path / "temp-src.fif"
      write_source_spaces(out_name, src)
      src_from_file = read_source_spaces(out_name)
      _compare_source_spaces(src, src_from_file, mode="approx")
  
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 16 for calling a global function with example usage: test_source_space_from_label(tmp_path, pass_ids) without return types