Passed
Push — master ( 0b0a34...8a30f9 )
by Fernando
01:06
created

torchio.datasets.mni.colin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B Colin27.__init__() 0 37 5
1
import urllib.parse
2
from torchvision.datasets.utils import download_and_extract_archive
3
from ...utils import get_torchio_cache_dir
4
from ... import Image, LABEL
5
from .mni import SubjectMNI
6
7
8
class Colin27(SubjectMNI):
9
    """Colin27 MNI template.
10
11
    Arguments:
12
        version: Template year. It can ``1998`` or ``2008``.
13
    """
14
    def __init__(self, version=1998):
15
        if version not in (1998, 2008):
16
            raise ValueError(f'Version must be 1998 or 2008, not "{version}"')
17
        self.name = f'mni_colin27_{version}_nifti'
18
        self.url_dir = urllib.parse.urljoin(self.url_base, 'colin27/')
19
        self.filename = f'{self.name}.zip'
20
        self.url = urllib.parse.urljoin(self.url_dir, self.filename)
21
        download_root = get_torchio_cache_dir() / self.name
22
        if download_root.is_dir():
23
            print(f'Using cache found in {download_root}')
24
        else:
25
            download_and_extract_archive(
26
                self.url,
27
                download_root=download_root,
28
                filename=self.filename,
29
            )
30
31
        if version == 1998:
32
            t1, head, mask = [
33
                download_root / f'colin27_t1_tal_lin{suffix}.nii'
34
                for suffix in ('', '_headmask', '_mask')
35
            ]
36
            super().__init__(
37
                t1=Image(t1),
38
                head=Image(head, type=LABEL),
39
                brain=Image(mask, type=LABEL),
40
            )
41
        elif version == 2008:
42
            t1, t2, pd, label = [
43
                download_root / f'colin27_{name}_tal_hires.nii'
44
                for name in ('t1', 't2', 'pd', 'cls')
45
            ]
46
            super().__init__(
47
                t1=Image(t1),
48
                t2=Image(t2),
49
                pd=Image(pd),
50
                cls=Image(label, type=LABEL),
51
            )
52