code: def test_plot_alignment_basic(
      tmp_path, renderer, mixed_fwd_cov_evoked
  ):
      """Test plotting of -trans.fif files and MEG sensor layouts."""
      # generate fiducials file for testing
      fiducials_path = tmp_path / "fiducials.fif"
      fid = [
          {
              "coord_frame": 5,
              "ident": 1,
              "kind": 1,
              "r": [-0.08061612, -0.02908875, -0.04131077],
          },
          {
              "coord_frame": 5,
              "ident": 2,
              "kind": 1,
              "r": [0.00146763, 0.08506715, -0.03483611],
          },
          {
              "coord_frame": 5,
              "ident": 3,
              "kind": 1,
              "r": [0.08436285, -0.02850276, -0.04127743],
          },
      ]
      write_dig(fiducials_path, fid, 5)
      evoked = read_evokeds(evoked_fname)[0]
      info = evoked.info
  
      sample_src = read_source_spaces(src_fname)
      pytest.raises(
          TypeError,
          plot_alignment,
          "foo",
          trans_fname,
          subject="sample",
          subjects_dir=subjects_dir,
      )
      pytest.raises(
          OSError,
          plot_alignment,
          info,
          trans_fname,
          subject="sample",
          subjects_dir=subjects_dir,
          src="foo",
      )
      pytest.raises(
          ValueError,
          plot_alignment,
          info,
          trans_fname,
          subject="fsaverage",
          subjects_dir=subjects_dir,
          src=sample_src,
      )
      sample_src.plot(
          subjects_dir=subjects_dir,
          head=True,
          skull=True,
          brain="white",
      )
      # mixed source space
      mixed_src = mixed_fwd_cov_evoked[0]["src"]
      assert mixed_src.kind == "mixed"
      fig = plot_alignment(
          info,
          meg=["helmet", "sensors"],
          dig=True,
          coord_frame="head",
          trans=Path(trans_fname),
          subject="sample",
          mri_fiducials=fiducials_path,
          subjects_dir=subjects_dir,
          src=mixed_src,
      )
      assert isinstance(fig, Figure3D)
      renderer.backend._close_all()
      # no-head version
      renderer.backend._close_all()
      # trans required
      with pytest.raises(
          ValueError, match="transformation matrix.*in head"
      ):
          plot_alignment(info, trans=None, src=src_fname)
      with pytest.raises(
          ValueError, match="transformation matrix.*in head"
      ):
          plot_alignment(info, trans=None, mri_fiducials=True)
      with pytest.raises(
          ValueError, match="transformation matrix.*in head"
      ):
          plot_alignment(info, trans=None, surfaces=["brain"])
      assert mixed_src[0]["coord_frame"] == FIFF.FIFFV_COORD_HEAD
      with pytest.raises(
          ValueError, match="head-coordinate source space in mr"
      ):
          plot_alignment(trans=None, src=mixed_src, coord_frame="mri")
      # all coord frames
      plot_alignment(info)  # works: surfaces='auto' default
      for coord_frame in ("meg", "head", "mri"):
          plot_alignment(
              info,
              meg=["helmet", "sensors"],
              dig=True,
              coord_frame=coord_frame,
              trans=Path(trans_fname),
              subject="sample",
              src=src_fname,
              mri_fiducials=fiducials_path,
              subjects_dir=subjects_dir,
          )
      renderer.backend._close_all()
      # EEG only with strange options
      evoked_eeg_ecog_seeg = evoked.copy().pick_types(
          meg=False, eeg=True
      )
      with evoked_eeg_ecog_seeg.info._unlock():
          evoked_eeg_ecog_seeg.info["projs"] = []  # "remove" avg proj
      evoked_eeg_ecog_seeg.set_channel_types(
          {"EEG 001": "ecog", "EEG 002": "seeg"}
      )
      with catch_logging() as log:
          plot_alignment(
              evoked_eeg_ecog_seeg.info,
              subject="sample",
              trans=trans_fname,
              subjects_dir=subjects_dir,
              surfaces=["white", "outer_skin", "outer_skull"],
              meg=["helmet", "sensors"],
              eeg=["original", "projected"],
              ecog=True,
              seeg=True,
              verbose=True,
          )
      log = log.getvalue()
      assert "ecog: 1" in log
      assert "seeg: 1" in log
      renderer.backend._close_all()
  
      sphere = make_sphere_model(
          info=info, r0="auto", head_radius="auto"
      )
      bem_sol = read_bem_solution(
          subjects_dir
          / "sample"
          / "bem"
          / "sample-1280-1280-1280-bem-sol.fif"
      )
      bem_surfs = read_bem_surfaces(
          subjects_dir
          / "sample"
          / "bem"
          / "sample-1280-1280-1280-bem.fif"
      )
      sample_src[0]["coord_frame"] = 4  # hack for coverage
      plot_alignment(
          info,
          trans_fname,
          subject="sample",
          eeg="projected",
          meg="helmet",
          bem=sphere,
          dig=True,
          surfaces=[
              "brain",
              "inner_skull",
              "outer_skull",
              "outer_skin",
          ],
      )
      plot_alignment(
          info,
          trans_fname,
          subject="sample",
          meg="helmet",
          subjects_dir=subjects_dir,
          eeg="projected",
          bem=sphere,
          surfaces=["head", "brain"],
          src=sample_src,
      )
      # no trans okay, no mri surfaces
      plot_alignment(info, bem=sphere, surfaces=["brain"])
      with pytest.raises(
          ValueError, match="A head surface is required"
      ):
          plot_alignment(
              info,
              trans=trans_fname,
              subject="sample",
              subjects_dir=subjects_dir,
              eeg="projected",
              surfaces=[],
          )
      with pytest.raises(RuntimeError, match="No brain surface found"):
          plot_alignment(
              info,
              trans=trans_fname,
              subject="foo",
              subjects_dir=subjects_dir,
              surfaces=["brain"],
          )
      assert all(
          surf["coord_frame"] == FIFF.FIFFV_COORD_MRI
          for surf in bem_sol["surfs"]
      )
      plot_alignment(
          info,
          trans_fname,
          subject="sample",
          meg=[],
          subjects_dir=subjects_dir,
          bem=bem_sol,
          eeg=True,
          surfaces=["head", "inflated", "outer_skull", "inner_skull"],
      )
      assert all(
          surf["coord_frame"] == FIFF.FIFFV_COORD_MRI
          for surf in bem_sol["surfs"]
      )
      plot_alignment(
          info,
          trans_fname,
          subject="sample",
          meg=True,
          subjects_dir=subjects_dir,
          surfaces=["head", "inner_skull"],
          bem=bem_surfs,
      )
      # single-layer BEM can still plot head surface
      assert bem_surfs[-1]["id"] == FIFF.FIFFV_BEM_SURF_ID_BRAIN
      bem_sol_homog = read_bem_solution(
          subjects_dir / "sample" / "bem" / "sample-1280-bem-sol.fif"
      )
      for use_bem in (bem_surfs[-1:], bem_sol_homog):
          with catch_logging() as log:
              plot_alignment(
                  info,
                  trans_fname,
                  subject="sample",
                  meg=True,
                  subjects_dir=subjects_dir,
                  surfaces=["head", "inner_skull"],
                  bem=use_bem,
                  verbose=True,
              )
          log = log.getvalue()
          assert (
              "not find the surface for head in the provided BEM model"
              in log
          )
      # sphere model
      sphere = make_sphere_model("auto", "auto", info)
      src = setup_volume_source_space(sphere=sphere)
      plot_alignment(
          info,
          trans=Transform("head", "mri"),
          eeg="projected",
          meg="helmet",
          bem=sphere,
          src=src,
          dig=True,
          surfaces=[
              "brain",
              "inner_skull",
              "outer_skull",
              "outer_skin",
          ],
      )
      sphere = make_sphere_model("auto", None, info)  # one layer
      # if you ask for a brain surface with a 1-layer sphere model it's an error
      with pytest.raises(
          RuntimeError, match="Sphere model does not have"
      ):
          plot_alignment(
              trans=trans_fname,
              subject="sample",
              subjects_dir=subjects_dir,
              surfaces=["brain"],
              bem=sphere,
          )
      # but you can ask for a specific brain surface, and
      # no info is permitted
      plot_alignment(
          trans=trans_fname,
          subject="sample",
          meg=False,
          coord_frame="mri",
          subjects_dir=subjects_dir,
          surfaces=["white"],
          bem=sphere,
          show_axes=True,
      )
      renderer.backend._close_all()
      # TODO: We need to make this class public and document it properly
      # assert isinstance(fig, some_public_class)
      # 3D coil with no defined draw (ConvexHull)
      info_cube = pick_info(info, np.arange(6))
      with info._unlock():
          info["dig"] = None
      info_cube["chs"][0]["coil_type"] = 9999
      info_cube["chs"][1]["coil_type"] = 9998
      with pytest.raises(
          RuntimeError, match="coil definition not found"
      ):
          plot_alignment(info_cube, meg="sensors", surfaces=())
      coil_def_fname = tmp_path / "temp"
      with open(coil_def_fname, "w") as fid:
          fid.write(coil_3d)
      # make sure our other OPMs can be plotted, too
      for ii, kind in enumerate(
          (
              "QUSPIN_ZFOPM_MAG",
              "QUSPIN_ZFOPM_MAG2",
              "FIELDLINE_OPM_MAG_GEN1",
              "KERNEL_OPM_MAG_GEN1",
          ),
          2,
      ):
          info_cube["chs"][ii]["coil_type"] = getattr(
              FIFF, f"FIFFV_COIL_{kind}"
          )
      with use_coil_def(coil_def_fname):
          with catch_logging() as log:
              plot_alignment(
                  info_cube,
                  meg="sensors",
                  surfaces=(),
                  dig=True,
                  verbose="debug",
              )
      log = log.getvalue()
      assert "planar geometry" in log
  
      # one layer bem with skull surfaces:
      with pytest.raises(
          RuntimeError, match="Sphere model does not.*boundary"
      ):
          plot_alignment(
              info=info,
              trans=trans_fname,
              subject="sample",
              subjects_dir=subjects_dir,
              surfaces=["brain", "head", "inner_skull"],
              bem=sphere,
          )
      # wrong eeg value:
      with pytest.raises(
          ValueError, match="Invalid value for the .eeg"
      ):
          plot_alignment(
              info=info,
              trans=trans_fname,
              subject="sample",
              subjects_dir=subjects_dir,
              eeg="foo",
          )
      # wrong meg value:
      with pytest.raises(
          ValueError, match="Invalid value for the .meg"
      ):
          plot_alignment(
              info=info,
              trans=trans_fname,
              subject="sample",
              subjects_dir=subjects_dir,
              meg="bar",
          )
      # multiple brain surfaces:
      with pytest.raises(
          ValueError, match="Only one brain surface can be plot"
      ):
          plot_alignment(
              info=info,
              trans=trans_fname,
              subject="sample",
              subjects_dir=subjects_dir,
              surfaces=["white", "pial"],
          )
      with pytest.raises(TypeError, match="surfaces.*must be"):
          plot_alignment(
              info=info,
              trans=trans_fname,
              subject="sample",
              subjects_dir=subjects_dir,
              surfaces=[1],
          )
      with pytest.raises(ValueError, match="Unknown surface type"):
          plot_alignment(
              info=info,
              trans=trans_fname,
              subject="sample",
              subjects_dir=subjects_dir,
              surfaces=["foo"],
          )
      with pytest.raises(TypeError, match="must be an instance of "):
          plot_alignment(
              info=info,
              trans=trans_fname,
              subject="sample",
              subjects_dir=subjects_dir,
              surfaces=dict(brain="super clear"),
          )
      with pytest.raises(ValueError, match="must be between 0 and 1"):
          plot_alignment(
              info=info,
              trans=trans_fname,
              subject="sample",
              subjects_dir=subjects_dir,
              surfaces=dict(brain=42),
          )
      fwd_fname = (
          data_dir
          / "MEG"
          / "sample"
          / "sample_audvis_trunc-meg-eeg-oct-4-fwd.fif"
      )
      fwd = read_forward_solution(fwd_fname)
      plot_alignment(
          subject="sample",
          subjects_dir=subjects_dir,
          trans=trans_fname,
          fwd=fwd,
          surfaces="white",
          coord_frame="head",
      )
      fwd = convert_forward_solution(fwd, force_fixed=True)
      plot_alignment(
          subject="sample",
          subjects_dir=subjects_dir,
          trans=trans_fname,
          fwd=fwd,
          surfaces="white",
          coord_frame="head",
      )
      fwd[
          "coord_frame"
      ] = FIFF.FIFFV_COORD_MRI  # check required to get to MRI
      with pytest.raises(
          ValueError, match="transformation matrix.*in head coo"
      ):
          plot_alignment(info, trans=None, fwd=fwd)
      # surfaces as dict
      plot_alignment(
          subject="sample",
          coord_frame="head",
          trans=trans_fname,
          subjects_dir=subjects_dir,
          surfaces={"white": 0.4, "outer_skull": 0.6, "head": None},
      )
  
