code: def test_as_meg_type_evoked():
      """Test interpolation of data on to virtual channels."""
      # validation tests
      raw = read_raw_fif(raw_fname)
      events = mne.find_events(raw)
      picks = pick_types(
          raw.info,
          meg=True,
          eeg=True,
          stim=True,
          ecg=True,
          eog=True,
          include=["STI 014"],
          exclude="bads",
      )
      epochs = mne.Epochs(raw, events, picks=picks)
      evoked = epochs.average()
  
      with pytest.raises(
          ValueError, match="Invalid value for the 'ch_type'"
      ):
          evoked.as_type("meg")
      with pytest.raises(
          ValueError, match="Invalid value for the 'ch_type'"
      ):
          evoked.copy().pick(picks="grad").as_type("meg")
  
      # channel names
      ch_names = evoked.info["ch_names"]
      virt_evoked = evoked.copy().pick(ch_names[:10:1])
      virt_evoked.info.normalize_proj()
      virt_evoked = virt_evoked.as_type("mag")
      assert all(
          ch.endswith("_v") for ch in virt_evoked.info["ch_names"]
      )
  
      # pick from and to channels
      evoked_from = evoked.copy().pick(ch_names[2:10:3])
      evoked_to = evoked.copy().pick(ch_names[0:10:3])
  
      info_from, info_to = evoked_from.info, evoked_to.info
  
      # set up things
      args1, args2 = _setup_args(info_from), _setup_args(info_to)
      args1.update(coils2=args2["coils1"])
      args2.update(coils2=args1["coils1"])
  
      # test cross dots
      cross_dots1 = _do_cross_dots(**args1)
      cross_dots2 = _do_cross_dots(**args2)
  
      assert_array_almost_equal(cross_dots1, cross_dots2.T)
  
      # correlation test
      evoked = evoked.pick(ch_names[:10:]).copy()
      data1 = evoked.pick("grad").data.ravel()
      data2 = evoked.as_type("grad").data.ravel()
      assert np.corrcoef(data1, data2)[0, 1] > 0.95
  
      # Do it with epochs
      virt_epochs = epochs.copy().load_data().pick(ch_names[:10:1])
      virt_epochs.info.normalize_proj()
      virt_epochs = virt_epochs.as_type("mag")
      assert all(
          ch.endswith("_v") for ch in virt_epochs.info["ch_names"]
      )
      assert_allclose(
          virt_epochs.get_data(copy=False).mean(0), virt_evoked.data
      )
  
imports: from os import path
  from pathlib import Path
  import numpy
  import pytest
  from numpy.polynomial import legendre
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal, assert_equal
  from scipy.interpolate import interp1d
  import mne
  from mne import Epochs, make_fixed_length_events, pick_types, read_evokeds
  from mne.datasets import testing
  from mne.forward import _make_surface_mapping, make_field_map
  from mne.forward._field_interpolation import _setup_dots
  from mne.forward._lead_dots import _comp_sum_eeg, _comp_sums_meg, _do_cross_dots, _get_legen_table
  from mne.forward._make_forward import _create_meg_coils
  from mne.io import read_raw_fif
  from mne.surface import get_head_surf, get_meg_helmet_surf
label_desc: Use image node_id 8 for calling a global function with example usage: test_as_meg_type_evoked() without return types