code: def test_dipole_fitting_fixed(tmp_path):
      """Test dipole fitting with a fixed position."""
      tpeak = 0.073
      sphere = make_sphere_model(head_radius=0.1)
      evoked = read_evokeds(fname_evo, baseline=(None, 0))[0]
      evoked.pick("meg")
      t_idx = np.argmin(np.abs(tpeak - evoked.times))
      evoked_crop = evoked.copy().crop(tpeak, tpeak)
      assert len(evoked_crop.times) == 1
      cov = read_cov(fname_cov)
      dip_seq, resid = fit_dipole(evoked_crop, cov, sphere)
      assert isinstance(dip_seq, Dipole)
      assert isinstance(resid, Evoked)
      assert len(dip_seq.times) == 1
      pos, ori, gof = dip_seq.pos[0], dip_seq.ori[0], dip_seq.gof[0]
      amp = dip_seq.amplitude[0]
      # Fix position, allow orientation to change
      dip_free, resid_free = fit_dipole(evoked, cov, sphere, pos=pos)
      assert isinstance(dip_free, Dipole)
      assert isinstance(resid_free, Evoked)
      assert_allclose(dip_free.times, evoked.times)
      assert_allclose(
          np.tile(pos[np.newaxis], (len(evoked.times), 1)), dip_free.pos
      )
      assert_allclose(ori, dip_free.ori[t_idx])  # should find same ori
      assert np.dot(dip_free.ori, ori).mean() < 0.9  # but few the same
      assert_allclose(gof, dip_free.gof[t_idx])  # ... same gof
      assert_allclose(amp, dip_free.amplitude[t_idx])  # and same amp
      assert_allclose(resid.data, resid_free.data[:, [t_idx]])
      # Fix position and orientation
      dip_fixed, resid_fixed = fit_dipole(
          evoked, cov, sphere, pos=pos, ori=ori
      )
      assert isinstance(dip_fixed, DipoleFixed)
      assert_allclose(dip_fixed.times, evoked.times)
      assert_allclose(dip_fixed.info["chs"][0]["loc"][:3], pos)
      assert_allclose(dip_fixed.info["chs"][0]["loc"][3:6], ori)
      assert_allclose(dip_fixed.data[1, t_idx], gof)
      assert_allclose(resid.data, resid_fixed.data[:, [t_idx]])
      _check_roundtrip_fixed(dip_fixed, tmp_path)
      # bad resetting
      evoked.info["bads"] = [evoked.ch_names[3]]
      dip_fixed, resid_fixed = fit_dipole(
          evoked, cov, sphere, pos=pos, ori=ori
      )
      # Degenerate conditions
      evoked_nan = evoked.copy().crop(0, 0)
      evoked_nan.data[0, 0] = None
      pytest.raises(ValueError, fit_dipole, evoked_nan, cov, sphere)
      pytest.raises(
          ValueError, fit_dipole, evoked, cov, sphere, ori=[1, 0, 0]
      )
      pytest.raises(
          ValueError,
          fit_dipole,
          evoked,
          cov,
          sphere,
          pos=[0, 0, 0],
          ori=[2, 0, 0],
      )
      pytest.raises(
          ValueError, fit_dipole, evoked, cov, sphere, pos=[0.1, 0, 0]
      )
      # copying
      dip_fixed_2 = dip_fixed.copy()
      dip_fixed_2.data[:] = 0.0
      assert not np.isclose(dip_fixed.data, 0.0, atol=1e-20).any()
      # plotting
      plt.close("all")
      dip_fixed.plot()
      plt.close("all")
      orig_times = np.array(dip_fixed.times)
      shift_times = dip_fixed.shift_time(1.0).times
      assert_allclose(shift_times, orig_times + 1)
  
imports: import os
  import matplotlib.pyplot
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_array_less
  from mne import Dipole, DipoleFixed, Epochs, Evoked, EvokedArray, SourceEstimate, convert_forward_solution, fit_dipole, head_to_mni, make_ad_hoc_cov, make_fixed_length_events, make_forward_solution, make_sphere_model, pick_info, pick_types, read_cov, read_dipole, read_evokeds, read_forward_solution, read_source_spaces, transform_surface_to, write_evokeds
  from mne._fiff.constants import FIFF
  from mne.bem import _bem_find_surface, read_bem_solution
  from mne.datasets import testing
  from mne.dipole import _BDIP_ERROR_KEYS, get_phantom_dipoles
  from mne.io import read_raw_ctf, read_raw_fif
  from mne.proj import make_eeg_average_ref_proj
  from mne.simulation import simulate_evoked
  from mne.surface import _compute_nearest
  from mne.transforms import _get_trans, apply_trans
  from mne.utils import _record_warnings, requires_mne, run_subprocess
label_desc: Use image node_id 6 for calling a global function with example usage: test_dipole_fitting_fixed(tmp_path) without return types