class_docstr: Encapsulate PyStan specific logic.
class_docstr_tok: ["Encapsulate","PyStan","specific","logic","."]
docstr: Convert observed, constant data and predictions constant data to xarray.
code: def data_to_xarray(self):
      """Convert observed, constant data and predictions constant data to xarray."""
      posterior = self.posterior
      dims = {} if self.dims is None else self.dims
      obs_const_dict = {}
      for group_name in (
          "observed_data",
          "constant_data",
          "predictions_constant_data",
      ):
          names = getattr(self, group_name)
          if names is None:
              continue
          names = [names] if isinstance(names, str) else names
          data = OrderedDict()
          for key in names:
              vals = np.atleast_1d(posterior.data[key])
              val_dims = dims.get(key)
              val_dims, coords = generate_dims_coords(
                  vals.shape, key, dims=val_dims, coords=self.coords
              )
              data[key] = xr.DataArray(
                  vals, dims=val_dims, coords=coords
              )
          obs_const_dict[group_name] = xr.Dataset(
              data_vars=data, attrs=make_attrs(library=self.pystan)
          )
      return obs_const_dict
  
imports: import re
  from collections import OrderedDict
  from copy import deepcopy
  from math import ceil
  import numpy
  import xarray
  from ..None import _log
  from ..rcparams import rcParams
  from .base import dict_to_dataset, generate_dims_coords, infer_stan_dtypes, make_attrs, requires
  from .inference_data import InferenceData
label_desc: Use image node_id 10 for calling the PyStanConverter obj's underlying member method code with example usage: obj.data_to_xarray() and returns: obs_const_dict