class_docstr: Encapsulate emcee specific logic.
class_docstr_tok: ["Encapsulate","emcee","specific","logic","."]
docstr: Convert blobs to dictionary {groupname: xr.Dataset}.
  
  It also stores lp values in sample_stats group.
docstr_tok: ["Convert","blobs","to","dictionary","{","groupname",":","xr.Dataset","}",".","It","also","stores","lp","values","in","sample_stats","group","."]
code: def blobs_to_dict(self):
      """Convert blobs to dictionary {groupname: xr.Dataset}.
  
      It also stores lp values in sample_stats group.
      """
      store_blobs = self.blob_names is not None
      self.blob_names = (
          [] if self.blob_names is None else self.blob_names
      )
      if self.blob_groups is None:
          self.blob_groups = ["log_likelihood" for _ in self.blob_names]
      if len(self.blob_names) != len(self.blob_groups):
          raise ValueError(
              "blob_names and blob_groups must have the same length, or blob_groups be None"
          )
      if store_blobs:
          if int(self.emcee.__version__[0]) >= 3:
              blobs = self.sampler.get_blobs()
          else:
              blobs = np.array(self.sampler.blobs, dtype=object)
          if (blobs is None or blobs.size == 0) and self.blob_names:
              raise ValueError(
                  "No blobs in sampler, blob_names must be None"
              )
          if len(blobs.shape) == 2:
              blobs = np.expand_dims(blobs, axis=-1)
          blobs = blobs.swapaxes(0, 2)
          nblobs, nwalkers, ndraws, *_ = blobs.shape
          if (
              len(self.blob_names) != nblobs
              and len(self.blob_names) > 1
          ):
              raise ValueError(
                  "Incorrect number of blob names. "
                  f"Expected {nblobs}, found {len(self.blob_names)}"
              )
      blob_groups_set = set(self.blob_groups)
      blob_groups_set.add("sample_stats")
      idata_groups = ("posterior", "observed_data", "constant_data")
      if np.any(np.isin(list(blob_groups_set), idata_groups)):
          raise SyntaxError(
              f"{idata_groups} groups should not come from blobs. "
              "Using them here would overwrite their actual values"
          )
      blob_dict = {group: OrderedDict() for group in blob_groups_set}
      if len(self.blob_names) == 1:
          blob_dict[self.blob_groups[0]][
              self.blob_names[0]
          ] = blobs.swapaxes(0, 2).swapaxes(0, 1)
      else:
          for i_blob, (name, group) in enumerate(
              zip(self.blob_names, self.blob_groups)
          ):
              # for coherent blobs (all having the same dimensions) one line is enough
              blob = blobs[i_blob]
              # for blobs of different size, we get an array of arrays, which we convert
              # to an ndarray per blob_name
              if blob.dtype == object:
                  blob = blob.reshape(-1)
                  blob = np.stack(blob)
                  blob = blob.reshape((nwalkers, ndraws, -1))
              blob_dict[group][name] = np.squeeze(blob)
  
      # store lp in sample_stats group
      blob_dict["sample_stats"]["lp"] = (
          self.sampler.get_log_prob().swapaxes(0, 1)
          if hasattr(self.sampler, "get_log_prob")
          else self.sampler.lnprobability
      )
      for key, values in blob_dict.items():
          blob_dict[key] = dict_to_dataset(
              values,
              library=self.emcee,
              coords=self.coords,
              dims=self.dims,
              index_origin=self.index_origin,
          )
      return blob_dict
  
file_path: arviz/arviz/data/io_emcee.py
imports: import warnings
  from collections import OrderedDict
  import numpy
  import xarray
  from ..None import utils
  from .base import dict_to_dataset, generate_dims_coords, make_attrs
  from .inference_data import InferenceData
label_desc: Use image node_id 4 for calling the EmceeConverter obj's underlying member method code with example usage: obj.blobs_to_dict() and returns: blob_dict