Passed
Push — master ( 90dc5e...949e25 )
by Fernando
01:15
created

torchio.datasets.slicer.Slicer.__init__()   A

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nop 2
dl 0
loc 12
rs 9.85
c 0
b 0
f 0
1
import urllib.parse
2
from torchvision.datasets.utils import download_url
3
from .. import Subject, Image
4
from ..utils import get_torchio_cache_dir
5
6
7
SLICER_URL = 'https://github.com/Slicer/SlicerTestingData/releases/download/'
8
URLS_DICT = {
9
    'MRHead': ('MRHead.nrrd', 'SHA256/cc211f0dfd9a05ca3841ce1141b292898b2dd2d3f08286affadf823a7e58df93'),
10
}
11
12
13
class Slicer(Subject):
14
    """Sample data provided by 3D Slicer.
15
16
    See `the website <https://www.slicer.org/wiki/SampleData>`_
17
    for more information.
18
    """
19
    def __init__(self, name='MRHead'):
20
        filename, url_file = URLS_DICT[name]
21
        url = urllib.parse.urljoin(SLICER_URL, url_file)
22
        download_root = get_torchio_cache_dir() / 'slicer'
23
        stem = filename.split('.')[0]
24
        download_url(
25
            url,
26
            download_root,
27
            filename=filename,
28
        )
29
        super().__init__({
30
            stem: Image(download_root / filename),
31
        })
32