File: test_streamlines_ops.py

package info (click to toggle)
python-trx-python 0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 408 kB
  • sloc: python: 3,394; makefile: 66
file content (101 lines) | stat: -rw-r--r-- 3,283 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- coding: utf-8 -*-

import numpy as np
import pytest

from trx.streamlines_ops import (perform_streamlines_operation,
                                 intersection, union, difference)

streamlines_ori = [np.ones(90).reshape((30, 3)),
                   np.arange(90).reshape((30, 3)) + 0.3333]


@pytest.mark.parametrize(
    "precision, noise, expected",
    [
        (0, 0.0001, [4]),
        (1, 0.0001, [4]),
        (2, 0.0001, [4]),
        (4, 0.0001, []),
        (0, 0.01, [4]),
        (1, 0.01, [4]),
        (2, 0.01, []),
        (0, 1, []),
    ],
)
def test_intersection(precision, noise, expected):
    streamlines_new = []
    for i in range(5):
        if i < 4:
            streamlines_new.append(streamlines_ori[1] +
                                   np.random.random((30, 3)))
        else:
            streamlines_new.append(streamlines_ori[1] +
                                   noise * np.random.random((30, 3)))
    # print(streamlines_new)
    _, indices_uniq = perform_streamlines_operation(intersection,
                                                    [streamlines_new,
                                                     streamlines_ori],
                                                    precision=precision)
    indices_uniq = indices_uniq.tolist()
    assert indices_uniq == expected


@pytest.mark.parametrize(
    "precision, noise, expected",
    [
        (0, 0.0001, 6),
        (1, 0.0001, 6),
        (2, 0.0001, 6),
        (4, 0.0001, 7),
        (0, 0.01, 6),
        (1, 0.01, 6),
        (2, 0.01, 7),
        (0, 1, 7),
    ],
)
def test_union(precision, noise, expected):
    streamlines_new = []
    for i in range(5):
        if i < 4:
            streamlines_new.append(streamlines_ori[1] +
                                   np.random.random((30, 3)))
        else:
            streamlines_new.append(streamlines_ori[1] +
                                   noise * np.random.random((30, 3)))

    unique_streamlines, _ = perform_streamlines_operation(union,
                                                          [streamlines_new,
                                                           streamlines_ori],
                                                          precision=precision)
    assert len(unique_streamlines) == expected


@pytest.mark.parametrize(
    "precision, noise, expected",
    [
        (0, 0.0001, 4),
        (1, 0.0001, 4),
        (2, 0.0001, 4),
        (4, 0.0001, 5),
        (0, 0.01, 4),
        (1, 0.01, 4),
        (2, 0.01, 5),
        (0, 1, 5),
    ],
)
def test_difference(precision, noise, expected):
    streamlines_new = []
    for i in range(5):
        if i < 4:
            streamlines_new.append(streamlines_ori[1] +
                                   np.random.random((30, 3)))
        else:
            streamlines_new.append(streamlines_ori[1] +
                                   noise * np.random.random((30, 3)))

    unique_streamlines, _ = perform_streamlines_operation(difference,
                                                          [streamlines_new,
                                                           streamlines_ori],
                                                          precision=precision)
    assert len(unique_streamlines) == expected