code: def _write_proj(fid, projs, *, ch_names_mapping=None):
      """Write a projection operator to a file.
  
      Parameters
      ----------
      fid : file
          The file descriptor of the open file.
      projs : dict
          The projection operator.
      """
      if len(projs) == 0:
          return
  
      ch_names_mapping = (
          dict() if ch_names_mapping is None else ch_names_mapping
      )
      # validation
      _validate_type(projs, (list, tuple), "projs")
      for pi, proj in enumerate(projs):
          _validate_type(proj, Projection, f"projs[{pi}]")
  
      start_block(fid, FIFF.FIFFB_PROJ)
  
      for proj in projs:
          start_block(fid, FIFF.FIFFB_PROJ_ITEM)
          write_int(
              fid, FIFF.FIFF_NCHAN, len(proj["data"]["col_names"])
          )
          names = _rename_list(
              proj["data"]["col_names"], ch_names_mapping
          )
          write_name_list_sanitized(
              fid, FIFF.FIFF_PROJ_ITEM_CH_NAME_LIST, names, "col_names"
          )
          write_string(fid, FIFF.FIFF_NAME, proj["desc"])
          write_int(fid, FIFF.FIFF_PROJ_ITEM_KIND, proj["kind"])
          if proj["kind"] == FIFF.FIFFV_PROJ_ITEM_FIELD:
              write_float(fid, FIFF.FIFF_PROJ_ITEM_TIME, 0.0)
  
          write_int(fid, FIFF.FIFF_PROJ_ITEM_NVEC, proj["data"]["nrow"])
          write_int(fid, FIFF.FIFF_MNE_PROJ_ITEM_ACTIVE, proj["active"])
          write_float_matrix(
              fid, FIFF.FIFF_PROJ_ITEM_VECTORS, proj["data"]["data"]
          )
          if proj["explained_var"] is not None:
              write_float(
                  fid,
                  FIFF.FIFF_MNE_ICA_PCA_EXPLAINED_VAR,
                  proj["explained_var"],
              )
          end_block(fid, FIFF.FIFFB_PROJ_ITEM)
  
      end_block(fid, FIFF.FIFFB_PROJ)
  
imports: import re
  from copy import deepcopy
  from itertools import count
  import numpy
  from ..defaults import _BORDER_DEFAULT, _EXTRAPOLATE_DEFAULT, _INTERPOLATION_DEFAULT
  from ..fixes import _safe_svd
  from ..utils import _check_option, _validate_type, fill_doc, logger, object_diff, verbose, warn
  from .constants import FIFF
  from .pick import _ELECTRODE_CH_TYPES, _electrode_types, pick_info, pick_types
  from .tag import _rename_list, find_tag
  from .tree import dir_tree_find
  from .write import _safe_name_list, end_block, start_block, write_float, write_float_matrix, write_int, write_name_list_sanitized, write_string
label_desc: Use image node_id 3 for calling a global function with example usage: _write_proj(fid, projs) without return types