code: def tf_mixed_norm(
      evoked,
      forward,
      noise_cov,
      loose="auto",
      depth=0.8,
      maxit=3000,
      tol=1e-4,
      weights=None,
      weights_min=0.0,
      pca=True,
      debias=True,
      wsize=64,
      tstep=4,
      window=0.02,
      return_residual=False,
      return_as_dipoles=False,
      alpha=None,
      l1_ratio=None,
      dgap_freq=10,
      rank=None,
      pick_ori=None,
      n_tfmxne_iter=1,
      verbose=None,
  ):
      """Time-Frequency Mixed-norm estimate (TF-MxNE).
  
      Compute L1/L2 + L1 mixed-norm solution on time-frequency
      dictionary. Works with evoked data
      :footcite:`GramfortEtAl2013b,GramfortEtAl2011`.
  
      Parameters
      ----------
      evoked : instance of Evoked
          Evoked data to invert.
      forward : dict
          Forward operator.
      noise_cov : instance of Covariance
          Noise covariance to compute whitener.
      %(loose)s
      %(depth)s
      maxit : int
          Maximum number of iterations.
      tol : float
          Tolerance parameter.
      weights : None | array | SourceEstimate
          Weight for penalty in mixed_norm. Can be None or
          1d array of length n_sources or a SourceEstimate e.g. obtained
          with wMNE or dSPM or fMRI.
      weights_min : float
          Do not consider in the estimation sources for which weights
          is less than weights_min.
      pca : bool
          If True the rank of the data is reduced to true dimension.
      debias : bool
          Remove coefficient amplitude bias due to L1 penalty.
      wsize : int or array-like
          Length of the STFT window in samples (must be a multiple of 4).
          If an array is passed, multiple TF dictionaries are used (each having
          its own wsize and tstep) and each entry of wsize must be a multiple
          of 4. See :footcite:`BekhtiEtAl2016`.
      tstep : int or array-like
          Step between successive windows in samples (must be a multiple of 2,
          a divider of wsize and smaller than wsize/2) (default: wsize/2).
          If an array is passed, multiple TF dictionaries are used (each having
          its own wsize and tstep), and each entry of tstep must be a multiple
          of 2 and divide the corresponding entry of wsize. See
          :footcite:`BekhtiEtAl2016`.
      window : float or (float, float)
          Length of time window used to take care of edge artifacts in seconds.
          It can be one float or float if the values are different for left
          and right window length.
      return_residual : bool
          If True, the residual is returned as an Evoked instance.
      return_as_dipoles : bool
          If True, the sources are returned as a list of Dipole instances.
      alpha : float in [0, 100) or None
          Overall regularization parameter.
          If alpha and l1_ratio are not None, alpha_space and alpha_time are
          overridden by alpha * alpha_max * (1. - l1_ratio) and alpha * alpha_max
          * l1_ratio. 0 means no regularization, 100 would give 0 active dipole.
      l1_ratio : float in [0, 1] or None
          Proportion of temporal regularization.
          If l1_ratio and alpha are not None, alpha_space and alpha_time are
          overridden by alpha * alpha_max * (1. - l1_ratio) and alpha * alpha_max
          * l1_ratio. 0 means no time regularization a.k.a. MxNE.
      dgap_freq : int or np.inf
          The duality gap is evaluated every dgap_freq iterations.
      %(rank_none)s
  
          .. versionadded:: 0.18
      %(pick_ori)s
      n_tfmxne_iter : int
          Number of TF-MxNE iterations. If > 1, iterative reweighting is applied.
      %(verbose)s
  
      Returns
      -------
      stc : instance of SourceEstimate
          Source time courses.
      residual : instance of Evoked
          The residual a.k.a. data not explained by the sources.
          Only returned if return_residual is True.
  
      See Also
      --------
      mixed_norm
  
      References
      ----------
      .. footbibliography::
      """
      _check_reference(evoked)
  
      all_ch_names = evoked.ch_names
      info = evoked.info
  
      if not (0.0 <= alpha < 100.0):
          raise ValueError(
              "alpha must be in [0, 100). " "Got alpha = %s" % alpha
          )
  
      if not (0.0 <= l1_ratio <= 1.0):
          raise ValueError(
              "l1_ratio must be in range [0, 1]."
              " Got l1_ratio = %s" % l1_ratio
          )
      alpha_space = alpha * (1.0 - l1_ratio)
      alpha_time = alpha * l1_ratio
  
      if n_tfmxne_iter < 1:
          raise ValueError(
              "TF-MxNE has to be computed at least 1 time. "
              "Requires n_tfmxne_iter >= 1, got %s" % n_tfmxne_iter
          )
  
      if dgap_freq <= 0.0:
          raise ValueError(
              "dgap_freq must be a positive integer."
              " Got dgap_freq = %s" % dgap_freq
          )
  
      tstep = np.atleast_1d(tstep)
      wsize = np.atleast_1d(wsize)
      if len(tstep) != len(wsize):
          raise ValueError(
              "The same number of window sizes and steps must be "
              "passed. Got tstep = %s and wsize = %s" % (tstep, wsize)
          )
  
      (
          forward,
          gain,
          gain_info,
          whitener,
          source_weighting,
          mask,
      ) = _prepare_gain(
          forward,
          evoked.info,
          noise_cov,
          pca,
          depth,
          loose,
          rank,
          weights,
          weights_min,
      )
      _check_ori(pick_ori, forward)
  
      n_dip_per_pos = 1 if is_fixed_orient(forward) else 3
  
      if window is not None:
          evoked = _window_evoked(evoked, window)
  
      sel = [all_ch_names.index(name) for name in gain_info["ch_names"]]
      M = evoked.data[sel]
  
      # Whiten data
      logger.info("Whitening data matrix.")
      M = np.dot(whitener, M)
  
      n_steps = np.ceil(M.shape[1] / tstep.astype(float)).astype(int)
      n_freqs = wsize // 2 + 1
      n_coefs = n_steps * n_freqs
      phi = _Phi(wsize, tstep, n_coefs, evoked.data.shape[1])
  
      # Scaling to make setting of tol and alpha easy
      tol *= sum_squared(M)
      alpha_max = norm_epsilon_inf(
          gain, M, phi, l1_ratio, n_dip_per_pos
      )
      alpha_max *= 0.01
      gain /= alpha_max
      source_weighting /= alpha_max
  
      if n_tfmxne_iter == 1:
          X, active_set, E = tf_mixed_norm_solver(
              M,
              gain,
              alpha_space,
              alpha_time,
              wsize=wsize,
              tstep=tstep,
              maxit=maxit,
              tol=tol,
              verbose=verbose,
              n_orient=n_dip_per_pos,
              dgap_freq=dgap_freq,
              debias=debias,
          )
      else:
          X, active_set, E = iterative_tf_mixed_norm_solver(
              M,
              gain,
              alpha_space,
              alpha_time,
              wsize=wsize,
              tstep=tstep,
              n_tfmxne_iter=n_tfmxne_iter,
              maxit=maxit,
              tol=tol,
              verbose=verbose,
              n_orient=n_dip_per_pos,
              dgap_freq=dgap_freq,
              debias=debias,
          )
  
      if active_set.sum() == 0:
          raise Exception(
              "No active dipoles found. "
              "alpha_space/alpha_time are too big."
          )
  
      # Compute estimated whitened sensor data for each dipole (dip, ch, time)
      gain_active = gain[:, active_set]
  
      if mask is not None:
          active_set_tmp = np.zeros(len(mask), dtype=bool)
          active_set_tmp[mask] = active_set
          active_set = active_set_tmp
          del active_set_tmp
  
      X = _reapply_source_weighting(X, source_weighting, active_set)
      gain_active /= source_weighting[active_set]
  
      if return_residual:
          residual = _compute_residual(
              forward, evoked, X, active_set, gain_info
          )
  
      if return_as_dipoles:
          out = _make_dipoles_sparse(
              X,
              active_set,
              forward,
              evoked.times[0],
              1.0 / info["sfreq"],
              M,
              gain_active,
          )
      else:
          out = _make_sparse_stc(
              X,
              active_set,
              forward,
              evoked.times[0],
              1.0 / info["sfreq"],
              pick_ori=pick_ori,
          )
  
      logger.info("[done]")
  
      if return_residual:
          out = out, residual
  
      return out
  
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 12 for calling a global function with example usage: tf_mixed_norm(evoked, forward, noise_cov, loose, depth, maxit, tol, weights, weights_min, pca, debias, wsize, tstep, window, return_residual, return_as_dipoles, alpha, l1_ratio, dgap_freq, rank, pick_ori, n_tfmxne_iter, verbose) and returns: out