Passed
Pull Request — master (#625)
by Fernando
01:52
created

tests.transforms.preprocessing.test_slab_projection   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 16
eloc 54
dl 0
loc 69
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A TestProjection.test_very_large_slab_thickness() 0 5 1
A TestProjection.test_percentile_is_required() 0 3 2
A TestProjection.test_projection_type_invalid_input() 0 3 2
A TestProjection.test_percentile_is_invalid() 0 4 2
A TestProjection.test_full_slabs_only() 0 10 1
A TestProjection.test_mean_intensity_projection() 0 3 1
A TestProjection.test_percentile_intensity_projection() 0 4 1
A TestProjection.test_invalid_axis_name() 0 4 2
A TestProjection.test_maximum_intensity_projection() 0 3 1
A TestProjection.test_default_projection() 0 5 1
A TestProjection.test_minimum_intensity_projection() 0 3 1
A TestProjection.test_median_intensity_projection() 0 3 1
1
import torchio as tio
2
from ...utils import TorchioTestCase
3
4
5
class TestProjection(TorchioTestCase):
6
    """Tests for :class:`tio.SlabProjection` class."""
7
8
    def test_default_projection(self):
9
        transform = tio.SlabProjection('S')
10
        transformed = transform(self.sample_subject)
11
        axis_index = self.sample_subject.t1.axis_name_to_index('S')
12
        self.assertEqual(transformed.t1.shape[axis_index], 1)
13
14
    def test_invalid_axis_name(self):
15
        with self.assertRaises(ValueError):
16
            transform = tio.SlabProjection('123')
17
            transform(self.sample_subject)
18
19
    def test_projection_type_invalid_input(self):
20
        with self.assertRaises(ValueError):
21
            tio.SlabProjection('S', projection_type='bad')
22
23
    def test_percentile_is_required(self):
24
        with self.assertRaises(TypeError):
25
            tio.SlabProjection('S', projection_type='percentile')
26
27
    def test_percentile_is_invalid(self):
28
        with self.assertRaises(ValueError):
29
            tio.SlabProjection(
30
                'S', projection_type='percentile', percentile=-1)
31
32
    def test_full_slabs_only(self):
33
        sub = tio.datasets.Colin27()
34
        transform1 = tio.SlabProjection('S', slab_thickness=100, stride=100)
35
        transform2 = tio.SlabProjection(
36
            'S', slab_thickness=100, stride=100, full_slabs_only=False)
37
        transformed1 = transform1(sub)
38
        transformed2 = transform2(sub)
39
        axis_index = sub.t1.axis_name_to_index('S')
40
        self.assertEqual(transformed1.t1.shape[axis_index], 1)
41
        self.assertEqual(transformed2.t1.shape[axis_index], 2)
42
43
    def test_maximum_intensity_projection(self):
44
        transform = tio.SlabProjection('S', projection_type='max')
45
        transform(self.sample_subject)
46
47
    def test_minimum_intensity_projection(self):
48
        transform = tio.SlabProjection('S', projection_type='min')
49
        transform(self.sample_subject)
50
51
    def test_mean_intensity_projection(self):
52
        transform = tio.SlabProjection('S', projection_type='mean')
53
        transform(self.sample_subject)
54
55
    def test_median_intensity_projection(self):
56
        transform = tio.SlabProjection('S', projection_type='median')
57
        transform(self.sample_subject)
58
59
    def test_percentile_intensity_projection(self):
60
        transform = tio.SlabProjection(
61
            'S', projection_type='percentile', percentile=75)
62
        transform(self.sample_subject)
63
64
    def test_very_large_slab_thickness(self):
65
        transform = tio.SlabProjection('S', slab_thickness=1e6)
66
        transformed = transform(self.sample_subject)
67
        axis_index = self.sample_subject.t1.axis_name_to_index('S')
68
        self.assertEqual(transformed.t1.shape[axis_index], 1)
69