code: def _convert_channel_info(res4, t, use_eeg_pos):
      """Convert CTF channel information to fif format."""
      nmeg = neeg = nstim = nmisc = nref = 0
      chs = list()
      this_comp = None
      for k, cch in enumerate(res4["chs"]):
          cal = float(1.0 / (cch["proper_gain"] * cch["qgain"]))
          ch = dict(
              scanno=k + 1,
              range=1.0,
              cal=cal,
              loc=np.full(12, np.nan),
              unit_mul=FIFF.FIFF_UNITM_NONE,
              ch_name=cch["ch_name"][:15],
              coil_type=FIFF.FIFFV_COIL_NONE,
          )
          del k
          chs.append(ch)
          # Create the channel position information
          if cch["sensor_type_index"] in (
              CTF.CTFV_REF_MAG_CH,
              CTF.CTFV_REF_GRAD_CH,
              CTF.CTFV_MEG_CH,
          ):
              # Extra check for a valid MEG channel
              if (
                  np.sum(cch["coil"]["pos"][0] ** 2) < 1e-6
                  or np.sum(cch["coil"]["norm"][0] ** 2) < 1e-6
              ):
                  nmisc += 1
                  ch.update(
                      logno=nmisc,
                      coord_frame=FIFF.FIFFV_COORD_UNKNOWN,
                      kind=FIFF.FIFFV_MISC_CH,
                      unit=FIFF.FIFF_UNIT_V,
                  )
                  text = "MEG"
                  if cch["sensor_type_index"] != CTF.CTFV_MEG_CH:
                      text += " ref"
                  warn(
                      "%s channel %s did not have position assigned, so "
                      "it was changed to a MISC channel"
                      % (text, ch["ch_name"])
                  )
                  continue
              ch["unit"] = FIFF.FIFF_UNIT_T
              # Set up the local coordinate frame
              r0 = cch["coil"]["pos"][0].copy()
              ez = cch["coil"]["norm"][0].copy()
              # It turns out that positive proper_gain requires swapping
              # of the normal direction
              if cch["proper_gain"] > 0.0:
                  ez *= -1
              # Check how the other vectors should be defined
              off_diag = False
              # Default: ex and ey are arbitrary in the plane normal to ez
              if cch["sensor_type_index"] == CTF.CTFV_REF_GRAD_CH:
                  # The off-diagonal gradiometers are an exception:
                  #
                  # We use the same convention for ex as for Neuromag planar
                  # gradiometers: ex pointing in the positive gradient direction
                  diff = cch["coil"]["pos"][0] - cch["coil"]["pos"][1]
                  size = np.sqrt(np.sum(diff * diff))
                  if size > 0.0:
                      diff /= size
                  # Is ez normal to the line joining the coils?
                  if np.abs(np.dot(diff, ez)) < 1e-3:
                      off_diag = True
                      # Handle the off-diagonal gradiometer coordinate system
                      r0 -= size * diff / 2.0
                      ex = diff
                      ey = np.cross(ez, ex)
                  else:
                      ex, ey = _get_plane_vectors(ez)
              else:
                  ex, ey = _get_plane_vectors(ez)
              # Transform into a Neuromag-like device coordinate system
              ch["loc"] = np.concatenate(
                  [
                      apply_trans(t["t_ctf_dev_dev"], r0),
                      apply_trans(t["t_ctf_dev_dev"], ex, move=False),
                      apply_trans(t["t_ctf_dev_dev"], ey, move=False),
                      apply_trans(t["t_ctf_dev_dev"], ez, move=False),
                  ]
              )
              del r0, ex, ey, ez
              # Set the coil type
              if cch["sensor_type_index"] == CTF.CTFV_REF_MAG_CH:
                  ch["kind"] = FIFF.FIFFV_REF_MEG_CH
                  ch["coil_type"] = FIFF.FIFFV_COIL_CTF_REF_MAG
                  nref += 1
                  ch["logno"] = nref
              elif cch["sensor_type_index"] == CTF.CTFV_REF_GRAD_CH:
                  ch["kind"] = FIFF.FIFFV_REF_MEG_CH
                  if off_diag:
                      ch[
                          "coil_type"
                      ] = FIFF.FIFFV_COIL_CTF_OFFDIAG_REF_GRAD
                  else:
                      ch["coil_type"] = FIFF.FIFFV_COIL_CTF_REF_GRAD
                  nref += 1
                  ch["logno"] = nref
              else:
                  this_comp = _check_comp_ch(
                      cch, "Gradiometer", this_comp
                  )
                  ch["kind"] = FIFF.FIFFV_MEG_CH
                  ch["coil_type"] = FIFF.FIFFV_COIL_CTF_GRAD
                  nmeg += 1
                  ch["logno"] = nmeg
              # Encode the software gradiometer order
              ch["coil_type"] = int(
                  ch["coil_type"] | (cch["grad_order_no"] << 16)
              )
              ch["coord_frame"] = FIFF.FIFFV_COORD_DEVICE
          elif cch["sensor_type_index"] == CTF.CTFV_EEG_CH:
              coord_frame = FIFF.FIFFV_COORD_HEAD
              if use_eeg_pos:
                  # EEG electrode coordinates may be present but in the
                  # CTF head frame
                  ch["loc"][:3] = cch["coil"]["pos"][0]
                  if not _at_origin(ch["loc"][:3]):
                      if t["t_ctf_head_head"] is None:
                          warn(
                              "EEG electrode (%s) location omitted because of "
                              "missing HPI information" % ch["ch_name"]
                          )
                          ch["loc"].fill(np.nan)
                          coord_frame = FIFF.FIFFV_MNE_COORD_CTF_HEAD
                      else:
                          ch["loc"][:3] = apply_trans(
                              t["t_ctf_head_head"], ch["loc"][:3]
                          )
              neeg += 1
              ch.update(
                  logno=neeg,
                  kind=FIFF.FIFFV_EEG_CH,
                  unit=FIFF.FIFF_UNIT_V,
                  coord_frame=coord_frame,
                  coil_type=FIFF.FIFFV_COIL_EEG,
              )
          elif cch["sensor_type_index"] == CTF.CTFV_STIM_CH:
              nstim += 1
              ch.update(
                  logno=nstim,
                  coord_frame=FIFF.FIFFV_COORD_UNKNOWN,
                  kind=FIFF.FIFFV_STIM_CH,
                  unit=FIFF.FIFF_UNIT_V,
              )
          else:
              nmisc += 1
              ch.update(
                  logno=nmisc,
                  coord_frame=FIFF.FIFFV_COORD_UNKNOWN,
                  kind=FIFF.FIFFV_MISC_CH,
                  unit=FIFF.FIFF_UNIT_V,
              )
      return chs
  
imports: import os.path
  from calendar import timegm
  from time import strptime
  import numpy
  from ..._fiff.constants import FIFF
  from ..._fiff.ctf_comp import _add_kind, _calibrate_comp
  from ..._fiff.meas_info import _empty_info
  from ..._fiff.write import get_new_file_id
  from ...annotations import Annotations
  from ...transforms import _coord_frame_name, apply_trans, combine_transforms, invert_transform
  from ...utils import _clean_names, logger, warn
  from .constants import CTF
label_desc: Use image node_id 6 for calling a global function with example usage: _convert_channel_info(res4, t, use_eeg_pos) and returns: chs