code: def from_pystan(
      posterior=None,
      *,
      posterior_predictive=None,
      predictions=None,
      prior=None,
      prior_predictive=None,
      observed_data=None,
      constant_data=None,
      predictions_constant_data=None,
      log_likelihood=None,
      coords=None,
      dims=None,
      posterior_model=None,
      prior_model=None,
      save_warmup=None,
      dtypes=None,
  ):
      """Convert PyStan data into an InferenceData object.
  
      For a usage example read the
      :ref:`Creating InferenceData section on from_pystan <creating_InferenceData>`
  
      Parameters
      ----------
      posterior : StanFit4Model or stan.fit.Fit
          PyStan fit object for posterior.
      posterior_predictive : str, a list of str
          Posterior predictive samples for the posterior.
      predictions : str, a list of str
          Out-of-sample predictions for the posterior.
      prior : StanFit4Model or stan.fit.Fit
          PyStan fit object for prior.
      prior_predictive : str, a list of str
          Posterior predictive samples for the prior.
      observed_data : str or a list of str
          observed data used in the sampling.
          Observed data is extracted from the `posterior.data`.
          PyStan3 needs model object for the extraction.
          See `posterior_model`.
      constant_data : str or list of str
          Constants relevant to the model (i.e. x values in a linear
          regression).
      predictions_constant_data : str or list of str
          Constants relevant to the model predictions (i.e. new x values in a linear
          regression).
      log_likelihood : dict of {str: str}, list of str or str, optional
          Pointwise log_likelihood for the data. log_likelihood is extracted from the
          posterior. It is recommended to use this argument as a dictionary whose keys
          are observed variable names and its values are the variables storing log
          likelihood arrays in the Stan code. In other cases, a dictionary with keys
          equal to its values is used. By default, if a variable ``log_lik`` is
          present in the Stan model, it will be retrieved as pointwise log
          likelihood values. Use ``False`` or set ``data.log_likelihood`` to
          false to avoid this behaviour.
      coords : dict[str, iterable]
          A dictionary containing the values that are used as index. The key
          is the name of the dimension, the values are the index values.
      dims : dict[str, List(str)]
          A mapping from variables to a list of coordinate names for the variable.
      posterior_model : stan.model.Model
          PyStan3 specific model object. Needed for automatic dtype parsing
          and for the extraction of observed data.
      prior_model : stan.model.Model
          PyStan3 specific model object. Needed for automatic dtype parsing.
      save_warmup : bool
          Save warmup iterations into InferenceData object. If not defined, use default
          defined by the rcParams.
      dtypes: dict
          A dictionary containing dtype information (int, float) for parameters.
          By default dtype information is extracted from the model code.
          Model code is extracted from fit object in PyStan 2 and from model object
          in PyStan 3.
  
      Returns
      -------
      InferenceData object
      """
      check_posterior = (posterior is not None) and (
          type(posterior).__module__ == "stan.fit"
      )
      check_prior = (prior is not None) and (
          type(prior).__module__ == "stan.fit"
      )
      if check_posterior or check_prior:
          return PyStan3Converter(
              posterior=posterior,
              posterior_model=posterior_model,
              posterior_predictive=posterior_predictive,
              predictions=predictions,
              prior=prior,
              prior_model=prior_model,
              prior_predictive=prior_predictive,
              observed_data=observed_data,
              constant_data=constant_data,
              predictions_constant_data=predictions_constant_data,
              log_likelihood=log_likelihood,
              coords=coords,
              dims=dims,
              save_warmup=save_warmup,
              dtypes=dtypes,
          ).to_inference_data()
      else:
          return PyStanConverter(
              posterior=posterior,
              posterior_predictive=posterior_predictive,
              predictions=predictions,
              prior=prior,
              prior_predictive=prior_predictive,
              observed_data=observed_data,
              constant_data=constant_data,
              predictions_constant_data=predictions_constant_data,
              log_likelihood=log_likelihood,
              coords=coords,
              dims=dims,
              save_warmup=save_warmup,
              dtypes=dtypes,
          ).to_inference_data()
  
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 8 for calling a global function with example usage: from_pystan(posterior) and returns: PyStan3Converter, PyStanConverter