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
ds = xr.tutorial.load_dataset("cells3d")
ds
<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 0x7f2748bfb320>

ds['images'].sel(z=9, method='nearest').sel(c='membrane').plot()
<matplotlib.collections.QuadMesh at 0x7f2747b5d5b0>

ds['images'].max('z').sel(c='nuclei').plot()
ds['mask'].plot.contour(cmap='r')
<matplotlib.contour.QuadContourSet at 0x7f2748be38c0>

ds['mask'].plot()
<matplotlib.collections.QuadMesh at 0x7f273f9c7380>

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.