arviz_base.convert_to_datatree#

arviz_base.convert_to_datatree(obj, **kwargs)[source]#

Convert a supported object to a DataTree object following ArviZ conventions.

This function sends obj to the right conversion function. It is idempotent, in that it will return DataTree objects unchanged. In general however, it is better to call specific conversion functions directly. See below for more details.

Parameters:
obj

A supported object to convert to InferenceData:

  • DataTree: returns unchanged

  • InferenceData: returns the equivalent DataTree. kwargs are passed to datatree.DataTree.from_dict.

  • str:

    • If it ends with .csv, attempts to load the file as a cmdstan csv fit using from_cmdstan

    • Otherwise, attempts to load a netcdf or zarr file from disk using open_datatree

  • pystan fit: Calls from_pystan with default arguments

  • cmdstanpy fit: Calls from_cmdstanpy with default arguments

  • cmdstan csv-list: Calls from_cmdstan with default arguments

  • emcee sampler: Calls from_emcee with default arguments

  • pyro MCMC: Calls from_pyro with default arguments

  • numpyro MCMC: calls from_numpyro with default arguments

  • beanmachine MonteCarloSamples: Calls from_beanmachine with default arguments

  • xarray.Dataset: Adds it to the DataTree a the only group. The group name is taken from the group keyword in kwargs.

  • xarray.DataArray: Adds it to the DataTree as the only variable in a single group. If the name is not set, “x” is used as name. Like above, the group name is taken from the group keyword in kwargs.

  • dict: creates an xarray.Dataset with dict_to_dataset and adds it to the DataTree as the only group (named with the group key in kwargs).

  • numpy.ndarray: names the variable “x” and adds it to the DataTree with a single group, named with the group key in kwargs.

kwargs

Rest of the supported keyword arguments transferred to conversion function.

Returns:
datatree.DataTree

See also

from_dict

Convert a nested dictionary of {group_name: {var_name: data}} to a DataTree.