Passed
Push — master ( c291a8...879ee9 )
by Fernando
59s
created

tests.transforms.preprocessing.test_to_canonical   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A TestToCanonical.test_LAS_to_RAS() 0 13 1
A TestToCanonical.test_no_changes() 0 5 1
1
import numpy as np
2
from numpy.testing import assert_array_equal
3
from torchio.transforms import ToCanonical
4
from ...utils import TorchioTestCase
5
6
7
class TestToCanonical(TorchioTestCase):
8
    """Tests for :py:class:`ToCanonical` class."""
9
10
    def test_no_changes(self):
11
        transform = ToCanonical()
12
        transformed = transform(self.sample)
13
        assert_array_equal(transformed.t1.data, self.sample.t1.data)
14
        assert_array_equal(transformed.t1.affine, self.sample.t1.affine)
15
16
    def test_LAS_to_RAS(self):
17
        self.sample.t1.affine[0, 0] = -1    # Change orientation to 'LAS'
18
        transform = ToCanonical()
19
        transformed = transform(self.sample)
20
        self.assertEqual(transformed.t1.orientation, ('R', 'A', 'S'))
21
        assert_array_equal(
22
            transformed.t1.data,
23
            self.sample.t1.data.numpy()[:, ::-1, :, :]
24
        )
25
26
        fixture = np.eye(4)
27
        fixture[0, -1] = -self.sample.t1.spatial_shape[0] + 1
28
        assert_array_equal(transformed.t1.affine, fixture)
29