File: xarray_nD_image_.py

package info (click to toggle)
napari 0.7.0~a3-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 16,320 kB
  • sloc: python: 113,797; xml: 72; sh: 47; makefile: 43
file content (32 lines) | stat: -rw-r--r-- 594 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Xarray example
==============

Displays an xarray

.. tags:: visualization-nD, xarray
"""

try:
    import xarray as xr
except ModuleNotFoundError:
    raise ModuleNotFoundError(
        """This example uses a xarray but xarray is not
    installed. To install try 'pip install xarray'."""
    ) from None

import numpy as np

import napari

data = np.random.random((20, 40, 50))
xdata = xr.DataArray(data, dims=['z', 'y', 'x'])

# create an empty viewer
viewer = napari.Viewer()

# add the xarray
layer = viewer.add_image(xdata, name='xarray')

if __name__ == '__main__':
    napari.run()