File: interactive_scripting.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-- 671 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
"""
Interactive scripting
=====================

.. tags:: interactivity
"""

import time

import numpy as np

import napari
from napari.qt import thread_worker

# create the viewer with an image
data = np.random.random((512, 512))
viewer = napari.Viewer()
layer = viewer.add_image(data)

def update_layer(data):
    layer.data = data

@thread_worker(connect={'yielded': update_layer})
def create_data(*, update_period, num_updates):
    # number of times to update
    for _k in range(num_updates):
        yield np.random.random((512, 512))
        time.sleep(update_period)

create_data(update_period=0.05, num_updates=50)

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