class_docstr: Encapsulate CmdStan specific logic.
class_docstr_tok: ["Encapsulate","CmdStan","specific","logic","."]
docstr: Convert elementwise log_likelihood samples to xarray.
docstr_tok: ["Convert","elementwise","log_likelihood","samples","to","xarray","."]
code: def log_likelihood_to_xarray(self):
      """Convert elementwise log_likelihood samples to xarray."""
      log_likelihood = self.log_likelihood
  
      if (
          isinstance(log_likelihood, (tuple, list))
          and log_likelihood[0].endswith(".csv")
      ) or (
          isinstance(log_likelihood, str)
          and log_likelihood.endswith(".csv")
      ):
          if isinstance(log_likelihood, str):
              log_likelihood = [log_likelihood]
  
          chain_data = []
          chain_data_warmup = []
          columns = None
          attrs = {}
          for path in log_likelihood:
              parsed_output = _read_output(path)
              chain_data.append(parsed_output["sample"])
              chain_data_warmup.append(parsed_output["sample_warmup"])
  
              if columns is None:
                  columns = parsed_output["sample_columns"]
  
              for key, value in parsed_output[
                  "configuration_info"
              ].items():
                  if key not in attrs:
                      attrs[key] = []
                  attrs[key].append(value)
          data = _unpack_ndarrays(chain_data, columns, self.dtypes)
          data_warmup = _unpack_ndarrays(
              chain_data_warmup, columns, self.dtypes
          )
      else:
          if isinstance(log_likelihood, dict):
              log_lik_to_obs_name = {
                  v: k for k, v in log_likelihood.items()
              }
              columns = {
                  col.replace(
                      col_name, log_lik_to_obs_name[col_name]
                  ): idx
                  for col, col_name, idx in (
                      (col, col.split(".")[0], idx)
                      for col, idx in self.posterior_columns.items()
                  )
                  if any(
                      item == col_name
                      for item in log_likelihood.values()
                  )
              }
          else:
              if isinstance(log_likelihood, str):
                  log_likelihood = [log_likelihood]
              columns = {
                  col: idx
                  for col, idx in self.posterior_columns.items()
                  if any(
                      item == col.split(".")[0]
                      for item in log_likelihood
                  )
              }
          data = _unpack_ndarrays(
              self.posterior[0], columns, self.dtypes
          )
          data_warmup = _unpack_ndarrays(
              self.posterior[1], columns, self.dtypes
          )
          attrs = None
      return (
          dict_to_dataset(
              data,
              coords=self.coords,
              dims=self.dims,
              attrs=attrs,
              index_origin=self.index_origin,
              skip_event_dims=True,
          ),
          dict_to_dataset(
              data_warmup,
              coords=self.coords,
              dims=self.dims,
              attrs=attrs,
              index_origin=self.index_origin,
              skip_event_dims=True,
          ),
      )
  
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 8 for calling the CmdStanConverter obj's underlying member method code with example usage: obj.log_likelihood_to_xarray() and returns: dict_to_dataset,  dict_to_dataset