Passed
Push — master ( b80c39...c15875 )
by Fernando
01:37
created

torchio.datasets.fpg.FPG.__init__()   A

Complexity

Conditions 2

Size

Total Lines 36
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 28
nop 1
dl 0
loc 36
rs 9.208
c 0
b 0
f 0
1
import urllib.parse
2
from torchvision.datasets.utils import download_url
3
from .. import Subject, Image, DATA_REPO, INTENSITY, LABEL
4
from ..utils import get_torchio_cache_dir
5
from ..data.io import read_matrix
6
7
8
class FPG(Subject):
9
    """Some images of myself for testing."""
10
    def __init__(self):
11
        repo_dir = urllib.parse.urljoin(DATA_REPO, 'fernando/')
12
13
        self.filenames = {
14
            't1': 't1.nii.gz',
15
            'seg': 't1_seg_gif.nii.gz',
16
            'rigid': 't1_to_mni.tfm',
17
            'affine': 't1_to_mni_affine.h5',
18
        }
19
20
        download_root = get_torchio_cache_dir() / 'fpg'
21
        for filename in self.filenames.values():
22
            stem = filename.split('.')[0]
23
            download_url(
24
                urllib.parse.urljoin(repo_dir, filename),
25
                download_root,
26
                filename=filename,
27
            )
28
29
        rigid = read_matrix(download_root / self.filenames['rigid'])
30
        affine = read_matrix(download_root / self.filenames['affine'])
31
        subject_dict = {
32
            't1': Image(
33
                download_root / self.filenames['t1'],
34
                type=INTENSITY,
35
                rigid_matrix=rigid,
36
                affine_matrix=affine,
37
            ),
38
            'seg': Image(
39
                download_root / self.filenames['seg'],
40
                type=LABEL,
41
                rigid_matrix=rigid,
42
                affine_matrix=affine,
43
            ),
44
        }
45
        super().__init__(subject_dict)
46