code: def _write_inverse_operator(fid, inv):
      start_block(fid, FIFF.FIFFB_MNE)
  
      #
      #   Parent MEG measurement info
      #
      write_forward_meas_info(fid, inv["info"])
  
      #
      #   Parent MRI data
      #
      start_block(fid, FIFF.FIFFB_MNE_PARENT_MRI_FILE)
      write_string(
          fid, FIFF.FIFF_MNE_FILE_NAME, inv["info"]["mri_file"]
      )
      write_coord_trans(fid, inv["mri_head_t"])
      end_block(fid, FIFF.FIFFB_MNE_PARENT_MRI_FILE)
  
      #
      #   Write SSP operator
      #
      _write_proj(fid, inv["projs"])
  
      #
      #   Write the source spaces
      #
      if "src" in inv:
          _write_source_spaces_to_fid(fid, inv["src"])
  
      start_block(fid, FIFF.FIFFB_MNE_INVERSE_SOLUTION)
  
      logger.info("    Writing inverse operator info...")
  
      write_int(fid, FIFF.FIFF_MNE_INCLUDED_METHODS, inv["methods"])
      write_int(fid, FIFF.FIFF_MNE_COORD_FRAME, inv["coord_frame"])
  
      udict = {
          "Am": FIFF.FIFF_UNIT_AM,
          "Am/m^2": FIFF.FIFF_UNIT_AM_M2,
          "Am/m^3": FIFF.FIFF_UNIT_AM_M3,
      }
      if "units" in inv and inv["units"] is not None:
          write_int(
              fid,
              FIFF.FIFF_MNE_INVERSE_SOURCE_UNIT,
              udict[inv["units"]],
          )
  
      write_int(
          fid, FIFF.FIFF_MNE_SOURCE_ORIENTATION, inv["source_ori"]
      )
      write_int(fid, FIFF.FIFF_MNE_SOURCE_SPACE_NPOINTS, inv["nsource"])
      if "nchan" in inv:
          write_int(fid, FIFF.FIFF_NCHAN, inv["nchan"])
      elif "nchan" in inv["info"]:
          write_int(fid, FIFF.FIFF_NCHAN, inv["info"]["nchan"])
      write_float_matrix(
          fid,
          FIFF.FIFF_MNE_INVERSE_SOURCE_ORIENTATIONS,
          inv["source_nn"],
      )
      write_float(fid, FIFF.FIFF_MNE_INVERSE_SING, inv["sing"])
  
      #
      #   write the covariance matrices
      #
      logger.info("    Writing noise covariance matrix.")
      _write_cov(fid, inv["noise_cov"])
  
      logger.info("    Writing source covariance matrix.")
      _write_cov(fid, inv["source_cov"])
  
      #
      #   write the various priors
      #
      logger.info("    Writing orientation priors.")
      if inv["depth_prior"] is not None:
          _write_cov(fid, inv["depth_prior"])
      if inv["orient_prior"] is not None:
          _write_cov(fid, inv["orient_prior"])
      if inv["fmri_prior"] is not None:
          _write_cov(fid, inv["fmri_prior"])
  
      write_named_matrix(
          fid, FIFF.FIFF_MNE_INVERSE_FIELDS, inv["eigen_fields"]
      )
  
      #
      #   The eigenleads and eigenfields
      #
      if inv["eigen_leads_weighted"]:
          kind = FIFF.FIFF_MNE_INVERSE_LEADS_WEIGHTED
      else:
          kind = FIFF.FIFF_MNE_INVERSE_LEADS
      _transpose_named_matrix(inv["eigen_leads"])
      write_named_matrix(fid, kind, inv["eigen_leads"])
      _transpose_named_matrix(inv["eigen_leads"])
  
      #
      #   Done!
      #
      logger.info("    [done]")
  
      end_block(fid, FIFF.FIFFB_MNE_INVERSE_SOLUTION)
      end_block(fid, FIFF.FIFFB_MNE)
  
imports: from copy import deepcopy
  from math import sqrt
  import numpy
  from scipy import linalg
  from scipy.stats import chi2
  from .._fiff.constants import FIFF
  from .._fiff.matrix import _read_named_matrix, _transpose_named_matrix, write_named_matrix
  from .._fiff.open import fiff_open
  from .._fiff.pick import channel_type, pick_channels, pick_info, pick_types
  from .._fiff.proj import _electrode_types, _needs_eeg_average_ref_proj, _read_proj, _write_proj, make_projector
  from .._fiff.tag import find_tag
  from .._fiff.tree import dir_tree_find
  from .._fiff.write import end_block, start_and_end_file, start_block, write_coord_trans, write_float, write_float_matrix, write_int, write_string
  from ..cov import Covariance, _read_cov, _write_cov, compute_whitener, prepare_noise_cov
  from ..epochs import BaseEpochs, EpochsArray
  from ..evoked import Evoked, EvokedArray
  from ..fixes import _safe_svd
  from ..forward import _read_forward_meas_info, _select_orient_forward, compute_depth_prior, compute_orient_prior, convert_forward_solution, is_fixed_orient
  from ..forward.forward import _triage_loose, write_forward_meas_info
  from ..html_templates import _get_html_template
  from ..io import BaseRaw
  from ..source_estimate import _get_src_type, _make_stc
  from ..source_space._source_space import _get_src_nn, _get_vertno, _read_source_spaces_from_tree, _write_source_spaces_to_fid, find_source_space_hemi, label_src_vertno_sel
  from ..surface import _normal_orth
  from ..time_frequency.tfr import _check_tfr_complex
  from ..transforms import _ensure_trans, transform_surface_to
  from ..utils import _check_compensation_grade, _check_depth, _check_fname, _check_option, _check_src_normal, _validate_type, _verbose_safe_false, check_fname, logger, repr_html, verbose, warn
  from ._eloreta import _compute_eloreta
label_desc: Use image node_id 4 for calling a global function with example usage: _write_inverse_operator(fid, inv) without return types