class_docstr: Encapsulate PyStan specific logic.
class_docstr_tok: ["Encapsulate","PyStan","specific","logic","."]
docstr: Extract posterior samples from fit.
code: def posterior_to_xarray(self):
      """Extract posterior samples from fit."""
      posterior = self.posterior
      # filter posterior_predictive and log_likelihood
      posterior_predictive = self.posterior_predictive
      if posterior_predictive is None:
          posterior_predictive = []
      elif isinstance(posterior_predictive, str):
          posterior_predictive = [posterior_predictive]
      predictions = self.predictions
      if predictions is None:
          predictions = []
      elif isinstance(predictions, str):
          predictions = [predictions]
      log_likelihood = self.log_likelihood
      if log_likelihood is None:
          log_likelihood = []
      elif isinstance(log_likelihood, str):
          log_likelihood = [log_likelihood]
      elif isinstance(log_likelihood, dict):
          log_likelihood = list(log_likelihood.values())
  
      ignore = (
          posterior_predictive + predictions + log_likelihood + ["lp__"]
      )
  
      data, data_warmup = get_draws(
          posterior,
          ignore=ignore,
          warmup=self.save_warmup,
          dtypes=self.dtypes,
      )
      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 2 for calling the PyStanConverter obj's underlying member method code with example usage: obj.posterior_to_xarray() and returns: dict_to_dataset,  dict_to_dataset