code: def determine_coords(
      model,
      value: Union[pd.DataFrame, pd.Series, xr.DataArray],
      dims: Optional[Sequence[Optional[str]]] = None,
      coords: Optional[Dict[str, Union[Sequence, np.ndarray]]] = None,
  ) -> Tuple[
      Dict[str, Union[Sequence, np.ndarray]], Sequence[Optional[str]]
  ]:
      """Determines coordinate values from data or the model (via ``dims``)."""
      if coords is None:
          coords = {}
  
      dim_name = None
      # If value is a df or a series, we interpret the index as coords:
      if hasattr(value, "index"):
          if dims is not None:
              dim_name = dims[0]
          if dim_name is None and value.index.name is not None:
              dim_name = value.index.name
          if dim_name is not None:
              coords[dim_name] = value.index
  
      # If value is a df, we also interpret the columns as coords:
      if hasattr(value, "columns"):
          if dims is not None:
              dim_name = dims[1]
          if dim_name is None and value.columns.name is not None:
              dim_name = value.columns.name
          if dim_name is not None:
              coords[dim_name] = value.columns
  
      if isinstance(value, xr.DataArray):
          if dims is not None:
              for dim in dims:
                  dim_name = dim
                  # str is applied because dim entries may be None
                  coords[str(dim_name)] = cast(
                      xr.DataArray, value[dim]
                  ).to_numpy()
  
      if isinstance(value, np.ndarray) and dims is not None:
          if len(dims) != value.ndim:
              raise pm.exceptions.ShapeError(
                  "Invalid data shape. The rank of the dataset must match the "
                  "length of `dims`.",
                  actual=value.shape,
                  expected=value.ndim,
              )
          for size, dim in zip(value.shape, dims):
              coord = model.coords.get(dim, None)
              if coord is None and dim is not None:
                  coords[dim] = range(size)
  
      if dims is None:
          # TODO: Also determine dim names from the index
          dims = [None] * np.ndim(value)
  
      return coords, dims
  
imports: import io
  import urllib.request
  import warnings
  from copy import copy
  from typing import Dict, Optional, Sequence, Tuple, Union, cast
  import numpy
  import pandas
  import pytensor
  import pytensor.tensor
  import xarray
  from pytensor.compile.sharedvalue import SharedVariable
  from pytensor.raise_op import Assert
  from pytensor.scalar import Cast
  from pytensor.tensor.elemwise import Elemwise
  from pytensor.tensor.random.basic import IntegersRV
  from pytensor.tensor.subtensor import AdvancedSubtensor
  from pytensor.tensor.type import TensorType
  from pytensor.tensor.variable import TensorConstant, TensorVariable
  import pymc
  from pymc.pytensorf import convert_observed_data
label_desc: Use image node_id 6 for calling a global function with example usage: determine_coords(model, value, dims, coords) and returns: coords,  dims