code: def combine_metadata(*metadata_objects, **kwargs):
      
      average_times = kwargs.get('average_times', True)  # python 2 compatibility (no kwarg after *args)
      shared_keys = None
      info_dicts = []
      # grab all of the dictionary objects provided and make a set of the shared keys
      for metadata_object in metadata_objects:
          if isinstance(metadata_object, dict):
              metadata_dict = metadata_object
          elif hasattr(metadata_object, "attrs"):
              metadata_dict = metadata_object.attrs
          else:
              continue
          info_dicts.append(metadata_dict)
  
          if shared_keys is None:
              shared_keys = set(metadata_dict.keys())
          else:
              shared_keys &= set(metadata_dict.keys())
  
      # combine all of the dictionaries
      shared_info = {}
      for k in shared_keys:
          values = [nfo[k] for nfo in info_dicts]
          any_arrays = any([isinstance(val, np.ndarray) for val in values])
          if any_arrays:
              if all(np.all(val == values[0]) for val in values[1:]):
                  shared_info[k] = values[0]
          elif 'time' in k and isinstance(values[0], datetime) and average_times:
              shared_info[k] = average_datetimes(values)
          elif all(val == values[0] for val in values[1:]):
              shared_info[k] = values[0]
  
      return shared_info
docs: Combine the metadata of two or more Datasets.
  
      If any keys are not equal or do not exist in all provided dictionaries
      then they are not included in the returned dictionary.
      By default any keys with the word 'time' in them and consisting
      of datetime objects will be averaged. This is to handle cases where
      data were observed at almost the same time but not exactly.
  
      Args:
          *metadata_objects: MetadataObject or dict objects to combine
          average_times (bool): Average any keys with 'time' in the name
  
      Returns:
          dict: the combined metadata