https://docs.xarray.dev/en/stable/_static/dataset-diagram-logo.png

A Tour of the Xarray Ecosystem#

Xarray is easily extensible. This means it is easy to add onto to build custom packages that tackle particular computational problems.

These packages can plug in to xarray in various different ways. They may build directly on top of xarray, or they may take advantage of some of xarray’s dedicated interfacing features:

  • Accessors

  • Backend (filetype) entrypoint

  • Metadata attributes

  • Duck-array wrapping interface

  • Flexible indexes (coming soon!)

Here we introduce several popular or interesting extensions that are installable as their own packages (via conda and pip). These packages integrate with xarray using one or more of the features mentioned above.

  • hvplot, a powerful interactive plotting library

  • rioxarray, for working with geospatial raster data using rasterio

  • cf-xarray, for interpreting CF-compliant data

  • pint-xarray, for unit-aware computations using pint.

import xarray as xr
import numpy as np

Quick note on accessors#

Before we look at the packages we need to briefly introduce a feature they commonly use: “xarray accessors”.

The accessor-style syntax is used heavily by the other libraries we are about to cover.

For users accessors just allow us to have a method-like syntax on xarray objects, for example da.hvplot(), da.pint.quantify(), or da.cf.describe().

For developers who are interested in defining their own accessors, see the section on accessors at the bottom of this page.

hvplot via accessors#

The HoloViews library makes great use of accessors to allow seamless plotting of xarray data using a completely different plotting backend.

We first need to import the code that registers the hvplot accessor

import hvplot.xarray