code: def test_apply_inverse_operator(evoked, inv, min_, max_):
      """Test MNE inverse application."""
      # use fname_inv as it will be faster than fname_full (fewer verts and chs)
      inverse_operator = read_inverse_operator(inv)
  
      # Inverse has 306 channels - 4 proj = 302
      assert compute_rank_inverse(inverse_operator) == 302
  
      # Inverse has 306 channels - 4 proj = 302
      assert compute_rank_inverse(inverse_operator) == 302
  
      stc = apply_inverse(evoked, inverse_operator, lambda2, "MNE")
      assert stc.subject == "sample"
      assert stc.data.min() > min_
      assert stc.data.max() < max_
      assert abs(stc).data.mean() > 1e-11
  
      # test if using prepared and not prepared inverse operator give the same
      # result
      inv_op = prepare_inverse_operator(
          inverse_operator,
          nave=evoked.nave,
          lambda2=lambda2,
          method="MNE",
      )
      stc2 = apply_inverse(evoked, inv_op, lambda2, "MNE")
      assert_array_almost_equal(stc.data, stc2.data)
      assert_array_almost_equal(stc.times, stc2.times)
  
      # This is little more than a smoke test...
      stc = apply_inverse(evoked, inverse_operator, lambda2, "sLORETA")
      assert stc.subject == "sample"
      assert abs(stc).data.min() > 0
      assert 2 < stc.data.max() < 7
      assert abs(stc).data.mean() > 0.1
  
      stc = apply_inverse(evoked, inverse_operator, lambda2, "eLORETA")
      assert stc.subject == "sample"
      assert abs(stc).data.min() > min_
      assert stc.data.max() < max_ * 2
      assert abs(stc).data.mean() > 1e-11
  
      stc = apply_inverse(evoked, inverse_operator, lambda2, "dSPM")
      assert stc.subject == "sample"
      assert abs(stc).data.min() > 0
      assert 7.5 < stc.data.max() < 15
      assert abs(stc).data.mean() > 0.1
  
      # test without using a label (so delayed computation is used)
      label = read_label(str(fname_label) % "Aud-lh")
      for method in INVERSE_METHODS:
          stc = apply_inverse(evoked, inv_op, lambda2, method)
          stc_label = apply_inverse(
              evoked, inv_op, lambda2, method, label=label
          )
          assert_equal(stc_label.subject, "sample")
          label_stc = stc.in_label(label)
          assert label_stc.subject == "sample"
          assert_allclose(stc_label.data, label_stc.data)
  
      # Test that no errors are raised with loose inverse ops and picking normals
      noise_cov = read_cov(fname_cov)
      fwd = read_forward_solution_meg(fname_fwd)
      inv_op_meg = make_inverse_operator(
          evoked.info, fwd, noise_cov, loose=1, fixed="auto", depth=None
      )
      apply_inverse(
          evoked, inv_op_meg, 1 / 9.0, method="MNE", pick_ori="normal"
      )
  
      # Test type checking
      with pytest.raises(
          TypeError, match="must be an instance of Evoked"
      ):
          apply_inverse(
              mne.EpochsArray(evoked.data[np.newaxis], evoked.info),
              inv_op,
          )
      with pytest.raises(
          TypeError, match="must be an instance of Evoked"
      ):
          apply_inverse(
              mne.io.RawArray(evoked.data, evoked.info), inv_op
          )
  
      # Test we get errors when using custom ref or no average proj is present
      with evoked.info._unlock():
          evoked.info["custom_ref_applied"] = True
      with pytest.raises(ValueError, match="Custom EEG reference"):
          apply_inverse(evoked, inv_op, lambda2, "MNE")
      with evoked.info._unlock():
          evoked.info["custom_ref_applied"] = False
          evoked.info["projs"] = []  # remove EEG proj
      with pytest.raises(
          ValueError, match="EEG average reference.*mandatory"
      ):
          apply_inverse(evoked, inv_op, lambda2, "MNE")
  
      # But test that we do not get EEG-related errors on MEG-only inv (gh-4650)
      apply_inverse(evoked, inv_op_meg, 1.0 / 9.0)
  
imports: import copy
  import re
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_array_less, assert_equal
  from scipy import sparse
  import mne
  from mne import Covariance, EvokedArray, SourceEstimate, combine_evoked, compute_raw_covariance, convert_forward_solution, make_ad_hoc_cov, make_forward_solution, make_sphere_model, pick_channels_forward, pick_types, pick_types_forward, read_cov, read_evokeds, read_forward_solution
  from mne.datasets import testing
  from mne.epochs import Epochs, EpochsArray, make_fixed_length_epochs
  from mne.event import read_events
  from mne.forward import apply_forward, is_fixed_orient, restrict_forward_to_stc
  from mne.io import read_info, read_raw_fif
  from mne.label import label_sign_flip, read_label
  from mne.minimum_norm import INVERSE_METHODS, apply_inverse, apply_inverse_cov, apply_inverse_epochs, apply_inverse_raw, apply_inverse_tfr_epochs, compute_rank_inverse, make_inverse_operator, prepare_inverse_operator, read_inverse_operator, write_inverse_operator
  from mne.source_estimate import VolSourceEstimate, read_source_estimate
  from mne.source_space._source_space import _get_src_nn
  from mne.surface import _normal_orth
  from mne.time_frequency import EpochsTFR
  from mne.utils import _record_warnings, catch_logging
label_desc: Use image node_id 14 for calling a global function with example usage: test_apply_inverse_operator(evoked, inv, min_, max_) without return types