Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.

Commit c14078b

Browse files
Added docs page on io (#158)
* added page on io * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * whatsnew * fix typo which inverted meaning of key sentence * fix headings and link * add missing links * fix final link Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 711c83c commit c14078b

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

docs/source/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Datatree
1212
Quick Overview <quick-overview>
1313
Tutorial <tutorial>
1414
Data Model <data-structures>
15+
Reading and Writing Files <io>
1516
API Reference <api>
1617
How do I ... <howdoi>
1718
Contributing Guide <contributing>

docs/source/io.rst

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
.. _data structures:
2+
3+
Reading and Writing Files
4+
=========================
5+
6+
.. note::
7+
8+
This page builds on the information given in xarray's main page on
9+
`reading and writing files <https://docs.xarray.dev/en/stable/user-guide/io.html>`_,
10+
so it is suggested that you are familiar with those first.
11+
12+
13+
netCDF
14+
------
15+
16+
Groups
17+
~~~~~~
18+
19+
Whilst netCDF groups can only be loaded individually as Dataset objects, a whole file of many nested groups can be loaded
20+
as a single ``:py:class::DataTree`` object.
21+
To open a whole netCDF file as a tree of groups use the ``:py:func::open_datatree()`` function.
22+
To save a DataTree object as a netCDF file containing many groups, use the ``:py:meth::DataTree.to_netcdf()`` method.
23+
24+
25+
.. _netcdf.group.warning:
26+
27+
.. warning::
28+
``DataTree`` objects do not follow the exact same data model as netCDF files, which means that perfect round-tripping
29+
is not always possible.
30+
31+
In particular in the netCDF data model dimensions are entities that can exist regardless of whether any variable possesses them.
32+
This is in contrast to `xarray's data model <https://docs.xarray.dev/en/stable/user-guide/data-structures.html>`_
33+
(and hence :ref:`datatree's data model<data structures>`) in which the dimensions of a (Dataset/Tree)
34+
object are simply the set of dimensions present across all variables in that dataset.
35+
36+
This means that if a netCDF file contains dimensions but no variables which possess those dimensions,
37+
these dimensions will not be present when that file is opened as a DataTree object.
38+
Saving this DataTree object to file will therefore not preserve these "unused" dimensions.
39+
40+
Zarr
41+
----
42+
43+
Groups
44+
~~~~~~
45+
46+
Nested groups in zarr stores can be represented by loading the store as a ``:py:class::DataTree`` object, similarly to netCDF.
47+
To open a whole zarr store as a tree of groups use the ``:py:func::open_datatree()`` function.
48+
To save a DataTree object as a zarr store containing many groups, use the ``:py:meth::DataTree.to_zarr()`` method.
49+
50+
.. note::
51+
Note that perfect round-tripping should always be possible with a zarr store (:ref:`unlike for netCDF files<netcdf.group.warning>`),
52+
as zarr does not support "unused" dimensions.

docs/source/whats-new.rst

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Bug fixes
4040
Documentation
4141
~~~~~~~~~~~~~
4242

43+
- Added ``Reading and Writing Files`` page. (:pull:`158`)
44+
By `Tom Nicholas <https://github.com/TomNicholas>`_.
45+
4346
Internal Changes
4447
~~~~~~~~~~~~~~~~
4548

0 commit comments

Comments
 (0)