code: def warn(
      message,
      category=RuntimeWarning,
      module="mne",
      ignore_namespaces=("mne",),
  ):
      """Emit a warning with trace outside the mne namespace.
  
      This function takes arguments like warnings.warn, and sends messages
      using both ``warnings.warn`` and ``logger.warn``. Warnings can be
      generated deep within nested function calls. In order to provide a
      more helpful warning, this function traverses the stack until it
      reaches a frame outside the ``mne`` namespace that caused the error.
  
      Parameters
      ----------
      message : str
          Warning message.
      category : instance of Warning
          The warning class. Defaults to ``RuntimeWarning``.
      module : str
          The name of the module emitting the warning.
      ignore_namespaces : list of str
          Namespaces to ignore when traversing the stack.
  
          .. versionadded:: 0.24
      """
      root_dirs = [
          importlib.import_module(ns) for ns in ignore_namespaces
      ]
      root_dirs = [op.dirname(ns.__file__) for ns in root_dirs]
      frame = None
      if logger.level <= logging.WARNING:
          frame = inspect.currentframe()
          while frame:
              fname = frame.f_code.co_filename
              lineno = frame.f_lineno
              # in verbose dec
              if not _verbose_dec_re.search(fname):
                  # treat tests as scripts
                  # and don't capture unittest/case.py (assert_raises)
                  if (
                      not (
                          any(fname.startswith(rd) for rd in root_dirs)
                          or ("unittest" in fname and "case" in fname)
                      )
                      or op.basename(op.dirname(fname)) == "tests"
                  ):
                      break
              frame = frame.f_back
          del frame
          # We need to use this instead of warn(message, category, stacklevel)
          # because we move out of the MNE stack, so warnings won't properly
          # recognize the module name (and our warnings.simplefilter will fail)
          warnings.warn_explicit(
              message,
              category,
              fname,
              lineno,
              module,
              globals().get("__warningregistry__", {}),
          )
      # To avoid a duplicate warning print, we only emit the logger.warning if
      # one of the handlers is a FileHandler. See gh-5592
      # But it's also nice to be able to do:
      # with mne.utils.use_log_level('warning', add_frames=3):
      # so also check our add_frames attribute.
      if (
          any(
              isinstance(h, logging.FileHandler)
              or getattr(h, "_mne_file_like", False)
              for h in logger.handlers
          )
          or _filter.add_frames
      ):
          logger.warning(message)
  
imports: import contextlib
  import importlib
  import inspect
  import logging
  import os.path
  import re
  import sys
  import warnings
  from io import StringIO
  from typing import Any, Callable, TypeVar
  from decorator import FunctionMaker
  from .docs import fill_doc
label_desc: Use image node_id 7 for calling a global function with example usage: warn(message, category, module, ignore_namespaces) without return types