You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 24, 2024. It is now read-only.
* why hierarchical data
* add hierarchical data page to index
* Simpsons family tree
* evolutionary tree
* WIP rearrangement of creating trees
* fixed examples in data structures page
* dict-like navigation
* filesystem-like paths explained
* split PR into parts
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update docs/source/data-structures.rst
Co-authored-by: Justus Magin <[email protected]>
* black
* whatsnew
* get assign example working
* fix some links to methods
* relative_to example
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Justus Magin <[email protected]>
or by dynamically updating the attributes of one node to refer to another:
105
106
106
107
.. ipython:: python
107
108
108
-
# add a grandparent by updating the .parent property of an existing node
109
-
node0 = DataTree(name="General Sherman")
110
-
node1.parent = node0
109
+
# add a second child by first creating a new node ...
110
+
ds3 = xr.Dataset({"zed": np.NaN})
111
+
node3 = DataTree(name="b", data=ds3)
112
+
# ... then updating its .parent property
113
+
node3.parent = dt
111
114
112
-
Our tree now has three nodes within it, and one of the two new nodes has become the new root:
115
+
Our tree now has three nodes within it:
113
116
114
117
.. ipython:: python
115
118
116
-
node0
119
+
dt
117
120
118
-
Is is at tree construction time that consistency checks are enforced. For instance, if we try to create a `cycle` the constructor will raise an error:
121
+
It is at tree construction time that consistency checks are enforced. For instance, if we try to create a `cycle` the constructor will raise an error:
119
122
120
123
.. ipython:: python
121
124
:okexcept:
122
125
123
-
node0.parent = node2
124
-
125
-
The second way is to build the tree from a dictionary of filesystem-like paths and corresponding ``xarray.Dataset`` objects.
126
-
127
-
This relies on a syntax inspired by unix-like filesystems, where the "path" to a node is specified by the keys of each intermediate node in sequence,
128
-
separated by forward slashes. The root node is referred to by ``"/"``, so the path from our current root node to its grand-child would be ``"/Oak/Bonsai"``.
129
-
A path specified from the root (as opposed to being specified relative to an arbitrary node in the tree) is sometimes also referred to as a
Alternatively you can also create a ``DataTree`` object from
145
129
146
-
Notice that this method will also create any intermediate empty node necessary to reach the end of the specified path
147
-
(i.e. the node labelled `"c"` in this case.)
148
-
149
-
Finally the third way is from a file. if you have a file containing data on disk (such as a netCDF file or a Zarr Store), you can also create a datatree by opening the
150
-
file using ``:py:func::~datatree.open_datatree``. See the page on :ref:`reading and writing files <io>` for more details.
130
+
- An ``xarray.Dataset`` using ``Dataset.to_node()`` (not yet implemented),
131
+
- A dictionary mapping directory-like paths to either ``DataTree`` nodes or data, using ``DataTree.from_dict()``,
132
+
- A netCDF or Zarr file on disk with ``open_datatree()``. See :ref:`reading and writing files <io>`.
151
133
152
134
153
135
DataTree Contents
@@ -187,20 +169,17 @@ Like with ``Dataset``, you can access the data and coordinate variables of a nod
187
169
Dictionary-like methods
188
170
~~~~~~~~~~~~~~~~~~~~~~~
189
171
190
-
We can update the contents of the tree in-place using a dictionary-like syntax.
191
-
192
172
We can update a datatree in-place using Python's standard dictionary syntax, similar to how we can for Dataset objects.
193
173
For example, to create this example datatree from scratch, we could have written:
194
174
195
175
# TODO update this example using ``.coords`` and ``.data_vars`` as setters,
0 commit comments