code: def _prepare_gain(
      forward,
      info,
      noise_cov,
      pca,
      depth,
      loose,
      rank,
      weights=None,
      weights_min=None,
  ):
      depth = _check_depth(depth, "depth_sparse")
      (
          forward,
          gain_info,
          gain,
          _,
          _,
          source_weighting,
          _,
          _,
          whitener,
      ) = _prepare_forward(
          forward,
          info,
          noise_cov,
          "auto",
          loose,
          rank,
          pca,
          use_cps=True,
          **depth,
      )
  
      if weights is None:
          mask = None
      else:
          gain, source_weighting, mask = _prepare_weights(
              forward, gain, source_weighting, weights, weights_min
          )
  
      return forward, gain, gain_info, whitener, source_weighting, mask
  
imports: import numpy
  from .._fiff.proj import deactivate_proj
  from ..dipole import Dipole
  from ..fixes import _safe_svd
  from ..forward import is_fixed_orient
  from ..minimum_norm.inverse import _check_reference, _log_exp_var, _prepare_forward, combine_xyz
  from ..source_estimate import SourceEstimate, _BaseSourceEstimate, _make_stc
  from ..utils import _check_depth, _check_option, _validate_type, check_random_state, logger, sum_squared, verbose, warn
  from .mxne_optim import _Phi, groups_norm2, iterative_mixed_norm_solver, iterative_tf_mixed_norm_solver, mixed_norm_solver, norm_epsilon_inf, norm_l2inf, tf_mixed_norm_solver
label_desc: Use image node_id 3 for calling a global function with example usage: _prepare_gain(forward, info, noise_cov, pca, depth, loose, rank, weights, weights_min) and returns: forward,  gain,  gain_info,  whitener,  source_weighting,  mask