Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/guides/units.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ Pint also has logic to disambiguate unit names, for example,
If you do not set units, napari assumes pixels.
To set *no* units, use `layer.units = ('dimensionless',...)`.

## Inheriting scale and units from xarray

If you pass an [Xarray](https://docs.xarray.dev/en/stable/generated/xarray.DataArray.html)
`DataArray` to napari, it automatically inherits metadata from it: dimension
names become the layer's axis labels, coordinate values are used for `scale`
and `translate`, and CF-convention `units` attributes on coordinates (validated
with [pint](https://pint.readthedocs.io/)) become the layer units. Even
`datetime64` coordinates are converted to a sensible time unit. See the
[xarray example](sphx_glr_gallery_xarray-latlon-timeseries.py) for a
full demonstration.

## When units are consistent across layers

napari can use units to render layers in the same physical space even when the
Expand Down
7 changes: 7 additions & 0 deletions docs/howtos/layers/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ The great thing about napari support of array-like objects is that you get to
keep on using your favorite array libraries without worrying about any
conversions. napari handles all of that for you.

```{note}
If you pass an [Xarray](https://docs.xarray.dev/en/stable/generated/xarray.DataArray.html)
`DataArray` to napari, it automatically inherits metadata from it, such as axis
labels, `scale`, `translate`, and units. For details on how this metadata is
used for rendering, see the [units guide](units-guide).
```

napari will also wait until just before it displays data onto the screen to
actually generate a NumPy array from your data, and so if you're using a library
like `dask` or `zarr` that supports lazy loading and lazy evaluation, we won't
Expand Down
Loading