code: def get_key(key, key_container, num_results=1, best=True,
              resolution=None, calibration=None, polarization=None,
              level=None, modifiers=None):
      if isinstance(key, numbers.Number):
          key = DatasetID(wavelength=key, modifiers=None)
      elif isinstance(key, (str, six.text_type)):
          key = DatasetID(name=key, modifiers=None)
      elif not isinstance(key, DatasetID):
          raise ValueError("Expected 'DatasetID', str, or number dict key, "
                           "not {}".format(str(type(key))))
      res = filter_keys_by_dataset_id(key, key_container)
      if resolution is not None:
          if not isinstance(resolution, (list, tuple)):
              resolution = (resolution, )
          res = [k for k in res
                 if k.resolution is not None and k.resolution in resolution]
      if polarization is not None:
          if not isinstance(polarization, (list, tuple)):
              polarization = (polarization, )
          res = [k for k in res
                 if k.polarization is not None and k.polarization in
                 polarization]
      if calibration is not None:
          if not isinstance(calibration, (list, tuple)):
              calibration = (calibration, )
          res = [k for k in res
                 if k.calibration is not None and k.calibration in calibration]
      if level is not None:
          if not isinstance(level, (list, tuple)):
              level = (level, )
          res = [k for k in res
                 if k.level is not None and k.level in level]
      if modifiers is not None:
          res = [k for k in res
                 if k.modifiers is not None and k.modifiers == modifiers]
      if best:
          res = get_best_dataset_key(key, res)
      if num_results == 1 and not res:
          raise KeyError("No dataset matching '{}' found".format(str(key)))
      elif num_results == 1 and len(res) != 1:
          raise TooManyResults("No unique dataset matching {}".format(str(key)))
      elif num_results == 1:
          return res[0]
      elif num_results == 0:
          return res
      else:
          return res[:num_results]