File: linked_layers.py

package info (click to toggle)
napari 0.6.6-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,036 kB
  • sloc: python: 112,264; xml: 72; makefile: 44; sh: 5
file content (33 lines) | stat: -rw-r--r-- 930 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
33
"""
Linked layers
=============

Demonstrates the `link_layers` function.

This function takes a list of layers and an optional list of attributes, and
links them such that when one of the linked attributes changes on any of the
linked layers, all of the other layers follow.

.. tags:: experimental
"""
import numpy as np

import napari
from napari.experimental import link_layers

viewer = napari.Viewer()
layer = viewer.add_image(np.random.rand(3, 64, 64), channel_axis=0)

# link contrast_limits and gamma between all layers in viewer
# NOTE: you may also omit the second argument to link ALL valid, common
# attributes for the set of layers provided
link_layers(viewer.layers, ('contrast_limits', 'gamma'))

# unlinking may be done with napari.experimental.unlink_layers

# this may also be done in a context manager:
# with napari.experimental.layers_linked([layers]):
#     ...

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