Skip to content

Commit 95e67b6

Browse files
JessicaS11pre-commit-ci[bot]max-sixty
authored
add backend intro and how-to diagram (#9175)
* add backend intro and how-to diagram * update what's new * fix link style [skip-ci] * update numpy nan syntax to address docs build fail [skip-ci] * improve some spacing on diagram * fix items not rendering properly due to typos [skip-ci] * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update python syntax * use html code blocks to fix spacing [skip-ci] * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * suppress ipython block output * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * change to okexcept [skip-ci] * re-add supress so error output is ignored [skip-ci] * Update doc/user-guide/io.rst * add per-line links to diagram [skip-ci] --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maximilian Roos <[email protected]>
1 parent 9166eb2 commit 95e67b6

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

doc/internals/how-to-add-new-backend.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ How to add a new backend
44
------------------------
55

66
Adding a new backend for read support to Xarray does not require
7-
to integrate any code in Xarray; all you need to do is:
7+
one to integrate any code in Xarray; all you need to do is:
88

99
- Create a class that inherits from Xarray :py:class:`~xarray.backends.BackendEntrypoint`
1010
and implements the method ``open_dataset`` see :ref:`RST backend_entrypoint`

doc/user-guide/io.rst

+75
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,81 @@ format (recommended).
1919
2020
np.random.seed(123456)
2121
22+
You can `read different types of files <https://docs.xarray.dev/en/stable/user-guide/io.html>`_
23+
in `xr.open_dataset` by specifying the engine to be used:
24+
25+
.. ipython:: python
26+
:okexcept:
27+
:suppress:
28+
29+
import xarray as xr
30+
31+
xr.open_dataset("my_file.grib", engine="cfgrib")
32+
33+
The "engine" provides a set of instructions that tells xarray how
34+
to read the data and pack them into a `dataset` (or `dataarray`).
35+
These instructions are stored in an underlying "backend".
36+
37+
Xarray comes with several backends that cover many common data formats.
38+
Many more backends are available via external libraries, or you can `write your own <https://docs.xarray.dev/en/stable/internals/how-to-add-new-backend.html>`_.
39+
This diagram aims to help you determine - based on the format of the file you'd like to read -
40+
which type of backend you're using and how to use it.
41+
42+
Text and boxes are clickable for more information.
43+
Following the diagram is detailed information on many popular backends.
44+
You can learn more about using and developing backends in the
45+
`Xarray tutorial JupyterBook <https://tutorial.xarray.dev/advanced/backends/backends.html>`_.
46+
47+
.. mermaid::
48+
:alt: Flowchart illustrating how to choose the right backend engine to read your data
49+
50+
flowchart LR
51+
built-in-eng["""Is your data stored in one of these formats?
52+
- netCDF4 (<code>netcdf4</code>)
53+
- netCDF3 (<code>scipy</code>)
54+
- Zarr (<code>zarr</code>)
55+
- DODS/OPeNDAP (<code>pydap</code>)
56+
- HDF5 (<code>h5netcdf</code>)
57+
"""]
58+
59+
built-in("""You're in luck! Xarray bundles a backend for this format.
60+
Open data using <code>xr.open_dataset()</code>. We recommend
61+
always setting the engine you want to use.""")
62+
63+
installed-eng["""One of these formats?
64+
- <a href='https://github.com/ecmwf/cfgrib'>GRIB (<code>cfgrib</code>)
65+
- <a href='https://tiledb-inc.github.io/TileDB-CF-Py/documentation/index.html'>TileDB (<code>tiledb</code>)
66+
- <a href='https://corteva.github.io/rioxarray/stable/getting_started/getting_started.html#rioxarray'>GeoTIFF, JPEG-2000, ESRI-hdf (<code>rioxarray</code>, via GDAL)
67+
- <a href='https://www.bopen.eu/xarray-sentinel-open-source-library/'>Sentinel-1 SAFE (<code>xarray-sentinel</code>)
68+
"""]
69+
70+
installed("""Install the package indicated in parentheses to your
71+
Python environment. Restart the kernel and use
72+
<code>xr.open_dataset(files, engine='rioxarray')</code>.""")
73+
74+
other("""Ask around to see if someone in your data community
75+
has created an Xarray backend for your data type.
76+
If not, you may need to create your own or consider
77+
exporting your data to a more common format.""")
78+
79+
built-in-eng -->|Yes| built-in
80+
built-in-eng -->|No| installed-eng
81+
82+
installed-eng -->|Yes| installed
83+
installed-eng -->|No| other
84+
85+
click built-in-eng "https://docs.xarray.dev/en/stable/getting-started-guide/faq.html#how-do-i-open-format-x-file-as-an-xarray-dataset"
86+
click other "https://docs.xarray.dev/en/stable/internals/how-to-add-new-backend.html"
87+
88+
classDef quesNodefmt fill:#9DEEF4,stroke:#206C89,text-align:left
89+
class built-in-eng,installed-eng quesNodefmt
90+
91+
classDef ansNodefmt fill:#FFAA05,stroke:#E37F17,text-align:left,white-space:nowrap
92+
class built-in,installed,other ansNodefmt
93+
94+
linkStyle default font-size:20pt,color:#206C89
95+
96+
2297
.. _io.netcdf:
2398

2499
netCDF

doc/whats-new.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ Bug fixes
8484
Documentation
8585
~~~~~~~~~~~~~
8686

87-
- Adds a flow-chart diagram to help users navigate help resources (`Discussion #8990 <https://github.com/pydata/xarray/discussions/8990>`_).
87+
- Adds intro to backend section of docs, including a flow-chart to navigate types of backends (:pull:`9175`).
88+
By `Jessica Scheick <https://github.com/jessicas11>`_.
89+
- Adds a flow-chart diagram to help users navigate help resources (`Discussion #8990 <https://github.com/pydata/xarray/discussions/8990>`_, :pull:`9147`).
8890
By `Jessica Scheick <https://github.com/jessicas11>`_.
8991
- Improvements to Zarr & chunking docs (:pull:`9139`, :pull:`9140`, :pull:`9132`)
9092
By `Maximilian Roos <https://github.com/max-sixty>`_.

0 commit comments

Comments
 (0)