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_cmdstanOtherwise, attempts to load a netcdf or zarr file from disk using
open_datatree
pystan fit: Calls
from_pystanwith default argumentscmdstanpy fit: Calls
from_cmdstanpywith default argumentscmdstan csv-list: Calls
from_cmdstanwith default argumentsemcee sampler: Calls
from_emceewith default argumentspyro MCMC: Calls
from_pyrowith default argumentsnumpyro MCMC: calls
from_numpyrowith default argumentsbeanmachine MonteCarloSamples: Calls
from_beanmachinewith default argumentsxarray.Dataset: Adds it to the DataTree a the only group. The group name is taken from thegroupkeyword in kwargs.xarray.DataArray: Adds it to the DataTree as the only variable in a single group. If thenameis not set, “x” is used as name. Like above, the group name is taken from thegroupkeyword in kwargs.dict: creates an xarray.Dataset with
dict_to_datasetand adds it to the DataTree as the only group (named with thegroupkey in kwargs).numpy.ndarray: names the variable “x” and adds it to the DataTree with a single group, named with thegroupkey in kwargs.
- **kwargs
Rest of the supported keyword arguments transferred to conversion function.
- Returns:
See also
from_dictConvert a nested dictionary of {group_name: {var_name: data}} to a DataTree.