imports: from pathlib import Path
  import matplotlib.pyplot
  import numpy
  import pytest
  from matplotlib.colors import Colormap
  from matplotlib.figure import Figure
  from numpy.testing import assert_allclose, assert_array_equal
  from mne import MixedSourceEstimate, SourceEstimate, convert_forward_solution, make_field_map, make_sphere_model, pick_info, pick_types, read_dipole, read_evokeds, read_forward_solution, read_trans, setup_volume_source_space, use_coil_def
  from mne._fiff._digitization import write_dig
  from mne._fiff.constants import FIFF
  from mne.bem import read_bem_solution, read_bem_surfaces
  from mne.datasets import testing
  from mne.defaults import DEFAULTS
  from mne.io import read_info, read_raw_bti, read_raw_ctf, read_raw_kit, read_raw_nirx
  from mne.minimum_norm import apply_inverse
  from mne.source_estimate import _BaseVolSourceEstimate
  from mne.source_space import read_source_spaces
  from mne.transforms import Transform
  from mne.utils import _record_warnings, catch_logging
  from mne.viz import Brain, EvokedField, Figure3D, link_brains, mne_analyze_colormap, plot_alignment, plot_brain_colorbar, plot_head_positions, plot_source_estimates, plot_sparse_source_estimates, snapshot_brain_montage
  from mne.viz._3d import _get_map_ticks, _linearize_map, _process_clim
  from mne.viz.utils import _fake_click, _fake_keypress, _fake_scroll, _get_cmap
label_desc: Use image node_id 8 for calling a global function with example usage: test_plot_alignment_basic(tmp_path, renderer, mixed_fwd_cov_evoked) without return types