code: def compute_dev_head_t(montage):
      """Compute device to head transform from a DigMontage.
  
      Parameters
      ----------
      montage : DigMontage
          The `~mne.channels.DigMontage` must contain the fiducials in head
          coordinate system and hpi points in both head and
          meg device coordinate system.
  
      Returns
      -------
      dev_head_t : Transform
          A Device-to-Head transformation matrix.
      """
      _, coord_frame = _get_fid_coords(montage.dig)
      if coord_frame != FIFF.FIFFV_COORD_HEAD:
          raise ValueError(
              "montage should have been set to head coordinate "
              "system with transform_to_head function."
          )
  
      hpi_head = np.array(
          [
              d["r"]
              for d in montage.dig
              if (
                  d["kind"] == FIFF.FIFFV_POINT_HPI
                  and d["coord_frame"] == FIFF.FIFFV_COORD_HEAD
              )
          ],
          float,
      )
      hpi_dev = np.array(
          [
              d["r"]
              for d in montage.dig
              if (
                  d["kind"] == FIFF.FIFFV_POINT_HPI
                  and d["coord_frame"] == FIFF.FIFFV_COORD_DEVICE
              )
          ],
          float,
      )
  
      if not (len(hpi_head) == len(hpi_dev) and len(hpi_dev) > 0):
          raise ValueError(
              (
                  "To compute Device-to-Head transformation, the same number of HPI"
                  " points in device and head coordinates is required. (Got {dev}"
                  " points in device and {head} points in head coordinate systems)"
              ).format(dev=len(hpi_dev), head=len(hpi_head))
          )
  
      trans = _quat_to_affine(_fit_matched_points(hpi_dev, hpi_head)[0])
      return Transform(fro="meg", to="head", trans=trans)
  
imports: import os.path
  import re
  from collections import OrderedDict
  from copy import deepcopy
  from dataclasses import dataclass
  import numpy
  from .._fiff._digitization import _coord_frame_const, _count_points_by_type, _ensure_fiducials_head, _format_dig_points, _get_data_as_dict_from_dig, _get_dig_eeg, _get_fid_coords, _make_dig_points, _read_dig_fif, write_dig
  from .._fiff.constants import CHANNEL_LOC_ALIASES, FIFF
  from .._fiff.meas_info import create_info
  from .._fiff.open import fiff_open
  from .._fiff.pick import _picks_to_idx, channel_type, pick_types
  from .._freesurfer import get_mni_fiducials
  from ..defaults import HEAD_SIZE_DEFAULT
  from ..transforms import Transform, _ensure_trans, _fit_matched_points, _frame_to_str, _quat_to_affine, _sph_to_cart, _topo_to_sph, _verbose_frames, apply_trans, get_ras_to_neuromag_trans
  from ..utils import _check_fname, _check_option, _on_missing, _pl, _validate_type, copy_function_doc_to_method_doc, fill_doc, verbose, warn
  from ..utils.docs import docdict
  from ..viz import plot_montage
  from ._dig_montage_utils import _parse_brainvision_dig_montage, _read_dig_montage_egi
label_desc: Use image node_id 22 for calling a global function with example usage: compute_dev_head_t(montage) and returns: Transform