code: def compute_depth_prior(
      forward,
      info,
      exp=0.8,
      limit=10.0,
      limit_depth_chs=False,
      combine_xyz="spectral",
      noise_cov=None,
      rank=None,
      verbose=None,
  ):
      """Compute depth prior for depth weighting.
  
      Parameters
      ----------
      forward : instance of Forward
          The forward solution.
      %(info_not_none)s
      exp : float
          Exponent for the depth weighting, must be between 0 and 1.
      limit : float | None
          The upper bound on depth weighting.
          Can be None to be bounded by the largest finite prior.
      limit_depth_chs : bool | 'whiten'
          How to deal with multiple channel types in depth weighting.
          The default is True, which whitens based on the source sensitivity
          of the highest-SNR channel type. See Notes for details.
  
          .. versionchanged:: 0.18
             Added the "whiten" option.
      combine_xyz : 'spectral' | 'fro'
          When a loose (or free) orientation is used, how the depth weighting
          for each triplet should be calculated.
          If 'spectral', use the squared spectral norm of Gk.
          If 'fro', use the squared Frobenius norm of Gk.
  
          .. versionadded:: 0.18
      noise_cov : instance of Covariance | None
          The noise covariance to use to whiten the gain matrix when
          ``limit_depth_chs='whiten'``.
  
          .. versionadded:: 0.18
      %(rank_none)s
  
          .. versionadded:: 0.18
      %(verbose)s
  
      Returns
      -------
      depth_prior : ndarray, shape (n_vertices,)
          The depth prior.
  
      See Also
      --------
      compute_orient_prior
  
      Notes
      -----
      The defaults used by the minimum norm code and sparse solvers differ.
      In particular, the values for MNE are::
  
          compute_depth_prior(..., limit=10., limit_depth_chs=True,
                              combine_xyz='spectral')
  
      In sparse solvers and LCMV, the values are::
  
          compute_depth_prior(..., limit=None, limit_depth_chs='whiten',
                              combine_xyz='fro')
  
      The ``limit_depth_chs`` argument can take the following values:
  
      * :data:`python:True` (default)
            Use only grad channels in depth weighting (equivalent to MNE C
            minimum-norm code). If grad channels aren't present, only mag
            channels will be used (if no mag, then eeg). This makes the depth
            prior dependent only on the sensor geometry (and relationship
            to the sources).
      * ``'whiten'``
            Compute a whitener and apply it to the gain matrix before computing
            the depth prior. In this case ``noise_cov`` must not be None.
            Whitening the gain matrix makes the depth prior
            depend on both sensor geometry and the data of interest captured
            by the noise covariance (e.g., projections, SNR).
  
            .. versionadded:: 0.18
      * :data:`python:False`
            Use all channels. Not recommended since the depth weighting will be
            biased toward whichever channel type has the largest values in
            SI units (such as EEG being orders of magnitude larger than MEG).
      """
      from ..cov import Covariance, compute_whitener
  
      _validate_type(forward, Forward, "forward")
      patch_areas = forward.get("patch_areas", None)
      is_fixed_ori = is_fixed_orient(forward)
      G = forward["sol"]["data"]
      logger.info("Creating the depth weighting matrix...")
      _validate_type(
          noise_cov,
          (Covariance, None),
          "noise_cov",
          "Covariance or None",
      )
      _validate_type(limit_depth_chs, (str, bool), "limit_depth_chs")
      if isinstance(limit_depth_chs, str):
          if limit_depth_chs != "whiten":
              raise ValueError(
                  'limit_depth_chs, if str, must be "whiten", got '
                  "%s" % (limit_depth_chs,)
              )
          if not isinstance(noise_cov, Covariance):
              raise ValueError(
                  'With limit_depth_chs="whiten", noise_cov must be'
                  " a Covariance, got %s" % (type(noise_cov),)
              )
      if combine_xyz is not False:  # private / expert option
          _check_option("combine_xyz", combine_xyz, ("fro", "spectral"))
  
      # If possible, pick best depth-weighting channels
      if limit_depth_chs is True:
          G = _restrict_gain_matrix(G, info)
      elif limit_depth_chs == "whiten":
          whitener, _ = compute_whitener(
              noise_cov, info, pca=True, rank=rank, verbose=False
          )
          G = np.dot(whitener, G)
  
      # Compute the gain matrix
      if is_fixed_ori or combine_xyz in ("fro", False):
          d = np.sum(G**2, axis=0)
          if not (is_fixed_ori or combine_xyz is False):
              d = d.reshape(-1, 3).sum(axis=1)
          # Spherical leadfield can be zero at the center
          d[d == 0.0] = np.min(d[d != 0.0])
      else:  # 'spectral'
          # n_pos = G.shape[1] // 3
          # The following is equivalent to this, but 4-10x faster
          # d = np.zeros(n_pos)
          # for k in range(n_pos):
          #     Gk = G[:, 3 * k:3 * (k + 1)]
          #     x = np.dot(Gk.T, Gk)
          #     d[k] = linalg.svdvals(x)[0]
          G.shape = (G.shape[0], -1, 3)
          d = np.linalg.norm(
              np.einsum("svj,svk->vjk", G, G),  # vector dot prods
              ord=2,  # ord=2 spectral (largest s.v.)
              axis=(1, 2),
          )
          G.shape = (G.shape[0], -1)
  
      # XXX Currently the fwd solns never have "patch_areas" defined
      if patch_areas is not None:
          if not is_fixed_ori and combine_xyz is False:
              patch_areas = np.repeat(patch_areas, 3)
          d /= patch_areas**2
          logger.info(
              "    Patch areas taken into account in the depth "
              "weighting"
          )
  
      w = 1.0 / d
      if limit is not None:
          ws = np.sort(w)
          weight_limit = limit**2
          if limit_depth_chs is False:
              # match old mne-python behavior
              # we used to do ind = np.argmin(ws), but this is 0 by sort above
              n_limit = 0
              limit = ws[0] * weight_limit
          else:
              # match C code behavior
              limit = ws[-1]
              n_limit = len(d)
              if ws[-1] > weight_limit * ws[0]:
                  ind = np.where(ws > weight_limit * ws[0])[0][0]
                  limit = ws[ind]
                  n_limit = ind
  
          logger.info(
              "    limit = %d/%d = %f"
              % (n_limit + 1, len(d), np.sqrt(limit / ws[0]))
          )
          scale = 1.0 / limit
          logger.info("    scale = %g exp = %g" % (scale, exp))
          w = np.minimum(w / limit, 1)
      depth_prior = w**exp
  
      if not (is_fixed_ori or combine_xyz is False):
          depth_prior = np.repeat(depth_prior, 3)
  
      return depth_prior
  
