code: def test_add_source_space_distances_limited(tmp_path):
      """Test adding distances to source space with a dist_limit."""
      src = read_source_spaces(fname)
      src_new = read_source_spaces(fname)
      del src_new[0]["dist"]
      del src_new[1]["dist"]
      n_do = 200  # limit this for speed
      src_new[0]["vertno"] = src_new[0]["vertno"][:n_do].copy()
      src_new[1]["vertno"] = src_new[1]["vertno"][:n_do].copy()
      out_name = tmp_path / "temp-src.fif"
      add_source_space_distances(src_new, dist_limit=0.007)
      write_source_spaces(out_name, src_new)
      src_new = read_source_spaces(out_name)
  
      for so, sn in zip(src, src_new):
          assert_array_equal(
              so["dist_limit"], np.array([-0.007], np.float32)
          )
          assert_array_equal(
              sn["dist_limit"], np.array([0.007], np.float32)
          )
          do = so["dist"]
          dn = sn["dist"]
  
          # clean out distances > 0.007 in C code
          do.data[do.data > 0.007] = 0
          do.eliminate_zeros()
  
          # make sure we have some comparable distances
          assert np.sum(do.data < 0.007) > 400
  
          # do comparison over the region computed
          d = (do - dn)[: sn["vertno"][n_do - 1]][
              :, : sn["vertno"][n_do - 1]
          ]
          assert_allclose(
              np.zeros_like(d.data), d.data, rtol=0, atol=1e-6
          )
  
imports: from pathlib import Path
  from shutil import copytree
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_array_less, assert_equal
  import mne
  from mne import SourceEstimate, add_source_space_distances, compute_source_morph, get_volume_labels_from_src, make_sphere_model, morph_source_spaces, pick_types, read_bem_solution, read_bem_surfaces, read_freesurfer_lut, read_source_spaces, read_trans, setup_source_space, setup_volume_source_space, write_source_spaces
  from mne._fiff.constants import FIFF
  from mne._fiff.pick import _picks_to_idx
  from mne.datasets import testing
  from mne.fixes import _get_img_fdata
  from mne.source_estimate import _get_src_type
  from mne.source_space import compute_distance_to_sensors, get_decimated_surfaces
  from mne.source_space._source_space import _compare_source_spaces
  from mne.surface import _accumulate_normals, _triangle_neighbors
  from mne.utils import _record_warnings, requires_mne, run_subprocess
label_desc: Use image node_id 5 for calling a global function with example usage: test_add_source_space_distances_limited(tmp_path) without return types