code: def apply_solver(
      solver, evoked, forward, noise_cov, loose=0.2, depth=0.8
  ):
      """Call a custom solver on evoked data.
  
      This function does all the necessary computation:
  
      - to select the channels in the forward given the available ones in
        the data
      - to take into account the noise covariance and do the spatial whitening
      - to apply loose orientation constraint as MNE solvers
      - to apply a weigthing of the columns of the forward operator as in the
        weighted Minimum Norm formulation in order to limit the problem
        of depth bias.
  
      Parameters
      ----------
      solver : callable
          The solver takes 3 parameters: data M, gain matrix G, number of
          dipoles orientations per location (1 or 3). A solver shall return
          2 variables: X which contains the time series of the active dipoles
          and an active set which is a boolean mask to specify what dipoles are
          present in X.
      evoked : instance of mne.Evoked
          The evoked data
      forward : instance of Forward
          The forward solution.
      noise_cov : instance of Covariance
          The noise covariance.
      loose : float in [0, 1] | 'auto'
          Value that weights the source variances of the dipole components
          that are parallel (tangential) to the cortical surface. If loose
          is 0 then the solution is computed with fixed orientation.
          If loose is 1, it corresponds to free orientations.
          The default value ('auto') is set to 0.2 for surface-oriented source
          space and set to 1.0 for volumic or discrete source space.
      depth : None | float in [0, 1]
          Depth weighting coefficients. If None, no depth weighting is performed.
  
      Returns
      -------
      stc : instance of SourceEstimate
          The source estimates.
      """
      # Import the necessary private functions
      from mne.inverse_sparse.mxne_inverse import (
          _make_sparse_stc,
          _prepare_gain,
          _reapply_source_weighting,
          is_fixed_orient,
      )
  
      all_ch_names = evoked.ch_names
  
      # Handle depth weighting and whitening (here is no weights)
      (
          forward,
          gain,
          gain_info,
          whitener,
          source_weighting,
          mask,
      ) = _prepare_gain(
          forward,
          evoked.info,
          noise_cov,
          pca=False,
          depth=depth,
          loose=loose,
          weights=None,
          weights_min=None,
          rank=None,
      )
  
      # Select channels of interest
      sel = [all_ch_names.index(name) for name in gain_info["ch_names"]]
      M = evoked.data[sel]
  
      # Whiten data
      M = np.dot(whitener, M)
  
      n_orient = 1 if is_fixed_orient(forward) else 3
      X, active_set = solver(M, gain, n_orient)
      X = _reapply_source_weighting(X, source_weighting, active_set)
  
      stc = _make_sparse_stc(
          X,
          active_set,
          forward,
          tmin=evoked.times[0],
          tstep=1.0 / evoked.info["sfreq"],
      )
  
      return stc
  
imports: import numpy
  from scipy import linalg
  import mne
  from mne.datasets import sample
  from mne.viz import plot_sparse_source_estimates
label_desc: Use image node_id 1 for calling a global function with example usage: apply_solver(solver, evoked, forward, noise_cov, loose, depth) and returns: stc