You can run this notebook in a live session or view it on Github.
Introduction¶
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:
If you choose to install the tutorial locally, follow these steps:
Clone the repository:
git clone https://github.com/xarray-contrib/xarray-tutorial.git
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.yml conda activate xarray
Start a Jupyter session:
jupyter lab
Useful links¶
References
Ask for help:
Use the python-xarray on StackOverflow
GitHub Issues for bug reports and feature requests
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 before, it’s similar to the Jupyter Notebook. If you haven’t used the Notebook, the quick intro is
There are two modes: command and edit
From command mode, press Enter to edit a cell (like this markdown cell)
From edit mode, press Esc to change to command mode
Press shift+enter to execute a cell and move to the next cell.
The toolbar has commands for executing, converting, and creating cells.
The layout of the tutorial will be as follows:
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!”.
[1]:
# Your code here
In some cases, the next cell will have 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.
[2]:
print("Hello, world!")
Hello, world!
Going Deeper¶
We’ve designed the notebooks above to cover the basics of Xarray from beginning to end. To help you go deeper, we’ve also create a list of notebooks that demonstrate real-world applications of Xarray in a variety of use cases. These need not be explored in any particular sequence, instead they are meant to provide a sampling of what Xarray can be used for.
Xarray and Weather/Climate Model Data¶
Global Mean Surface Temperature from CMIP6: Start with
global_mean_surface_temp.ipynb
then feel free to explore the rest of the notebooks.National Water Model Streamflow Analysis: Start with
02_National_Water_Model.ipynb
then feel free to explore the rest of the notebooks.
Xarray and Satellite Data¶
Xarray and Baysian Statistical Modeling¶
Xarray and PyMC3: Start with
multilevel_modeling.ipynb
then feel free to explore the rest of the notebooks. Also checkout Arviz which uses Xarray as its data model.