# xarray.DataTree

### *class* xarray.DataTree(dataset=None, children=None, name=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/datatree.py#L478-L2736)

A tree-like hierarchical collection of xarray objects.

Attempts to present an API like that of xarray.Dataset, but methods are wrapped to also update all the tree’s child nodes.

#### \_\_init_\_(dataset=None, children=None, name=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/datatree.py#L533-L566)

Create a single node of a DataTree.

The node may optionally contain data in the form of data and coordinate
variables, stored in the same way as data is stored in an
xarray.Dataset.

* **Parameters:**
  * **dataset** ([`Dataset`](xarray.Dataset.html.md#xarray.Dataset), *optional*) – Data to store directly at this node.
  * **children** (`Mapping[str`, `DataTree]`, *optional*) – Any child nodes of this node.
  * **name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str), *optional*) – Name for this node of the tree.
* **Returns:**
  [`DataTree`](#xarray.DataTree)

#### SEE ALSO
[`DataTree.from_dict`](xarray.DataTree.from_dict.html.md#xarray.DataTree.from_dict)

### Methods

| [`__init__`](#xarray.DataTree.__init__)([dataset, children, name])                                         | Create a single node of a DataTree.                                                                                                                                                    |
|------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`all`](xarray.DataTree.all.html.md#xarray.DataTree.all)([dim, keep_attrs])                                  | Reduce this DataTree's data by applying `all` along some dimension(s).                                                                                                                 |
| [`any`](xarray.DataTree.any.html.md#xarray.DataTree.any)([dim, keep_attrs])                                  | Reduce this DataTree's data by applying `any` along some dimension(s).                                                                                                                 |
| [`argsort`](xarray.DataTree.argsort.html.md#xarray.DataTree.argsort)([axis, kind, order, stable, descending])    | Returns the indices that would sort this array.                                                                                                                                        |
| [`assign`](xarray.DataTree.assign.html.md#xarray.DataTree.assign)([items])                                      | Assign new data variables or child nodes to a DataTree, returning a new object with all the original items in addition to the new ones.                                                |
| [`chunk`](xarray.DataTree.chunk.html.md#xarray.DataTree.chunk)([chunks, name_prefix, token, lock, ...])        | Coerce all arrays in all groups in this tree into dask arrays with the given chunks.                                                                                                   |
| `close`()                                                                                                                    | Close any files associated with this tree.                                                                                                                                             |
| [`compute`](xarray.DataTree.compute.html.md#xarray.DataTree.compute)(\*\*kwargs)                                 | Manually trigger loading and/or computation of this datatree's data from disk or a remote source into memory and return a new datatree.                                                |
| [`conj`](xarray.DataTree.conj.html.md#xarray.DataTree.conj)()                                                 | Complex-conjugate all elements.                                                                                                                                                        |
| [`conjugate`](xarray.DataTree.conjugate.html.md#xarray.DataTree.conjugate)(\*args, \*\*kwargs)                     | a.conj()                                                                                                                                                                               |
| [`copy`](xarray.DataTree.copy.html.md#xarray.DataTree.copy)(\*[, inherit, deep])                              | Returns a copy of this subtree.                                                                                                                                                        |
| `count`([dim, keep_attrs])                                                                                                   | Reduce this DataTree's data by applying `count` along some dimension(s).                                                                                                               |
| [`cumprod`](xarray.DataTree.cumprod.html.md#xarray.DataTree.cumprod)([dim, skipna, keep_attrs])                  | Reduce this DataTree's data by applying `cumprod` (i.e., cumulative product) along some dimension(s).                                                                                  |
| [`cumsum`](xarray.DataTree.cumsum.html.md#xarray.DataTree.cumsum)([dim, skipna, keep_attrs])                    | Reduce this DataTree's data by applying `cumsum` (i.e., cumulative sum) along some dimension(s).                                                                                       |
| [`drop_nodes`](xarray.DataTree.drop_nodes.html.md#xarray.DataTree.drop_nodes)(names, \*[, errors])                  | Drop child nodes from this node.                                                                                                                                                       |
| [`equals`](xarray.DataTree.equals.html.md#xarray.DataTree.equals)(other)                                        | Two DataTrees are equal if they have isomorphic node structures, with matching node names, and if they have matching variables and coordinates, all of which are equal.                |
| [`filter`](xarray.DataTree.filter.html.md#xarray.DataTree.filter)(filterfunc)                                   | Filter nodes according to a specified condition.                                                                                                                                       |
| [`filter_like`](xarray.DataTree.filter_like.html.md#xarray.DataTree.filter_like)(other)                              | Filter a datatree like another datatree.                                                                                                                                               |
| [`find_common_ancestor`](xarray.DataTree.find_common_ancestor.html.md#xarray.DataTree.find_common_ancestor)(other)            | Find the first common ancestor of two nodes in the same tree.                                                                                                                          |
| [`from_dict`](xarray.DataTree.from_dict.html.md#xarray.DataTree.from_dict)([data, coords, name, nested])           | Create a datatree from a dictionary of data objects, organised by paths into the tree.                                                                                                 |
| [`get`](xarray.DataTree.get.html.md#xarray.DataTree.get)(key[, default])                                     | Access child nodes, variables, or coordinates stored in this node.                                                                                                                     |
| [`identical`](xarray.DataTree.identical.html.md#xarray.DataTree.identical)(other)                                  | Like equals, but also checks attributes on all datasets, variables and coordinates, and requires that any inherited coordinates at the tree root are also inherited on the other tree. |
| [`isel`](xarray.DataTree.isel.html.md#xarray.DataTree.isel)([indexers, drop, missing_dims])                   | Returns a new data tree with each array indexed along the specified dimension(s).                                                                                                      |
| [`isomorphic`](xarray.DataTree.isomorphic.html.md#xarray.DataTree.isomorphic)(other)                                | Two DataTrees are considered isomorphic if the set of paths to their descendent nodes are the same.                                                                                    |
| [`items`](xarray.DataTree.items.html.md#xarray.DataTree.items)()                                               |                                                                                                                                                                                        |
| [`iter_lineage`](xarray.DataTree.iter_lineage.html.md#xarray.DataTree.iter_lineage)()                                 | Iterate up the tree, starting from the current node.                                                                                                                                   |
| [`keys`](xarray.DataTree.keys.html.md#xarray.DataTree.keys)()                                                 |                                                                                                                                                                                        |
| [`load`](xarray.DataTree.load.html.md#xarray.DataTree.load)(\*\*kwargs)                                       | Manually trigger loading and/or computation of this datatree's data from disk or a remote source into memory and return this datatree.                                                 |
| [`map_over_datasets`](xarray.DataTree.map_over_datasets.html.md#xarray.DataTree.map_over_datasets)(func, \*args[, kwargs]) | Apply a function to every dataset in this subtree, returning a new tree which stores the results.                                                                                      |
| [`match`](xarray.DataTree.match.html.md#xarray.DataTree.match)(pattern)                                        | Return nodes with paths matching pattern.                                                                                                                                              |
| [`max`](xarray.DataTree.max.html.md#xarray.DataTree.max)([dim, skipna, keep_attrs])                          | Reduce this DataTree's data by applying `max` (i.e., maximum) along some dimension(s).                                                                                                 |
| [`mean`](xarray.DataTree.mean.html.md#xarray.DataTree.mean)([dim, skipna, keep_attrs])                        | Reduce this DataTree's data by applying `mean` along some dimension(s).                                                                                                                |
| [`median`](xarray.DataTree.median.html.md#xarray.DataTree.median)([dim, skipna, keep_attrs])                    | Reduce this DataTree's data by applying `median` along some dimension(s).                                                                                                              |
| [`min`](xarray.DataTree.min.html.md#xarray.DataTree.min)([dim, skipna, keep_attrs])                          | Reduce this DataTree's data by applying `min` (i.e., minimum) along some dimension(s).                                                                                                 |
| [`orphan`](xarray.DataTree.orphan.html.md#xarray.DataTree.orphan)()                                             | Detach this node from its parent.                                                                                                                                                      |
| [`persist`](xarray.DataTree.persist.html.md#xarray.DataTree.persist)(\*\*kwargs)                                 | Trigger computation, keeping data as chunked arrays.                                                                                                                                   |
| [`pipe`](xarray.DataTree.pipe.html.md#xarray.DataTree.pipe)(func, \*args, \*\*kwargs)                         | Apply `func(self, *args, **kwargs)`                                                                                                                                                    |
| [`prod`](xarray.DataTree.prod.html.md#xarray.DataTree.prod)([dim, skipna, min_count, keep_attrs])             | Reduce this DataTree's data by applying `prod` (i.e., product) along some dimension(s).                                                                                                |
| `prune`([drop_size_zero_vars])                                                                                               | Remove empty nodes from the tree.                                                                                                                                                      |
| `reduce`(func[, dim, keep_attrs, keepdims, ...])                                                                             | Reduce this tree by applying func along some dimension(s).                                                                                                                             |
| [`relative_to`](xarray.DataTree.relative_to.html.md#xarray.DataTree.relative_to)(other)                              | Compute the relative path from this node to node other.                                                                                                                                |
| [`round`](xarray.DataTree.round.html.md#xarray.DataTree.round)(\*args, \*\*kwargs)                             |                                                                                                                                                                                        |
| [`same_tree`](xarray.DataTree.same_tree.html.md#xarray.DataTree.same_tree)(other)                                  | True if other node is in the same tree as this node.                                                                                                                                   |
| [`sel`](xarray.DataTree.sel.html.md#xarray.DataTree.sel)([indexers, method, tolerance, drop])                | Returns a new data tree with each array indexed by tick labels along the specified dimension(s).                                                                                       |
| `set_close`(close)                                                                                                           | Set the closer for this node.                                                                                                                                                          |
| [`std`](xarray.DataTree.std.html.md#xarray.DataTree.std)([dim, skipna, ddof, keep_attrs])                    | Reduce this DataTree's data by applying `std` (i.e., standard deviation) along some dimension(s).                                                                                      |
| [`sum`](xarray.DataTree.sum.html.md#xarray.DataTree.sum)([dim, skipna, min_count, keep_attrs])               | Reduce this DataTree's data by applying `sum` along some dimension(s).                                                                                                                 |
| [`to_dataset`](xarray.DataTree.to_dataset.html.md#xarray.DataTree.to_dataset)([inherit])                            | Return the data in this node as a new xarray.Dataset object.                                                                                                                           |
| [`to_dict`](xarray.DataTree.to_dict.html.md#xarray.DataTree.to_dict)([relative])                                 | Create a dictionary mapping of paths to the data contained in those nodes.                                                                                                             |
| [`to_netcdf`](xarray.DataTree.to_netcdf.html.md#xarray.DataTree.to_netcdf)([filepath, mode, encoding, ...])        | Write datatree contents to a netCDF file.                                                                                                                                              |
| [`to_zarr`](xarray.DataTree.to_zarr.html.md#xarray.DataTree.to_zarr)(store[, mode, encoding, ...])               | Write datatree contents to a Zarr store.                                                                                                                                               |
| [`update`](xarray.DataTree.update.html.md#xarray.DataTree.update)(other)                                        | Update this node's children and / or variables.                                                                                                                                        |
| [`values`](xarray.DataTree.values.html.md#xarray.DataTree.values)()                                             |                                                                                                                                                                                        |
| [`var`](xarray.DataTree.var.html.md#xarray.DataTree.var)([dim, skipna, ddof, keep_attrs])                    | Reduce this DataTree's data by applying `var` (i.e., variance) along some dimension(s).                                                                                                |

### Attributes

| [`ancestors`](xarray.DataTree.ancestors.html.md#xarray.DataTree.ancestors)                 | All parent nodes and their parent nodes, starting with the most distant.      |
|------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|
| [`attrs`](xarray.DataTree.attrs.html.md#xarray.DataTree.attrs)                         | Dictionary of global attributes on this node object.                          |
| [`children`](xarray.DataTree.children.html.md#xarray.DataTree.children)                   | Child nodes of this node, stored under a mapping via their names.             |
| [`chunksizes`](xarray.DataTree.chunksizes.html.md#xarray.DataTree.chunksizes)               | Mapping from group paths to a mapping of chunksizes.                          |
| [`coords`](xarray.DataTree.coords.html.md#xarray.DataTree.coords)                       | Dictionary of xarray.DataArray objects corresponding to coordinate variables  |
| [`data_vars`](xarray.DataTree.data_vars.html.md#xarray.DataTree.data_vars)                 | Dictionary of DataArray objects corresponding to data variables               |
| [`dataset`](xarray.DataTree.dataset.html.md#xarray.DataTree.dataset)                     | An immutable Dataset-like view onto the data in this node.                    |
| [`depth`](xarray.DataTree.depth.html.md#xarray.DataTree.depth)                         | Maximum level of this tree.                                                   |
| [`descendants`](xarray.DataTree.descendants.html.md#xarray.DataTree.descendants)             | Child nodes and all their child nodes.                                        |
| [`dims`](xarray.DataTree.dims.html.md#xarray.DataTree.dims)                           | Mapping from dimension names to lengths.                                      |
| [`ds`](xarray.DataTree.ds.html.md#xarray.DataTree.ds)                               | An immutable Dataset-like view onto the data in this node.                    |
| [`encoding`](xarray.DataTree.encoding.html.md#xarray.DataTree.encoding)                   | Dictionary of global encoding attributes on this node object.                 |
| [`groups`](xarray.DataTree.groups.html.md#xarray.DataTree.groups)                       | Return all groups in the tree, given as a tuple of path-like strings.         |
| [`has_attrs`](xarray.DataTree.has_attrs.html.md#xarray.DataTree.has_attrs)                 | Whether or not there are any metadata attributes in this node.                |
| [`has_data`](xarray.DataTree.has_data.html.md#xarray.DataTree.has_data)                   | Whether or not there are any variables in this node.                          |
| [`indexes`](xarray.DataTree.indexes.html.md#xarray.DataTree.indexes)                     | Mapping of pandas.Index objects used for label based indexing.                |
| [`is_empty`](xarray.DataTree.is_empty.html.md#xarray.DataTree.is_empty)                   | False if node contains any data or attrs.                                     |
| [`is_hollow`](xarray.DataTree.is_hollow.html.md#xarray.DataTree.is_hollow)                 | True if only leaf nodes contain data.                                         |
| [`is_leaf`](xarray.DataTree.is_leaf.html.md#xarray.DataTree.is_leaf)                     | Whether this node is a leaf node.                                             |
| [`is_root`](xarray.DataTree.is_root.html.md#xarray.DataTree.is_root)                     | Whether this node is the tree root.                                           |
| [`leaves`](xarray.DataTree.leaves.html.md#xarray.DataTree.leaves)                       | All leaf nodes.                                                               |
| [`level`](xarray.DataTree.level.html.md#xarray.DataTree.level)                         | Level of this node.                                                           |
| [`lineage`](xarray.DataTree.lineage.html.md#xarray.DataTree.lineage)                     | All parent nodes and their parent nodes, starting with the closest.           |
| [`name`](xarray.DataTree.name.html.md#xarray.DataTree.name)                           | The name of this node.                                                        |
| [`nbytes`](xarray.DataTree.nbytes.html.md#xarray.DataTree.nbytes)                       |                                                                               |
| [`parent`](xarray.DataTree.parent.html.md#xarray.DataTree.parent)                       | Parent of this node.                                                          |
| [`parents`](xarray.DataTree.parents.html.md#xarray.DataTree.parents)                     | All parent nodes and their parent nodes, starting with the closest.           |
| [`path`](xarray.DataTree.path.html.md#xarray.DataTree.path)                           | Return the file-like path from the root to this node.                         |
| [`root`](xarray.DataTree.root.html.md#xarray.DataTree.root)                           | Root node of the tree                                                         |
| [`siblings`](xarray.DataTree.siblings.html.md#xarray.DataTree.siblings)                   | Nodes with the same parent as this node.                                      |
| [`sizes`](xarray.DataTree.sizes.html.md#xarray.DataTree.sizes)                         | Mapping from dimension names to lengths.                                      |
| [`subtree`](xarray.DataTree.subtree.html.md#xarray.DataTree.subtree)                     | Iterate over all nodes in this tree, including both self and all descendants. |
| [`subtree_with_keys`](xarray.DataTree.subtree_with_keys.html.md#xarray.DataTree.subtree_with_keys) | Iterate over relative paths and node pairs for all nodes in this tree.        |
| [`variables`](xarray.DataTree.variables.html.md#xarray.DataTree.variables)                 | Low level interface to node contents as dict of Variable objects.             |
| [`width`](xarray.DataTree.width.html.md#xarray.DataTree.width)                         | Number of nodes at this level in the tree.                                    |
| [`xindexes`](xarray.DataTree.xindexes.html.md#xarray.DataTree.xindexes)                   | Mapping of xarray Index objects used for label based indexing.                |
