code: def get_coords(data, coords):
      """Subselects xarray DataSet or DataArray object to provided coords. Raises exception if fails.
  
      Raises
      ------
      ValueError
          If coords name are not available in data
  
      KeyError
          If coords dims are not available in data
  
      Returns
      -------
      data: xarray
          xarray.DataSet or xarray.DataArray object, same type as input
      """
      if not isinstance(data, (list, tuple)):
          try:
              return data.sel(**coords)
  
          except ValueError as err:
              invalid_coords = set(coords.keys()) - set(
                  data.coords.keys()
              )
              raise ValueError(
                  f"Coords {invalid_coords} are invalid coordinate keys"
              ) from err
  
          except KeyError as err:
              raise KeyError(
                  (
                      "Coords should follow mapping format {{coord_name:[dim1, dim2]}}. "
                      "Check that coords structure is correct and"
                      " dimensions are valid. {}"
                  ).format(err)
              ) from err
      if not isinstance(coords, (list, tuple)):
          coords = [coords] * len(data)
      data_subset = []
      for idx, (datum, coords_dict) in enumerate(zip(data, coords)):
          try:
              data_subset.append(get_coords(datum, coords_dict))
          except ValueError as err:
              raise ValueError(f"Error in data[{idx}]: {err}") from err
          except KeyError as err:
              raise KeyError(f"Error in data[{idx}]: {err}") from err
      return data_subset
  
imports: import functools
  import importlib
  import importlib.resources
  import re
  import warnings
  from functools import lru_cache
  import matplotlib.pyplot
  import numpy
  from numpy import newaxis
  from .rcparams import rcParams
label_desc: Use image node_id 17 for calling a global function with example usage: get_coords(data, coords) and returns: data_subset, data