xarray.DataTree#

class xarray.DataTree(dataset=None, children=None, name=None)[source]#

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]#

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, optional) – Data to store directly at this node.

  • children (Mapping[str, DataTree], optional) – Any child nodes of this node.

  • name (str, optional) – Name for this node of the tree.

Methods

__init__([dataset, children, name])

Create a single node of a DataTree.

all([dim, keep_attrs])

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

any([dim, keep_attrs])

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

argsort([axis, kind, order, stable, descending])

Returns the indices that would sort this array.

assign([items])

Assign new data variables or child nodes to a DataTree.

chunk([chunks, name_prefix, token, lock, ...])

Coerce all arrays in all groups into dask arrays with the given chunks.

close()

Close any files associated with this tree.

compute(**kwargs)

Trigger loading data into memory and return a new datatree.

conj()

Complex-conjugate all elements.

conjugate(*args, **kwargs)

a.conj()

copy(*[, inherit, deep])

Return a copy of this subtree.

count([dim, keep_attrs])

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

cumprod([dim, skipna, keep_attrs])

Reduce this DataTree's data by applying cumprod (i.e., cumulative product) along some dimension(s).

cumsum([dim, skipna, keep_attrs])

Reduce this DataTree's data by applying cumsum (i.e., cumulative sum) along some dimension(s).

drop_nodes(names, *[, errors])

Drop child nodes from this node.

equals(other)

Check whether two DataTrees are equal.

filter(filterfunc)

Filter nodes according to a specified condition.

filter_like(other)

Filter a datatree like another datatree.

find_common_ancestor(other)

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

from_dict([data, coords, name, nested])

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

get(key[, default])

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

identical(other)

Check whether two DataTrees are identical.

isel([indexers, drop, missing_dims])

Return a new data tree with each array indexed along the given dimension(s).

isomorphic(other)

Check whether two DataTrees are isomorphic.

items()

iter_lineage()

Iterate up the tree, starting from the current node.

keys()

load(**kwargs)

Trigger loading data into memory and return this 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(pattern)

Return nodes with paths matching pattern.

max([dim, skipna, keep_attrs])

Reduce this DataTree's data by applying max (i.e., maximum) along some dimension(s).

mean([dim, skipna, keep_attrs])

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

median([dim, skipna, keep_attrs])

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

min([dim, skipna, keep_attrs])

Reduce this DataTree's data by applying min (i.e., minimum) along some dimension(s).

orphan()

Detach this node from its parent.

persist(**kwargs)

Trigger computation, keeping data as chunked arrays.

pipe(func, *args, **kwargs)

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

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(other)

Compute the relative path from this node to node other.

round(*args, **kwargs)

same_tree(other)

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

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

Return a new data tree with each array indexed by tick labels.

set_close(close)

Set the closer for this node.

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

Reduce this DataTree's data by applying std (i.e., standard deviation) along some dimension(s).

sum([dim, skipna, min_count, keep_attrs])

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

to_dataset([inherit])

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

to_dict([relative])

Create a dictionary mapping of paths to the data contained in those nodes.

to_netcdf([filepath, mode, encoding, ...])

Write datatree contents to a netCDF file.

to_zarr(store[, mode, encoding, ...])

Write datatree contents to a Zarr store.

update(other)

Update this node's children and / or variables.

values()

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

Reduce this DataTree's data by applying var (i.e., variance) along some dimension(s).

Attributes

ancestors

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

attrs

Dictionary of global attributes on this node object.

children

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

chunksizes

Mapping from group paths to a mapping of chunksizes.

coords

Dictionary of DataArray objects corresponding to coordinate variables.

data_vars

Dictionary of DataArray objects corresponding to data variables.

dataset

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

depth

Maximum level of this tree.

descendants

Child nodes and all their child nodes.

dims

Mapping from dimension names to lengths.

ds

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

encoding

Dictionary of global encoding attributes on this node object.

groups

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

has_attrs

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

has_data

Whether or not there are any variables in this node.

indexes

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

is_empty

False if node contains any data or attrs.

is_hollow

True if only leaf nodes contain data.

is_leaf

Whether this node is a leaf node.

is_root

Whether this node is the tree root.

leaves

All leaf nodes.

level

Level of this node.

lineage

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

name

The name of this node.

nbytes

parent

Parent of this node.

parents

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

path

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

root

Root node of the tree.

siblings

Nodes with the same parent as this node.

sizes

Mapping from dimension names to lengths.

subtree

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

subtree_with_keys

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

variables

Low level interface to node contents as dict of Variable objects.

width

Number of nodes at this level in the tree.

xindexes

Mapping of xarray Index objects used for label based indexing.