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

torchio.datasets.slicer   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A Slicer.__init__() 0 12 1
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