code: def _order_epochs(data, times, order=None, overlay_times=None):
      """Sort epochs image data (2D). Helper for plot_epochs_image."""
      n_epochs = len(data)
  
      if overlay_times is not None:
          if len(overlay_times) != n_epochs:
              raise ValueError(
                  f"size of overlay_times parameter ({len(overlay_times)}) does "
                  f"not match the number of epochs ({n_epochs})."
              )
          overlay_times = np.array(overlay_times)
          times_min = np.min(overlay_times)
          times_max = np.max(overlay_times)
          if (times_min < times[0]) or (times_max > times[-1]):
              warn(
                  "Some values in overlay_times fall outside of the epochs "
                  f"time interval (between {times[0]} s and {times[-1]} s)"
              )
  
      if callable(order):
          order = order(times, data)
  
      if order is not None:
          if len(order) != n_epochs:
              raise ValueError(
                  f"If order is a {type(order).__name__}, its "
                  f"length ({len(order)}) must match the length of "
                  f"the data ({n_epochs})."
              )
          order = np.array(order)
          data = data[order]
          if overlay_times is not None:
              overlay_times = overlay_times[order]
  
      return data, overlay_times
  
file_path: mne-python/mne/viz/epochs.py
imports: from collections import Counter
  from copy import deepcopy
  import numpy
  from scipy.ndimage import gaussian_filter1d
  from .._fiff.meas_info import create_info
  from .._fiff.pick import _DATA_CH_TYPES_SPLIT, _VALID_CHANNEL_TYPES, _picks_to_idx
  from ..defaults import _handle_default
  from ..fixes import _sharex
  from ..utils import _check_option, fill_doc, legacy, logger, verbose, warn
  from ..utils.spectrum import _split_psd_kwargs
  from .raw import _setup_channel_selections
  from .utils import DraggableColorbar, _check_cov, _compute_scalings, _get_channel_plotting_order, _handle_decim, _handle_precompute, _make_combine_callable, _make_event_color_dict, _set_title_multiple_electrodes, _set_window_title, _setup_cmap, _setup_vmin_vmax, _validate_type, plt_show
label_desc: Use image node_id 3 for calling a global function with example usage: _order_epochs(data, times, order, overlay_times) and returns: data,  overlay_times