code: def grade_to_vertices(
      subject, grade, subjects_dir=None, n_jobs=None, verbose=None
  ):
      """Convert a grade to source space vertices for a given subject.
  
      Parameters
      ----------
      subject : str
          Name of the subject.
      grade : int | list
          Resolution of the icosahedral mesh (typically 5). If None, all
          vertices will be used (potentially filling the surface). If a list,
          then values will be morphed to the set of vertices specified in
          in grade[0] and grade[1]. Note that specifying the vertices (e.g.,
          grade=[np.arange(10242), np.arange(10242)] for fsaverage on a
          standard grade 5 source space) can be substantially faster than
          computing vertex locations. Note that if subject='fsaverage'
          and 'grade=5', this set of vertices will automatically be used
          (instead of computed) for speed, since this is a common morph.
      %(subjects_dir)s
      %(n_jobs)s
      %(verbose)s
  
      Returns
      -------
      vertices : list of array of int
          Vertex numbers for LH and RH.
      """
      _validate_type(grade, (list, "int-like", None), "grade")
      # add special case for fsaverage for speed
      if (
          subject == "fsaverage"
          and isinstance(grade, int)
          and grade == 5
      ):
          return [np.arange(10242), np.arange(10242)]
      subjects_dir = get_subjects_dir(subjects_dir, raise_error=True)
  
      spheres_to = [
          subjects_dir / subject / "surf" / (xh + ".sphere.reg")
          for xh in ["lh", "rh"]
      ]
      lhs, rhs = (read_surface(s)[0] for s in spheres_to)
  
      if grade is not None:  # fill a subset of vertices
          if isinstance(grade, list):
              if not len(grade) == 2:
                  raise ValueError(
                      "grade as a list must have two elements "
                      "(arrays of output vertices)"
                  )
              vertices = grade
          else:
              grade = _ensure_int(grade)
              # find which vertices to use in "to mesh"
              ico = _get_ico_tris(grade, return_surf=True)
              lhs /= np.sqrt(np.sum(lhs**2, axis=1))[:, None]
              rhs /= np.sqrt(np.sum(rhs**2, axis=1))[:, None]
  
              # Compute nearest vertices in high dim mesh
              parallel, my_compute_nearest, _ = parallel_func(
                  _compute_nearest, n_jobs
              )
              lhs, rhs, rr = (
                  a.astype(np.float32) for a in [lhs, rhs, ico["rr"]]
              )
              vertices = parallel(
                  my_compute_nearest(xhs, rr) for xhs in [lhs, rhs]
              )
              # Make sure the vertices are ordered
              vertices = [np.sort(verts) for verts in vertices]
              for verts in vertices:
                  if (np.diff(verts) == 0).any():
                      raise ValueError(
                          "Cannot use icosahedral grade %s with subject %s, "
                          "mapping %s vertices onto the high-resolution mesh "
                          "yields repeated vertices, use a lower grade or a "
                          "list of vertices from an existing source space"
                          % (grade, subject, len(verts))
                      )
      else:  # potentially fill the surface
          vertices = [np.arange(lhs.shape[0]), np.arange(rhs.shape[0])]
  
      return vertices
  
imports: import copy
  import os.path
  import warnings
  import numpy
  from scipy import sparse
  from .fixes import _get_img_fdata
  from .morph_map import read_morph_map
  from .parallel import parallel_func
  from .source_estimate import _BaseSourceEstimate, _BaseSurfaceSourceEstimate, _BaseVolSourceEstimate, _get_ico_tris
  from .source_space._source_space import SourceSpaces, _ensure_src, _grid_interp
  from .surface import _compute_nearest, mesh_edges, read_surface
  from .utils import BunchConst, ProgressBar, _check_fname, _check_option, _custom_lru_cache, _ensure_int, _import_h5io_funcs, _import_nibabel, _validate_type, check_version, fill_doc, get_subjects_dir, logger, use_log_level, verbose, warn
  from .utils import warn
label_desc: Use image node_id 16 for calling a global function with example usage: grade_to_vertices(subject, grade, subjects_dir, n_jobs, verbose) and returns: vertices, list