You can run this notebook in a live session Binder or view it on Github.



Welcome to the Xarray Tutorial.

Xarray is an open source project and Python package that makes working with labelled multi-dimensional arrays simple, efficient, and fun!

Xarray introduces labels in the form of dimensions, coordinates and attributes on top of raw NumPy-like arrays, which allows for a more intuitive, more concise, and less error-prone developer experience. The package includes a large and growing library of domain-agnostic functions for advanced analytics and visualization with these data structures.

Xarray is inspired by and borrows heavily from pandas, the popular data analysis package focused on labelled tabular data. It is particularly tailored to working with netCDF files, which were the source of xarray’s data model, and integrates tightly with Dask for parallel computing.

Tutorial Setup

This tutorial is designed to run on Binder. This will allow you to run the turoial in the cloud without any additional setup. To get started, simply click here: Binder

If you choose to install the tutorial locally, follow these steps:

  1. Clone the repository:

    git clone
  2. Install the environment. The repository includes an environment.yaml in the .binder subdirectory that contains a list of all the packages needed to run this tutorial. To install them using conda run:

    conda env create -f .binder/environment.yaml
    conda activate xarray-tutorial
  3. Start a Jupyter session:

    jupyter lab

Tutorial Structure

This tutorial is made up of multiple Jupyter Notebooks. These notebooks mix code, text, visualization, and exercises.

If you haven’t used Jupyterlab, it’s similar to the Jupyter Notebook. If you haven’t used the Notebook, the quick intro is

  1. There are two modes: command and edit

  2. From command mode, press Enter to edit a cell (like this markdown cell)

  3. From edit mode, press Esc to change to command mode

  4. Press shift+enter to execute a cell and move to the next cell.

  5. The toolbar has commands for executing, converting, and creating cells.

The layout of the tutorial will be as follows:

  1. Introduction + Data structures for multi-dimensional data

  2. Working with labeled data

  3. Computation with Xarray

  4. Plotting and Visualization

  5. Introduction to Dask

  6. Dask and Xarray

  7. `Self-guided exercises <>`__

Exercise: Print Hello, world!

Each notebook will have exercises for you to solve. You’ll be given a blank or partially completed cell, followed by a hidden cell with a solution. For example.

Print the text “Hello, world!”.

# Your code here

The next cell has the solution. Click the ellipses to expand the solution, and always make sure to run the solution cell, in case later sections of the notebook depend on the output from the solution.

print("Hello, world!")
Hello, world!