class_docstr: Encapsulate PyStan specific logic.
class_docstr_tok: ["Encapsulate","PyStan","specific","logic","."]
docstr: Extract sample_stats from posterior.
code: def sample_stats_to_xarray(self):
      """Extract sample_stats from posterior."""
      posterior = self.posterior
  
      data, data_warmup = get_sample_stats(
          posterior, warmup=self.save_warmup
      )
  
      # lp__
      stat_lp, stat_lp_warmup = get_draws(
          posterior,
          variables="lp__",
          warmup=self.save_warmup,
          dtypes=self.dtypes,
      )
      data["lp"] = stat_lp["lp__"]
      if stat_lp_warmup:
          data_warmup["lp"] = stat_lp_warmup["lp__"]
  
      attrs = get_attrs(posterior)
      return (
          dict_to_dataset(
              data,
              library=self.pystan,
              attrs=attrs,
              coords=self.coords,
              dims=self.dims,
          ),
          dict_to_dataset(
              data_warmup,
              library=self.pystan,
              attrs=attrs,
              coords=self.coords,
              dims=self.dims,
          ),
      )
  
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 3 for calling the PyStanConverter obj's underlying member method code with example usage: obj.sample_stats_to_xarray() and returns: dict_to_dataset,  dict_to_dataset