File: test_imageview.py

package info (click to toggle)
python-pyqtgraph 0.13.7-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,072 kB
  • sloc: python: 54,043; makefile: 127; ansic: 40; sh: 2
file content (47 lines) | stat: -rw-r--r-- 1,206 bytes parent folder | download | duplicates (2)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np

import pyqtgraph as pg

app = pg.mkQApp()


def test_nan_image():
    img = np.ones((10,10))
    img[0,0] = np.nan
    iv = pg.ImageView()
    iv.setImage(img)
    iv.show()
    iv.getImageItem().getHistogram()
    app.processEvents()
    iv.window().close()


def test_timeslide_snap():
    count = 31
    frames = np.ones((count, 10, 10))
    iv = pg.ImageView(discreteTimeLine=True)
    assert iv.nframes() == 0
    iv.setImage(frames, xvals=(np.linspace(0., 1., count)))
    iv.show()
    assert iv.nframes() == count
    speed = count / 2
    iv.play(speed)
    assert iv.playRate == speed
    iv.timeLine.setPos(0.51)  # side effect: also pauses playback
    assert iv.playRate == 0
    ind, val = iv.timeIndex(iv.timeLine)
    assert ind == count // 2
    assert val == 0.5
    iv.togglePause()  # restarts playback
    assert iv.playRate == speed
    iv.togglePause()  # pauses playback
    assert iv.playRate == 0
    iv.play()
    assert iv.playRate == speed


def test_init_with_mode_and_imageitem():
    data = np.random.randint(256, size=(256, 256, 3))
    imgitem = pg.ImageItem(data)
    pg.ImageView(imageItem=imgitem, levelMode="rgba")
    assert(pg.image is not None)