code: def apply_transform(
      transform: Callable[..., ReturnType],
      data: Any,
      map_items: bool = True,
      unpack_items: bool = False,
      log_stats: bool | str = False,
      lazy: bool | None = None,
      overrides: dict | None = None,
  ) -> list[ReturnType] | ReturnType:
      """
      Transform `data` with `transform`.
  
      If `data` is a list or tuple and `map_data` is True, each item of `data` will be transformed
      and this method returns a list of outcomes.
      otherwise transform will be applied once with `data` as the argument.
  
      Args:
          transform: a callable to be used to transform `data`.
          data: an object to be transformed.
          map_items: whether to apply transform to each item in `data`,
              if `data` is a list or tuple. Defaults to True.
          unpack_items: whether to unpack parameters using `*`. Defaults to False.
          log_stats: log errors when they occur in the processing pipeline. By default, this is set to False, which
              disables the logger for processing pipeline errors. Setting it to None or True will enable logging to the
              default logger name. Setting it to a string specifies the logger to which errors should be logged.
          lazy: whether to execute in lazy mode or not. See the :ref:`Lazy Resampling topic<lazy_resampling> for more
              information about lazy resampling. Defaults to None.
          overrides: optional overrides to apply to transform parameters. This parameter is ignored unless transforms
              are being executed lazily. See the :ref:`Lazy Resampling topic<lazy_resampling> for more details and
              examples of its usage.
  
      Raises:
          Exception: When ``transform`` raises an exception.
  
      Returns:
          Union[List[ReturnType], ReturnType]: The return type of `transform` or a list thereof.
      """
      try:
          if isinstance(data, (list, tuple)) and map_items:
              return [
                  _apply_transform(
                      transform,
                      item,
                      unpack_items,
                      lazy,
                      overrides,
                      log_stats,
                  )
                  for item in data
              ]
          return _apply_transform(
              transform, data, unpack_items, lazy, overrides, log_stats
          )
      except Exception as e:
          # if in debug mode, don't swallow exception so that the breakpoint
          # appears where the exception was raised.
          if MONAIEnvVars.debug():
              raise
          if log_stats is not False and not isinstance(
              transform, transforms.compose.Compose
          ):
              # log the input data information of exact transform in the transform chain
              if isinstance(log_stats, str):
                  datastats = transforms.utility.array.DataStats(
                      data_shape=False,
                      value_range=False,
                      name=log_stats,
                  )
              else:
                  datastats = transforms.utility.array.DataStats(
                      data_shape=False, value_range=False
                  )
              logger = logging.getLogger(datastats._logger_name)
              logger.error(
                  f"\n=== Transform input info -- {type(transform).__name__} ==="
              )
              if isinstance(data, (list, tuple)):
                  data = data[0]
  
              def _log_stats(data, prefix: str | None = "Data"):
                  if isinstance(data, (np.ndarray, torch.Tensor)):
                      # log data type, shape, range for array
                      datastats(
                          img=data,
                          data_shape=True,
                          value_range=True,
                          prefix=prefix,
                      )
                  else:
                      # log data type and value for other metadata
                      datastats(
                          img=data, data_value=True, prefix=prefix
                      )
  
              if isinstance(data, dict):
                  for k, v in data.items():
                      _log_stats(data=v, prefix=k)
              else:
                  _log_stats(data=data)
          raise RuntimeError(f"applying transform {transform}") from e
  
imports: from __future__ import annotations
  import logging
  from abc import ABC, abstractmethod
  from collections.abc import Callable, Generator, Hashable, Iterable, Mapping
  from typing import Any, TypeVar
  import numpy
  import torch
  from monai import config, transforms
  from monai.config import KeysCollection
  from monai.data.meta_tensor import MetaTensor
  from monai.transforms.traits import LazyTrait, RandomizableTrait, ThreadUnsafe
  from monai.utils import MAX_SEED, ensure_tuple, first
  from monai.utils.enums import TransformBackends
  from monai.utils.misc import MONAIEnvVars
label_desc: Use image node_id 2 for calling a global function with example usage: apply_transform(transform, data, map_items, unpack_items, log_stats, lazy, overrides) and returns: _apply_transform, unknown