def check_parameters_for_validity(parameters, parameter_description,
                                  valid_parameters, default_parameters=None):
  """Checks the given parameters for validity.

  Checks a given parameter is in the set of valid parameters. It also
  assures that the parameters form a tuple or a list.  If parameters is
  'None' or empty, the default_parameters will be returned (if
  default_parameters is omitted, all valid_parameters are returned).

  This function will return a tuple or list of parameters, or raise a
  ValueError.


  Parameters
  ----------
  parameters : str or list of :obj:`str` or None
      The parameters to be checked. Might be a string, a list/tuple of
      strings, or None.

  parameter_description : str
      A short description of the parameter. This will be used to raise an
      exception in case the parameter is not valid.

  valid_parameters : list of :obj:`str`
      A list/tuple of valid values for the parameters.

  default_parameters : list of :obj:`str` or None
      The list/tuple of default parameters that will be returned in case
      parameters is None or empty. If omitted, all valid_parameters are used.

  Returns
  -------
  tuple
      A list or tuple containing the valid parameters.

  Raises
  ------
  ValueError
      If some of the parameters are not valid.

  """

  if not parameters:
    # parameters are not specified, i.e., 'None' or empty lists
    parameters = default_parameters if default_parameters is not None \
        else valid_parameters

  if not isinstance(parameters, (list, tuple, set)):
    # parameter is just a single element, not a tuple or list -> transform it
    # into a tuple
    parameters = (parameters,)

  # perform the checks
  for parameter in parameters:
    if parameter not in valid_parameters:
      raise ValueError(
          "Invalid %s '%s'. Valid values are %s, or lists/tuples of those" %
          (parameter_description, parameter, valid_parameters))

  # check passed, now return the list/tuple of parameters
  return parameters