code: def subset_metadata(
      metadata, keep_only=None, exclude=None, unsupported_keys=None
  ):
      """Filter the metadata"""
      metadata = suppress_unsupported_keys(
          metadata, unsupported_keys=unsupported_keys
      )
      if keep_only is not None:
          filtered_metadata = {
              key: metadata[key] for key in metadata if key in keep_only
          }
          sub_keep_only = second_level(keep_only)
          for key in sub_keep_only:
              if key in metadata:
                  filtered_metadata[key] = subset_metadata(
                      metadata[key],
                      keep_only=sub_keep_only[key],
                      unsupported_keys=unsupported_keys,
                  )
      else:
          filtered_metadata = copy(metadata)
  
      if exclude is not None:
          for key in exclude:
              if key in filtered_metadata:
                  filtered_metadata.pop(key)
          sub_exclude = second_level(exclude)
          for key in sub_exclude:
              if key in filtered_metadata:
                  filtered_metadata[key] = subset_metadata(
                      filtered_metadata[key],
                      exclude=sub_exclude[key],
                      unsupported_keys=unsupported_keys,
                  )
  
      return filtered_metadata
  
file_path: jupytext/src/jupytext/metadata_filter.py
imports: from copy import copy
  from .cell_metadata import _JUPYTEXT_CELL_METADATA, is_valid_metadata_key
label_desc: Use image node_id 7 for calling a global function with example usage: subset_metadata(metadata, keep_only, exclude, unsupported_keys) and returns: filtered_metadata