Datasets in other fields

Datasets in other fields#

While there are many Xarray examples from geosciences the Xarray data model is not constrained to that field. Our examples so far solve problems that are highly analogous to the problems faced in biology. In this notebook we will load a dataset based on the cells3d dataset from scikit-image.

import xarray as xr

Loading the Dataset#

This dataset follows a classic pattern in microscopy where we have a stack of images, with two fluoresence channels. In addition to that we have a mask (or labels layer) that identifies individual cells

<xarray.Dataset> Size: 16MB
Dimensions:  (c: 2, z: 60, y: 256, x: 256)
Coordinates:
  * c        (c) <U8 64B 'membrane' 'nuclei'
  * z        (z) float64 480B 0.0 0.26 0.52 0.78 ... 14.56 14.82 15.08 15.34
  * y        (y) float64 2kB 0.0 0.26 0.52 0.78 1.04 ... 65.52 65.78 66.04 66.3
  * x        (x) float64 2kB 0.0 0.26 0.52 0.78 1.04 ... 65.52 65.78 66.04 66.3
Data variables:
    images   (z, c, y, x) uint16 16MB 2060 2058 2126 2087 ... 4979 6781 4031
    mask     (y, x) int32 262kB 1 1 1 1 1 0 0 1 1 1 1 ... 0 0 0 0 0 0 0 0 0 0 0
Attributes:
    length:   micron
ds['images'].max('z').sel(c='nuclei').plot()
<matplotlib.collections.QuadMesh at 0x7fd5bb19f0b0>
../_images/1959fab3b002bca4d16066bd9c309f718ee1e872e3cf1a3bd213761be0cfd462.png
ds['images'].sel(z=9, method='nearest').sel(c='membrane').plot()
<matplotlib.collections.QuadMesh at 0x7fd5b9f9d250>
../_images/19f009391d14543e24be1938e994db8a85a96d640925af87593283abec990ca1.png
ds['images'].max('z').sel(c='nuclei').plot()
ds['mask'].plot.contour(cmap='r')
<matplotlib.contour.QuadContourSet at 0x7fd5b9fe1070>
../_images/c2a9f1a7a5fe675cca1384b382f137cdc4391fcabe10df8c777dea21b5b75efd.png
ds['mask'].plot()
<matplotlib.collections.QuadMesh at 0x7fd5b9f57170>
../_images/aba7e6871952a5d6636adcaeac6c51b27d7662022702c12af2d76b3946c0e0d8.png

Allows high level computations.#

We won’t get into here - but this structuring data allows you to leverage Xarray to do powerful operations such as computing per cell properties. See the Computational Patterns Notebook for more.