code: def _get_mgz_header(fname):
      """Adapted from nibabel to quickly extract header info."""
      fname = _check_fname(
          fname, overwrite="read", must_exist=True, name="MRI image"
      )
      if fname.suffix != ".mgz":
          raise OSError("Filename must end with .mgz")
      header_dtd = [
          ("version", ">i4"),
          ("dims", ">i4", (4,)),
          ("type", ">i4"),
          ("dof", ">i4"),
          ("goodRASFlag", ">i2"),
          ("delta", ">f4", (3,)),
          ("Mdc", ">f4", (3, 3)),
          ("Pxyz_c", ">f4", (3,)),
      ]
      header_dtype = np.dtype(header_dtd)
      with GzipFile(fname, "rb") as fid:
          hdr_str = fid.read(header_dtype.itemsize)
      header = np.ndarray(shape=(), dtype=header_dtype, buffer=hdr_str)
      # dims
      dims = header["dims"].astype(int)
      dims = dims[:3] if len(dims) == 4 else dims
      # vox2ras_tkr
      delta = header["delta"]
      ds = np.array(delta, float)
      ns = np.array(dims * ds) / 2.0
      v2rtkr = np.array(
          [
              [-ds[0], 0, 0, ns[0]],
              [0, 0, ds[2], -ns[2]],
              [0, -ds[1], 0, ns[1]],
              [0, 0, 0, 1],
          ],
          dtype=np.float32,
      )
      # ras2vox
      d = np.diag(delta)
      pcrs_c = dims / 2.0
      Mdc = header["Mdc"].T
      pxyz_0 = header["Pxyz_c"] - np.dot(Mdc, np.dot(d, pcrs_c))
      M = np.eye(4, 4)
      M[0:3, 0:3] = np.dot(Mdc, d)
      M[0:3, 3] = pxyz_0.T
      header = dict(
          dims=dims,
          vox2ras_tkr=v2rtkr,
          vox2ras=M,
          zooms=header["delta"],
      )
      return header
  
imports: import os.path
  from gzip import GzipFile
  from pathlib import Path
  import numpy
  from ._fiff.constants import FIFF
  from ._fiff.meas_info import read_fiducials
  from .surface import _read_mri_surface, read_surface
  from .transforms import Transform, _ensure_trans, apply_trans, combine_transforms, invert_transform, read_ras_mni_t
  from .utils import _check_fname, _check_option, _import_nibabel, _validate_type, get_subjects_dir, logger, verbose
label_desc: Use image node_id 6 for calling a global function with example usage: _get_mgz_header(fname) and returns: header