code: def from_contour(
      x: ArrayLike | None = None,
      y: ArrayLike | None = None,
      z: ArrayLike | np.ma.MaskedArray | None = None,
      levels: ArrayLike | None = None,
      **visuals,  # This is union of LineProps, FillProps and HatchProps
  ) -> ContourRenderer:
      """Creates a :class:`bokeh.models.ContourRenderer` containing filled
      polygons and/or contour lines.
  
      Usually it is preferable to call :func:`~bokeh.plotting.figure.contour`
      instead of this function.
  
      Filled contour polygons are calculated if ``fill_color`` is set,
      contour lines if ``line_color`` is set.
  
      Args:
          x (array-like[float] of shape (ny, nx) or (nx,), optional) :
              The x-coordinates of the ``z`` values. May be 2D with the same
              shape as ``z.shape``, or 1D with length ``nx = z.shape[1]``.
              If not specified are assumed to be ``np.arange(nx)``. Must be
              ordered monotonically.
  
          y (array-like[float] of shape (ny, nx) or (ny,), optional) :
              The y-coordinates of the ``z`` values. May be 2D with the same
              shape as ``z.shape``, or 1D with length ``ny = z.shape[0]``.
              If not specified are assumed to be ``np.arange(ny)``. Must be
              ordered monotonically.
  
          z (array-like[float] of shape (ny, nx)) :
              A 2D NumPy array of gridded values to calculate the contours
              of.  May be a masked array, and any invalid values (``np.inf``
              or ``np.nan``) will also be masked out.
  
          levels (array-like[float]) :
              The z-levels to calculate the contours at, must be increasing.
              Contour lines are calculated at each level and filled contours
              are calculated between each adjacent pair of levels so the
              number of sets of contour lines is ``len(levels)`` and the
              number of sets of filled contour polygons is ``len(levels)-1``.
  
          **visuals: |fill properties|, |hatch properties| and |line properties|
              Fill and hatch properties are used for filled contours, line
              properties for line contours. If using vectorized properties
              then the correct number must be used, ``len(levels)`` for line
              properties and ``len(levels)-1`` for fill and hatch properties.
  
              ``fill_color`` and ``line_color`` are more flexible in that
              they will accept longer sequences and interpolate them to the
              required number using :func:`~bokeh.palettes.linear_palette`,
              and also accept palette collections (dictionaries mapping from
              integer length to color sequence) such as
              `bokeh.palettes.Cividis`.
  
      """
      levels = _validate_levels(levels)
      if len(levels) < 2:
          want_fill = False
  
      nlevels = len(levels)
  
      want_line = visuals.get("line_color", None) is not None
      if want_line:
          # Handle possible callback or interpolation for line_color.
          visuals["line_color"] = _color(visuals["line_color"], nlevels)
  
          line_cds = ColumnDataSource()
          _process_sequence_literals(
              MultiLine, visuals, line_cds, False
          )
  
          # Remove line visuals identified from visuals dict.
          line_visuals = {}
          for name in LineProps.properties():
              prop = visuals.pop(name, None)
              if prop is not None:
                  line_visuals[name] = prop
      else:
          visuals.pop("line_color", None)
  
      want_fill = visuals.get("fill_color", None) is not None
      if want_fill:
          # Handle possible callback or interpolation for fill_color and hatch_color.
          visuals["fill_color"] = _color(
              visuals["fill_color"], nlevels - 1
          )
          if "hatch_color" in visuals:
              visuals["hatch_color"] = _color(
                  visuals["hatch_color"], nlevels - 1
              )
  
          fill_cds = ColumnDataSource()
          _process_sequence_literals(
              MultiPolygons, visuals, fill_cds, False
          )
      else:
          visuals.pop("fill_color", None)
  
      # Check for extra unknown kwargs.
      unknown = (
          visuals.keys()
          - FillProps.properties()
          - HatchProps.properties()
      )
      if unknown:
          raise ValueError(
              f"Unknown keyword arguments in 'from_contour': {', '.join(unknown)}"
          )
  
      new_contour_data = contour_data(
          x=x,
          y=y,
          z=z,
          levels=levels,
          want_fill=want_fill,
          want_line=want_line,
      )
  
      # Will be other possibilities here like logarithmic....
      contour_renderer = ContourRenderer(
          fill_renderer=GlyphRenderer(
              glyph=MultiPolygons(), data_source=ColumnDataSource()
          ),
          line_renderer=GlyphRenderer(
              glyph=MultiLine(), data_source=ColumnDataSource()
          ),
          levels=list(levels),
      )
      contour_renderer.set_data(new_contour_data)
  
      if new_contour_data.fill_data:
          glyph = contour_renderer.fill_renderer.glyph
          for name, value in visuals.items():
              setattr(glyph, name, value)
  
          cds = contour_renderer.fill_renderer.data_source
          for name, value in fill_cds.data.items():
              cds.add(value, name)
  
          glyph.line_alpha = 0  # Don't display lines around fill.
          glyph.line_width = 0
  
      if new_contour_data.line_data:
          glyph = contour_renderer.line_renderer.glyph
          for name, value in line_visuals.items():
              setattr(glyph, name, value)
  
          cds = contour_renderer.line_renderer.data_source
          for name, value in line_cds.data.items():
              cds.add(value, name)
  
      return contour_renderer
  
imports: from __future__ import annotations
  import logging
  from typing import TYPE_CHECKING, Sequence, Union, cast
  import numpy
  from ..core.property_mixins import FillProps, HatchProps, LineProps
  from ..models.glyphs import MultiLine, MultiPolygons
  from ..models.renderers import ContourRenderer, GlyphRenderer
  from ..models.sources import ColumnDataSource
  from ..palettes import interp_palette
  from ..plotting._renderer import _process_sequence_literals
  from ..util.dataclasses import dataclass, entries
label_desc: Use image node_id 2 for calling a global function with example usage: from_contour(x, y, z, levels) and returns: contour_renderer