class_docstr: Encapsulate CmdStan specific logic.
class_docstr_tok: ["Encapsulate","CmdStan","specific","logic","."]
docstr: Extract posterior samples from output csv.
docstr_tok: ["Extract","posterior","samples","from","output","csv","."]
code: def posterior_to_xarray(self):
      """Extract posterior samples from output csv."""
      columns = self.posterior_columns
  
      # filter posterior_predictive, predictions and log_likelihood
      posterior_predictive = self.posterior_predictive
      if posterior_predictive is None or (
          isinstance(posterior_predictive, str)
          and posterior_predictive.lower().endswith(".csv")
      ):
          posterior_predictive = []
      elif isinstance(posterior_predictive, str):
          posterior_predictive = [
              col
              for col in columns
              if posterior_predictive == col.split(".")[0]
          ]
      else:
          posterior_predictive = [
              col
              for col in columns
              if any(
                  item == col.split(".")[0]
                  for item in posterior_predictive
              )
          ]
  
      predictions = self.predictions
      if predictions is None or (
          isinstance(predictions, str)
          and predictions.lower().endswith(".csv")
      ):
          predictions = []
      elif isinstance(predictions, str):
          predictions = [
              col for col in columns if predictions == col.split(".")[0]
          ]
      else:
          predictions = [
              col
              for col in columns
              if any(item == col.split(".")[0] for item in predictions)
          ]
  
      log_likelihood = self.log_likelihood
      if log_likelihood is None or (
          isinstance(log_likelihood, str)
          and log_likelihood.lower().endswith(".csv")
      ):
          log_likelihood = []
      elif isinstance(log_likelihood, str):
          log_likelihood = [
              col
              for col in columns
              if log_likelihood == col.split(".")[0]
          ]
      elif isinstance(log_likelihood, dict):
          log_likelihood = [
              col
              for col in columns
              if any(
                  item == col.split(".")[0]
                  for item in log_likelihood.values()
              )
          ]
      else:
          log_likelihood = [
              col
              for col in columns
              if any(
                  item == col.split(".")[0] for item in log_likelihood
              )
          ]
  
      invalid_cols = posterior_predictive + predictions + log_likelihood
      valid_cols = {
          col: idx
          for col, idx in columns.items()
          if col not in invalid_cols
      }
      data = _unpack_ndarrays(
          self.posterior[0], valid_cols, self.dtypes
      )
      data_warmup = _unpack_ndarrays(
          self.posterior[1], valid_cols, self.dtypes
      )
      return (
          dict_to_dataset(
              data,
              coords=self.coords,
              dims=self.dims,
              attrs=self.attrs,
              index_origin=self.index_origin,
          ),
          dict_to_dataset(
              data_warmup,
              coords=self.coords,
              dims=self.dims,
              attrs=self.attrs,
              index_origin=self.index_origin,
          ),
      )
  
imports: import logging
  import os
  import re
  from collections import defaultdict
  from glob import glob
  from pathlib import Path
  from typing import Dict, List, Optional, Union
  import numpy
  from ..None import utils
  from ..rcparams import rcParams
  from .base import CoordSpec, DimSpec, dict_to_dataset, infer_stan_dtypes, requires
  from .inference_data import InferenceData
label_desc: Use image node_id 4 for calling the CmdStanConverter obj's underlying member method code with example usage: obj.posterior_to_xarray() and returns: dict_to_dataset,  dict_to_dataset