imports: import os
  import re
  import shutil
  import tempfile
  from copy import deepcopy
  from os import PathLike
  from os import path
  from pathlib import Path
  from time import time
  import numpy
  from scipy import sparse
  from .._fiff.constants import FIFF
  from .._fiff.matrix import _read_named_matrix, _transpose_named_matrix, write_named_matrix
  from .._fiff.meas_info import Info, _make_ch_names_mapping, _read_bad_channels, _read_extended_ch_info, _write_bad_channels, _write_ch_infos, write_info
  from .._fiff.open import fiff_open
  from .._fiff.pick import pick_channels, pick_channels_forward, pick_info, pick_types
  from .._fiff.tag import find_tag, read_tag
  from .._fiff.tree import dir_tree_find
  from .._fiff.write import end_block, start_and_end_file, start_block, write_coord_trans, write_id, write_int, write_string
  from ..epochs import BaseEpochs
  from ..evoked import Evoked, EvokedArray
  from ..html_templates import _get_html_template
  from ..io import BaseRaw, RawArray
  from ..label import Label
  from ..source_estimate import _BaseSourceEstimate, _BaseVectorSourceEstimate
  from ..source_space._source_space import _get_src_nn, _read_source_spaces_from_tree, _set_source_space_vertices, _src_kind_dict, _write_source_spaces_to_fid, find_source_space_hemi
  from ..surface import _normal_orth
  from ..transforms import invert_transform, transform_surface_to, write_trans
  from ..utils import _check_compensation_grade, _check_fname, _check_option, _check_stc_units, _import_h5io_funcs, _on_missing, _stamp_to_dt, _validate_type, check_fname, fill_doc, get_subjects_dir, has_mne_c, logger, repr_html, run_subprocess, verbose, warn
label_desc: Use image node_id 19 for calling a global function with example usage: compute_depth_prior(forward, info, exp, limit, limit_depth_chs, combine_xyz, noise_cov, rank, verbose) and returns: depth_prior