DataTree#

Creating a DataTree#

Methods of creating a DataTree.

DataTree([dataset, children, name])

A tree-like hierarchical collection of xarray objects.

DataTree.from_dict(d, /[, name])

Create a datatree from a dictionary of data objects, organised by paths into the tree.

Tree Attributes#

Attributes relating to the recursive tree-like structure of a DataTree.

DataTree.parent

Parent of this node.

DataTree.children

Child nodes of this node, stored under a mapping via their names.

DataTree.name

The name of this node.

DataTree.path

Return the file-like path from the root to this node.

DataTree.root

Root node of the tree

DataTree.is_root

Whether this node is the tree root.

DataTree.is_leaf

Whether this node is a leaf node.

DataTree.leaves

All leaf nodes.

DataTree.level

Level of this node.

DataTree.depth

Maximum level of this tree.

DataTree.width

Number of nodes at this level in the tree.

DataTree.subtree

Iterate over all nodes in this tree, including both self and all descendants.

DataTree.subtree_with_keys

Iterate over relative paths and node pairs for all nodes in this tree.

DataTree.descendants

Child nodes and all their child nodes.

DataTree.siblings

Nodes with the same parent as this node.

DataTree.lineage

All parent nodes and their parent nodes, starting with the closest.

DataTree.parents

All parent nodes and their parent nodes, starting with the closest.

DataTree.ancestors

All parent nodes and their parent nodes, starting with the most distant.

DataTree.groups

Return all groups in the tree, given as a tuple of path-like strings.

DataTree.xindexes

Mapping of xarray Index objects used for label based indexing.

Data Contents#

Interface to the data objects (optionally) stored inside a single DataTree node. This interface echoes that of xarray.Dataset.

DataTree.dims

Mapping from dimension names to lengths.

DataTree.sizes

Mapping from dimension names to lengths.

DataTree.data_vars

Dictionary of DataArray objects corresponding to data variables

DataTree.ds

An immutable Dataset-like view onto the data in this node.

DataTree.coords

Dictionary of xarray.DataArray objects corresponding to coordinate variables

DataTree.attrs

Dictionary of global attributes on this node object.

DataTree.encoding

Dictionary of global encoding attributes on this node object.

DataTree.indexes

Mapping of pandas.Index objects used for label based indexing.

DataTree.nbytes

DataTree.dataset

An immutable Dataset-like view onto the data in this node.

DataTree.to_dataset([inherit])

Return the data in this node as a new xarray.Dataset object.

DataTree.has_data

Whether or not there are any variables in this node.

DataTree.has_attrs

Whether or not there are any metadata attributes in this node.

DataTree.is_empty

False if node contains any data or attrs.

DataTree.is_hollow

True if only leaf nodes contain data.

DataTree.chunksizes

Mapping from group paths to a mapping of chunksizes.

Dictionary Interface#

DataTree objects also have a dict-like interface mapping keys to either xarray.DataArrays or to child DataTree nodes.

DataTree.__getitem__(key)

Access child nodes, variables, or coordinates stored anywhere in this tree.

DataTree.__setitem__(key, value)

Add either a child node or an array to the tree, at any position.

DataTree.__delitem__(key)

Remove a variable or child node from this datatree node.

DataTree.update(other)

Update this node's children and / or variables.

DataTree.get(key[, default])

Access child nodes, variables, or coordinates stored in this node.

DataTree.items()

DataTree.keys()

DataTree.values()

Tree Manipulation#

For manipulating, traversing, navigating, or mapping over the tree structure.

DataTree.orphan()

Detach this node from its parent.

DataTree.same_tree(other)

True if other node is in the same tree as this node.

DataTree.relative_to(other)

Compute the relative path from this node to node other.

DataTree.iter_lineage()

Iterate up the tree, starting from the current node.

DataTree.find_common_ancestor(other)

Find the first common ancestor of two nodes in the same tree.

DataTree.map_over_datasets(func, *args[, kwargs])

Apply a function to every dataset in this subtree, returning a new tree which stores the results.

DataTree.pipe(func, *args, **kwargs)

Apply func(self, *args, **kwargs)

DataTree.match(pattern)

Return nodes with paths matching pattern.

DataTree.filter(filterfunc)

Filter nodes according to a specified condition.

DataTree.filter_like(other)

Filter a datatree like another datatree.

Pathlib-like Interface#

DataTree objects deliberately echo some of the API of pathlib.PurePath.

DataTree.name

The name of this node.

DataTree.parent

Parent of this node.

DataTree.parents

All parent nodes and their parent nodes, starting with the closest.

DataTree.relative_to(other)

Compute the relative path from this node to node other.

DataTree Contents#

Manipulate the contents of all nodes in a DataTree simultaneously.

DataTree.copy(*[, inherit, deep])

Returns a copy of this subtree.

DataTree Node Contents#

Manipulate the contents of a single DataTree node.

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.

DataTree.drop_nodes(names, *[, errors])

Drop child nodes from this node.

DataTree Operations#

Apply operations over multiple DataTree objects.

map_over_datasets(func, *args[, kwargs])

Applies a function to every dataset in one or more DataTree objects with the same structure (ie.., that are isomorphic), returning new trees which store the results.

group_subtrees(*trees)

Iterate over subtrees grouped by relative paths in breadth-first order.

Comparisons#

Compare one DataTree object to another.

DataTree.isomorphic(other)

Two DataTrees are considered isomorphic if the set of paths to their descendent nodes are the same.

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.

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.

Indexing#

Index into all nodes in the subtree simultaneously.

DataTree.isel([indexers, drop, missing_dims])

Returns a new data tree with each array indexed along the specified dimension(s).

DataTree.sel([indexers, method, tolerance, drop])

Returns a new data tree with each array indexed by tick labels along the specified dimension(s).

Aggregation#

Aggregate data in all nodes in the subtree simultaneously.

DataTree.all([dim, keep_attrs])

Reduce this DataTree's data by applying all along some dimension(s).

DataTree.any([dim, keep_attrs])

Reduce this DataTree's data by applying any along some dimension(s).

DataTree.max([dim, skipna, keep_attrs])

Reduce this DataTree's data by applying max along some dimension(s).

DataTree.min([dim, skipna, keep_attrs])

Reduce this DataTree's data by applying min along some dimension(s).

DataTree.mean([dim, skipna, keep_attrs])

Reduce this DataTree's data by applying mean along some dimension(s).

DataTree.median([dim, skipna, keep_attrs])

Reduce this DataTree's data by applying median along some dimension(s).

DataTree.prod([dim, skipna, min_count, ...])

Reduce this DataTree's data by applying prod along some dimension(s).

DataTree.sum([dim, skipna, min_count, ...])

Reduce this DataTree's data by applying sum along some dimension(s).

DataTree.std([dim, skipna, ddof, keep_attrs])

Reduce this DataTree's data by applying std along some dimension(s).

DataTree.var([dim, skipna, ddof, keep_attrs])

Reduce this DataTree's data by applying var along some dimension(s).

DataTree.cumsum([dim, skipna, keep_attrs])

Reduce this DataTree's data by applying cumsum along some dimension(s).

DataTree.cumprod([dim, skipna, keep_attrs])

Reduce this DataTree's data by applying cumprod along some dimension(s).

ndarray methods#

Methods copied from numpy.ndarray objects, here applying to the data in all nodes in the subtree.

DataTree.argsort([axis, kind, order])

Returns the indices that would sort this array.

DataTree.conj()

Complex-conjugate all elements.

DataTree.conjugate(*args, **kwargs)

a.conj()

DataTree.round(*args, **kwargs)