Attention
This repository has been archived. Please use xarray.DataTree instead.
API reference#
DataTree#
Creating a DataTree#
Methods of creating a datatree.
|
A tree-like hierarchical collection of xarray objects. |
|
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
.
Parent of this node. |
|
Child nodes of this node, stored under a mapping via their names. |
|
The name of this node. |
|
Return the file-like path from the root to this node. |
|
Root node of the tree |
|
Whether this node is the tree root. |
|
Whether this node is a leaf node. |
|
All leaf nodes. |
|
Level of this node. |
|
Maximum level of this tree. |
|
Number of nodes at this level in the tree. |
|
An iterator over all nodes in this tree, including both self and all descendants. |
|
Child nodes and all their child nodes. |
|
Nodes with the same parent as this node. |
|
All parent nodes and their parent nodes, starting with the closest. |
|
All parent nodes and their parent nodes, starting with the closest. |
|
All parent nodes and their parent nodes, starting with the most distant. |
|
Return all netCDF4 groups in the tree, given as a tuple of path-like strings. |
Data Contents#
Interface to the data objects (optionally) stored inside a single DataTree
node.
This interface echoes that of xarray.Dataset
.
Mapping from dimension names to lengths. |
|
Mapping from dimension names to lengths. |
|
Dictionary of DataArray objects corresponding to data variables |
|
Dictionary of xarray.DataArray objects corresponding to coordinate variables |
|
Dictionary of global attributes on this node object. |
|
Dictionary of global encoding attributes on this node object. |
|
Mapping of pandas.Index objects used for label based indexing. |
|
An immutable Dataset-like view onto the data in this node. |
|
Return the data in this node as a new xarray.Dataset object. |
|
Whether or not there are any data variables in this node. |
|
Whether or not there are any metadata attributes in this node. |
|
False if node contains any data or attrs. |
|
True if only leaf nodes contain data. |
Dictionary Interface#
DataTree
objects also have a dict-like interface mapping keys to either xarray.DataArray``s or to child ``DataTree
nodes.
|
Access child nodes, variables, or coordinates stored anywhere in this tree. |
|
Add either a child node or an array to the tree, at any position. |
|
Remove a child node from this tree object. |
|
Update this node's children and / or variables. |
|
Access child nodes, variables, or coordinates stored in this node. |
Tree Manipulation#
For manipulating, traversing, navigating, or mapping over the tree structure.
Detach this node from its parent. |
|
|
True if other node is in the same tree as this node. |
|
Compute the relative path from this node to node other. |
Iterate up the tree, starting from the current node. |
|
Find the first common ancestor of two nodes in the same tree. |
|
|
Apply a function to every dataset in this subtree, returning a new tree which stores the results. |
|
Decorator which turns a function which acts on (and returns) Datasets into one which acts on and returns DataTrees. |
|
Apply |
|
Return nodes with paths matching pattern. |
|
Filter nodes according to a specified condition. |
Pathlib-like Interface#
DataTree
objects deliberately echo some of the API of pathlib.PurePath.
The name of this node. |
|
Parent of this node. |
|
All parent nodes and their parent nodes, starting with the closest. |
|
|
Compute the relative path from this node to node other. |
Missing:
DataTree.glob
DataTree.joinpath
DataTree.with_name
DataTree.walk
DataTree.rename
DataTree.replace
DataTree Contents#
Manipulate the contents of all nodes in a tree simultaneously.
|
Returns a copy of this subtree. |
|
Assign new coordinates to this object. |
|
Merge all the leaves of a second DataTree into this one. |
|
Returns a new object with renamed variables, coordinates and dimensions. |
|
Returns a new object with renamed variables including coordinates |
|
Returns a new object with renamed dimensions only. |
|
Returns a new object with swapped dimensions. |
|
Return a new object with an additional axis (or axes) inserted at the corresponding position in the array shape. |
|
Drop variables from this dataset. |
|
Drop dimensions and associated variables from this dataset. |
|
Given names of one or more variables, set them as coordinates |
|
Given names of coordinates, reset them to become variables |
DataTree Node Contents#
Manipulate the contents of a single DataTree node.
|
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. |
|
Drop child nodes from this node. |
Comparisons#
Compare one DataTree
object to another.
|
Two DataTrees are considered isomorphic if every node has the same number of children. |
|
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. |
|
Like equals, but will also check all dataset attributes and the attributes on all variables and coordinates. |
Indexing#
Index into all nodes in the subtree simultaneously.
|
Returns a new dataset with each array indexed along the specified dimension(s). |
|
Returns a new dataset with each array indexed by tick labels along the specified dimension(s). |
|
Drop index labels from this dataset. |
|
Drop index positions from this Dataset. |
|
Returns a new dataset with the first n values of each array for the specified dimension(s). |
|
Returns a new dataset with the last n values of each array for the specified dimension(s). |
|
Returns a new dataset with each array indexed along every n-th value for the specified dimension(s) |
|
Return a new object with squeezed data. |
|
Interpolate a Dataset onto new coordinates |
|
Interpolate this object onto the coordinates of another object, filling the out of range values with NaN. |
|
Conform this object onto a new set of indexes, filling in missing values with |
|
Conform this object onto the indexes of another object, for indexes which the objects share. |
|
Set Dataset (multi-)indexes using one or more existing coordinates or variables. |
|
Reset the specified index(es) or multi-index level(s). |
|
Rearrange index levels using input order. |
|
Return a new dataset with each array indexed along the specified dimension(s), where the indexers are given as strings containing Python expressions to be evaluated against the data variables in the dataset. |
Missing:
DataTree.loc
Missing Value Handling#
|
Test each value in the array for whether it is a missing value. |
|
Test each value in the array for whether it is not a missing value. |
|
Combine two Datasets, default to data_vars of self. |
|
Returns a new dataset with dropped labels for missing values along the provided dimension. |
|
Fill missing values in this object. |
|
Fill NaN values by propagating values forward |
|
Fill NaN values by propagating values backward |
|
Fill in NaNs by interpolating according to different methods. |
|
Filter elements from this object according to a condition. |
|
Tests each value in the array for whether it is in test elements. |
Computation#
Apply a computation to the data in all nodes in the subtree simultaneously.
|
Apply a function to each data variable in this dataset |
|
Reduce this dataset by applying func along some dimension(s). |
|
Calculate the n-th order discrete difference along given axis. |
|
Compute the qth quantile of the data along the specified dimension. |
|
Differentiate with the second order accurate central differences. |
|
Integrate along the given coordinate using the trapezoidal rule. |
|
Apply a function to each block of this Dataset. |
|
Least squares polynomial fit. |
|
Curve fitting optimization for arbitrary functions. |
Aggregation#
Aggregate data in all nodes in the subtree simultaneously.
|
Reduce this Dataset's data by applying |
|
Reduce this Dataset's data by applying |
|
Indices of the maxima of the member variables. |
|
Indices of the minima of the member variables. |
|
Return the coordinate label of the maximum value along a dimension. |
|
Return the coordinate label of the minimum value along a dimension. |
|
Reduce this Dataset's data by applying |
|
Reduce this Dataset's data by applying |
|
Reduce this Dataset's data by applying |
|
Reduce this Dataset's data by applying |
|
Reduce this Dataset's data by applying |
|
Reduce this Dataset's data by applying |
|
Reduce this Dataset's data by applying |
|
Reduce this Dataset's data by applying |
|
Reduce this Dataset's data by applying |
|
Reduce this Dataset's data by applying |
ndarray methods#
Methods copied from numpy.ndarray
objects, here applying to the data in all nodes in the subtree.
|
Returns the indices that would sort this array. |
|
Copy of the xarray object, with data cast to a specified type. |
|
Return an array whose values are limited to |
Complex-conjugate all elements. |
|
Return the complex conjugate, element-wise. |
|
|
Round an array to the given number of decimals. |
|
Ranks the data. |
Reshaping and reorganising#
Reshape or reorganise the data in all nodes in the subtree.
|
Return a new Dataset object with all array dimensions transposed. |
|
Stack any number of existing dimensions into a single new dimension. |
|
Unstack existing dimensions corresponding to MultiIndexes into multiple new dimensions. |
|
Shift this dataset by an offset along one or more dimensions. |
|
Roll this dataset by an offset along one or more dimensions. |
|
Pad this dataset along one or more dimensions. |
|
Sort object by labels or values (along an axis). |
|
Broadcast this DataArray against another Dataset or DataArray. |
Plotting#
I/O#
Open a datatree from an on-disk store or serialize the tree.
|
Open and decode a dataset from a file or file-like object, creating one Tree node for each group in the file. |
Create a dictionary mapping of absolute node paths to the data contained in those nodes. |
|
|
Write datatree contents to a netCDF file. |
|
Write datatree contents to a Zarr store. |
Missing:
open_mfdatatree
Tutorial#
Testing#
Test that two DataTree objects are similar.
|
Two DataTrees are considered isomorphic if every node has the same number of children. |
|
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. |
|
Like assert_equals, but will also check all dataset attributes and the attributes on all variables and coordinates. |
Exceptions#
Exceptions raised when manipulating trees.
Error raised if two tree objects do not share the same node structure. |
|
Raised when user attempts to create an invalid tree in some way. |
|
Raised when operation can't be completed because one node is part of the expected tree. |
Advanced API#
Relatively advanced API for users or developers looking to understand the internals, or extend functionality.
Low level interface to node contents as dict of Variable objects. |
|
Register a custom accessor on DataTree objects. |
Missing:
DataTree.set_close