code: def _check_head_pos(head_pos, info, first_samp, times=None):
      if head_pos is None:  # use pos from info['dev_head_t']
          head_pos = dict()
      if isinstance(head_pos, (str, Path, os.PathLike)):
          head_pos = read_head_pos(head_pos)
      if isinstance(head_pos, np.ndarray):  # can be head_pos quats
          head_pos = head_pos_to_trans_rot_t(head_pos)
      if isinstance(
          head_pos, tuple
      ):  # can be quats converted to trans, rot, t
          transs, rots, ts = head_pos
          first_time = first_samp / info["sfreq"]
          ts = ts - first_time  # MF files need reref
          dev_head_ts = [
              np.r_[np.c_[r, t[:, np.newaxis]], [[0, 0, 0, 1]]]
              for r, t in zip(rots, transs)
          ]
          del transs, rots
      elif isinstance(head_pos, dict):
          ts = np.array(list(head_pos.keys()), float)
          ts.sort()
          dev_head_ts = [head_pos[float(tt)] for tt in ts]
      else:
          raise TypeError("unknown head_pos type %s" % type(head_pos))
      bad = ts < 0
      if bad.any():
          raise RuntimeError(
              "All position times must be >= 0, found %s/%s"
              "< 0" % (bad.sum(), len(bad))
          )
      if times is not None:
          bad = ts > times[-1]
          if bad.any():
              raise RuntimeError(
                  "All position times must be <= t_end (%0.1f "
                  "s), found %s/%s bad values (is this a split "
                  "file?)" % (times[-1], bad.sum(), len(bad))
              )
      # If it starts close to zero, make it zero (else unique(offset) fails)
      if len(ts) > 0 and ts[0] < (0.5 / info["sfreq"]):
          ts[0] = 0.0
      # If it doesn't start at zero, insert one at t=0
      elif len(ts) == 0 or ts[0] > 0:
          ts = np.r_[[0.0], ts]
          dev_head_ts.insert(0, info["dev_head_t"]["trans"])
      dev_head_ts = [
          {
              "trans": d,
              "to": info["dev_head_t"]["to"],
              "from": info["dev_head_t"]["from"],
          }
          for d in dev_head_ts
      ]
      offsets = np.round(ts * info["sfreq"]).astype(int)
      assert np.array_equal(offsets, np.unique(offsets))
      assert len(offsets) == len(dev_head_ts)
      offsets = list(offsets)
      return dev_head_ts, offsets
  
imports: import os
  from collections.abc import Iterable
  from pathlib import Path
  import numpy
  from .._fiff.constants import FIFF
  from .._fiff.meas_info import Info
  from .._fiff.pick import pick_channels, pick_channels_forward, pick_info, pick_types
  from .._ola import _Interp2
  from ..bem import fit_sphere_to_headshape, make_sphere_model, read_bem_solution
  from ..chpi import _get_hpi_initial_fit, get_chpi_info, head_pos_to_trans_rot_t, read_head_pos
  from ..cov import Covariance, make_ad_hoc_cov, read_cov
  from ..event import _get_stim_channel
  from ..forward import _compute_forwards, _magnetic_dipole_field_vec, _merge_fwds, _prep_meg_channels, _prepare_for_forward, _stc_src_sel, _to_forward_dict, _transform_orig_meg_coils, convert_forward_solution, restrict_forward_to_stc
  from ..io import BaseRaw, RawArray
  from ..source_estimate import _BaseSourceEstimate
  from ..source_space._source_space import _ensure_src, _set_source_space_vertices, setup_volume_source_space
  from ..surface import _CheckInside
  from ..transforms import _get_trans, transform_surface_to
  from ..utils import _check_preload, _pl, _validate_type, check_random_state, logger, verbose
  from .source import SourceSimulator
label_desc: Use image node_id 4 for calling a global function with example usage: _check_head_pos(head_pos, info, first_samp, times) and returns: dev_head_ts,  offsets