1 of 6

XArray Basics

Ujaval Gandhi

ujaval@spatialthoughts.com

Mapping and Data Visualization with Python

2 of 6

XArray

  • Xarray is an evolution of rasterio and is inspired by libraries like pandas to work with raster datasets.
  • Supports vectorized operations on arrays resulting in magnitudes of faster processing over other Python/R packages. [benchmark]
  • Particularly suited for working with multi-dimensional time-series raster datasets.
  • Integrates tightly with dask that allows one to scale raster data processing using parallel computing.
  • Fast evolving ecosystem around spatial extensions (rioxarray, xarray-spatial, xy-scipy etc.)

3 of 6

Basic Terminology

  • Variables: This is similar to a band in a raster dataset. Each variable contains an array of values.
  • Dimensions: This is similar to number of array axes. A grid of pixels (lat and lon) at multiple time intervals time with multiple variables is a 4D dataset.
  • Coordinates: These are the labels for values in each dimension. We have labels for lat, lon and time.
  • Attributes: This is the metadata associated with the dataset.

4 of 6

Bands

Red

Blue

Green

NIR

X Coordinates

Y Coordinates

Variable

Coordinate

Coordinate

5 of 6

Red

Blue

Green

NIR

Red

Blue

Green

NIR

Red

Blue

Green

NIR

Image 1

Image 2

Image 3

Time 1

Time 2

Time 3

Time Coordinates

6 of 6

Red

Blue

Green

NIR

Red

Blue

Green

NIR

Red

Blue

Green

NIR

Image 1

Image 2

Image 3

Time Coordinates (time)

Y Coordinates (lat)

X Coordinates (lon)

Coordinates

Variables

Red

Green

Blue

NIR

Dimensions

lon

lat

time

variables