code: def test_lcmv_reg_proj(proj, weight_norm):
      """Test LCMV with and without proj."""
      raw = mne.io.read_raw_fif(fname_raw, preload=True)
      events = mne.find_events(raw)
      raw.pick(picks="meg", exclude="bads")
      assert len(raw.ch_names) == 305
      epochs = mne.Epochs(raw, events, None, preload=True, proj=proj)
      with pytest.warns(RuntimeWarning, match="Too few samples"):
          noise_cov = mne.compute_covariance(epochs, tmax=0)
          data_cov = mne.compute_covariance(
              epochs, tmin=0.04, tmax=0.15
          )
      forward = mne.read_forward_solution(fname_fwd)
      filters = make_lcmv(
          epochs.info,
          forward,
          data_cov,
          reg=0.05,
          noise_cov=noise_cov,
          pick_ori="max-power",
          weight_norm="nai",
          rank=None,
          verbose=True,
      )
      want_rank = 302  # 305 good channels - 3 MEG projs
      assert filters["rank"] == want_rank
      # And also with and without noise_cov
      with pytest.raises(ValueError, match="several sensor types"):
          make_lcmv(
              epochs.info, forward, data_cov, reg=0.05, noise_cov=None
          )
      epochs.pick(picks="grad")
      kwargs = dict(reg=0.05, pick_ori=None, weight_norm=weight_norm)
      filters_cov = make_lcmv(
          epochs.info, forward, data_cov, noise_cov=noise_cov, **kwargs
      )
      filters_nocov = make_lcmv(
          epochs.info, forward, data_cov, noise_cov=None, **kwargs
      )
      ad_hoc = mne.make_ad_hoc_cov(epochs.info)
      filters_adhoc = make_lcmv(
          epochs.info, forward, data_cov, noise_cov=ad_hoc, **kwargs
      )
      evoked = epochs.average()
      stc_cov = apply_lcmv(evoked, filters_cov)
      stc_nocov = apply_lcmv(evoked, filters_nocov)
      stc_adhoc = apply_lcmv(evoked, filters_adhoc)
  
      # Compare adhoc and nocov: scale difference is necessitated by using std=1.
      if weight_norm == "unit-noise-gain":
          scale = np.sqrt(ad_hoc["data"][0])
      else:
          scale = 1.0
      assert_allclose(stc_nocov.data, stc_adhoc.data * scale)
      a = np.dot(filters_nocov["weights"], filters_nocov["whitener"])
      b = (
          np.dot(filters_adhoc["weights"], filters_adhoc["whitener"])
          * scale
      )
      atol = np.mean(np.sqrt(a * a)) * 1e-7
      assert_allclose(a, b, atol=atol, rtol=1e-7)
  
      # Compare adhoc and cov: locs might not be equivalent, but the same
      # general profile should persist, so look at the std and be lenient:
      if weight_norm == "unit-noise-gain":
          adhoc_scale = 0.12
      else:
          adhoc_scale = 1.0
      assert_allclose(
          np.linalg.norm(stc_adhoc.data, axis=0) * adhoc_scale,
          np.linalg.norm(stc_cov.data, axis=0),
          rtol=0.3,
      )
      assert_allclose(
          np.linalg.norm(stc_nocov.data, axis=0) / scale * adhoc_scale,
          np.linalg.norm(stc_cov.data, axis=0),
          rtol=0.3,
      )
  
      if weight_norm == "nai":
          # NAI is always normalized by noise-level (based on eigenvalues)
          for stc in (stc_nocov, stc_cov):
              assert_allclose(stc.data.std(), 0.584, rtol=0.2)
      elif weight_norm is None:
          # None always represents something not normalized, reflecting channel
          # weights
          for stc in (stc_nocov, stc_cov):
              assert_allclose(stc.data.std(), 2.8e-8, rtol=0.1)
      else:
          assert weight_norm == "unit-noise-gain"
          # Channel scalings depend on presence of noise_cov
          assert_allclose(stc_nocov.data.std(), 7.8e-13, rtol=0.1)
          assert_allclose(stc_cov.data.std(), 0.187, rtol=0.2)
  
imports: from contextlib import nullcontext
  from copy import deepcopy
  from inspect import signature
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_array_less
  from scipy import linalg
  from scipy.spatial.distance import cdist
  import mne
  from mne import EvokedArray, VolSourceEstimate, VolVectorSourceEstimate, compute_rank, convert_forward_solution, pick_channels_cov, read_forward_solution, read_vectorview_selection
  from mne._fiff.compensator import set_current_comp
  from mne._fiff.constants import FIFF
  from mne.beamformer import Beamformer, apply_lcmv, apply_lcmv_cov, apply_lcmv_epochs, apply_lcmv_raw, make_dics, make_lcmv, read_beamformer
  from mne.beamformer._compute_beamformer import _prepare_beamformer_input
  from mne.datasets import testing
  from mne.minimum_norm import apply_inverse, make_inverse_operator
  from mne.minimum_norm.tests.test_inverse import _assert_free_ori_match
  from mne.simulation import simulate_evoked
  from mne.transforms import apply_trans, invert_transform
  from mne.utils import _record_warnings, catch_logging, object_diff
label_desc: Use image node_id 8 for calling a global function with example usage: test_lcmv_reg_proj(proj, weight_norm) without return types