code: def _get_sorted_file_groups(
      all_file_keys, time_threshold
  ):  # noqa: D417
      """Get sorted file groups.
  
      Get a list of dictionaries, where each list item consists of a dictionary
      mapping a tuple of keys to a mapping of reader names to files.  The files
      listed in each list item are considered to be grouped within the same time.
  
      Args:
          all_file_keys, as returned by _get_file_keys_for_reader_files
          time_threshold: temporal threshold
  
      Returns:
          List[Mapping[Tuple, Mapping[str, List[str]]]], as described
  
      Internal helper for group_files.
      """
      # flatten to get an overall sorting; put the name in the middle in the
      # interest of sorting
      flat_keys = (
          (v[0], rn, v[1])
          for (rn, vL) in all_file_keys.items()
          for v in vL
      )
      prev_key = None
      threshold = timedelta(seconds=time_threshold)
      # file_groups is sorted, because dictionaries are sorted by insertion
      # order in Python 3.7+
      file_groups = {}
      for gk, rn, f in sorted(flat_keys):
          # use first element of key as time identifier (if datetime type)
          if prev_key is None:
              is_new_group = True
              prev_key = gk
          elif isinstance(gk[0], datetime):
              # datetimes within threshold difference are "the same time"
              is_new_group = (gk[0] - prev_key[0]) > threshold
          else:
              is_new_group = gk[0] != prev_key[0]
  
          # compare keys for those that are found for both the key and
          # this is a generator and is not computed until the if statement below
          # when we know that `prev_key` is not None
          vals_not_equal = (
              this_val != prev_val
              for this_val, prev_val in zip(gk[1:], prev_key[1:])
              if this_val is not None and prev_val is not None
          )
          # if this is a new group based on the first element
          if is_new_group or any(vals_not_equal):
              file_groups[gk] = {rn: [f]}
              prev_key = gk
          else:
              if rn not in file_groups[prev_key]:
                  file_groups[prev_key][rn] = [f]
              else:
                  file_groups[prev_key][rn].append(f)
      return file_groups
  
imports: from __future__ import annotations
  import logging
  import os
  import pathlib
  import pickle
  import warnings
  from datetime import datetime, timedelta
  from functools import total_ordering
  import yaml
  from yaml import UnsafeLoader
  from satpy._config import config_search_paths, get_entry_points_config_dirs, glob_config
  from .yaml_reader import AbstractYAMLReader
  from .yaml_reader import load_yaml_configs
label_desc: Use image node_id 4 for calling a global function with example usage: _get_sorted_file_groups(all_file_keys, time_threshold) and returns: file_groups