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 usingfrom_cmdstan
Otherwise, attempts to load a netcdf or zarr file from disk using
open_datatree
pystan fit: Calls
from_pystan
with default argumentscmdstanpy fit: Calls
from_cmdstanpy
with default argumentscmdstan csv-list: Calls
from_cmdstan
with default argumentsemcee sampler: Calls
from_emcee
with default argumentspyro MCMC: Calls
from_pyro
with default argumentsnumpyro MCMC: calls
from_numpyro
with default argumentsbeanmachine MonteCarloSamples: Calls
from_beanmachine
with default argumentsxarray.Dataset
: Adds it to the DataTree a the only group. The group name is taken from thegroup
keyword in kwargs.xarray.DataArray
: Adds it to the DataTree as the only variable in a single group. If thename
is not set, “x” is used as name. Like above, the group name is taken from thegroup
keyword in kwargs.dict: creates an xarray.Dataset with
dict_to_dataset
and adds it to the DataTree as the only group (named with thegroup
key in kwargs).numpy.ndarray
: names the variable “x” and adds it to the DataTree with a single group, named with thegroup
key in kwargs.
- kwargs
Rest of the supported keyword arguments transferred to conversion function.
- Returns:
See also
from_dict
Convert a nested dictionary of {group_name: {var_name: data}} to a DataTree.