Skip to content

Commit

Permalink
add backend intro and how-to diagram (#9175)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Jul 22, 2024
1 parent 9166eb2 commit 95e67b6
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/internals/how-to-add-new-backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ How to add a new backend
------------------------

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

- Create a class that inherits from Xarray :py:class:`~xarray.backends.BackendEntrypoint`
and implements the method ``open_dataset`` see :ref:`RST backend_entrypoint`
Expand Down
75 changes: 75 additions & 0 deletions doc/user-guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,81 @@ format (recommended).
np.random.seed(123456)
You can `read different types of files <https://docs.xarray.dev/en/stable/user-guide/io.html>`_
in `xr.open_dataset` by specifying the engine to be used:

.. ipython:: python
:okexcept:
:suppress:
import xarray as xr
xr.open_dataset("my_file.grib", engine="cfgrib")
The "engine" provides a set of instructions that tells xarray how
to read the data and pack them into a `dataset` (or `dataarray`).
These instructions are stored in an underlying "backend".

Xarray comes with several backends that cover many common data formats.
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>`_.
This diagram aims to help you determine - based on the format of the file you'd like to read -
which type of backend you're using and how to use it.

Text and boxes are clickable for more information.
Following the diagram is detailed information on many popular backends.
You can learn more about using and developing backends in the
`Xarray tutorial JupyterBook <https://tutorial.xarray.dev/advanced/backends/backends.html>`_.

.. mermaid::
:alt: Flowchart illustrating how to choose the right backend engine to read your data

flowchart LR
built-in-eng["""Is your data stored in one of these formats?
- netCDF4 (<code>netcdf4</code>)
- netCDF3 (<code>scipy</code>)
- Zarr (<code>zarr</code>)
- DODS/OPeNDAP (<code>pydap</code>)
- HDF5 (<code>h5netcdf</code>)
"""]

built-in("""You're in luck! Xarray bundles a backend for this format.
Open data using <code>xr.open_dataset()</code>. We recommend
always setting the engine you want to use.""")

installed-eng["""One of these formats?
- <a href='https://github.com/ecmwf/cfgrib'>GRIB (<code>cfgrib</code>)
- <a href='https://tiledb-inc.github.io/TileDB-CF-Py/documentation/index.html'>TileDB (<code>tiledb</code>)
- <a href='https://corteva.github.io/rioxarray/stable/getting_started/getting_started.html#rioxarray'>GeoTIFF, JPEG-2000, ESRI-hdf (<code>rioxarray</code>, via GDAL)
- <a href='https://www.bopen.eu/xarray-sentinel-open-source-library/'>Sentinel-1 SAFE (<code>xarray-sentinel</code>)
"""]

installed("""Install the package indicated in parentheses to your
Python environment. Restart the kernel and use
<code>xr.open_dataset(files, engine='rioxarray')</code>.""")

other("""Ask around to see if someone in your data community
has created an Xarray backend for your data type.
If not, you may need to create your own or consider
exporting your data to a more common format.""")

built-in-eng -->|Yes| built-in
built-in-eng -->|No| installed-eng

installed-eng -->|Yes| installed
installed-eng -->|No| other

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"
click other "https://docs.xarray.dev/en/stable/internals/how-to-add-new-backend.html"

classDef quesNodefmt fill:#9DEEF4,stroke:#206C89,text-align:left
class built-in-eng,installed-eng quesNodefmt

classDef ansNodefmt fill:#FFAA05,stroke:#E37F17,text-align:left,white-space:nowrap
class built-in,installed,other ansNodefmt

linkStyle default font-size:20pt,color:#206C89


.. _io.netcdf:

netCDF
Expand Down
4 changes: 3 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ Bug fixes
Documentation
~~~~~~~~~~~~~

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

0 comments on commit 95e67b6

Please sign in to comment.