code: def _check_option(parameter, value, allowed_values, extra=""):
      """Check the value of a parameter against a list of valid options.
  
      Return the value if it is valid, otherwise raise a ValueError with a
      readable error message.
  
      Parameters
      ----------
      parameter : str
          The name of the parameter to check. This is used in the error message.
      value : any type
          The value of the parameter to check.
      allowed_values : list
          The list of allowed values for the parameter.
      extra : str
          Extra string to append to the invalid value sentence, e.g.
          "when using ico mode".
  
      Raises
      ------
      ValueError
          When the value of the parameter is not one of the valid options.
  
      Returns
      -------
      value : any type
          The value if it is valid.
      """
      if value in allowed_values:
          return value
  
      # Prepare a nice error message for the user
      extra = f" {extra}" if extra else extra
      msg = (
          "Invalid value for the '{parameter}' parameter{extra}. "
          "{options}, but got {value!r} instead."
      )
      allowed_values = list(allowed_values)  # e.g., if a dict was given
      if len(allowed_values) == 1:
          options = (
              f"The only allowed value is {repr(allowed_values[0])}"
          )
      else:
          options = "Allowed values are "
          if len(allowed_values) == 2:
              options += " and ".join(repr(v) for v in allowed_values)
          else:
              options += ", ".join(repr(v) for v in allowed_values[:-1])
              options += f", and {repr(allowed_values[-1])}"
      raise ValueError(
          msg.format(
              parameter=parameter,
              options=options,
              value=value,
              extra=extra,
          )
      )
  
imports: import numbers
  import operator
  import os
  import re
  from builtins import input
  from difflib import get_close_matches
  from importlib import import_module
  from pathlib import Path
  import numpy
  from ..defaults import HEAD_SIZE_DEFAULT, _handle_default
  from ..fixes import _compare_version, _median_complex
  from ._logging import _record_warnings, _verbose_safe_false, logger, verbose, warn
label_desc: Use image node_id 37 for calling a global function with example usage: _check_option(parameter, value, allowed_values, extra) and returns: value