1
|
|
|
import abc |
2
|
|
|
import tempfile |
3
|
|
|
|
4
|
|
|
from .. import Subject, ScalarImage |
5
|
|
|
from ..utils import get_torchio_cache_dir |
6
|
|
|
from ..download import download_and_extract_archive |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class VisibleHuman(abc.ABC, Subject): |
10
|
|
|
|
11
|
|
|
URL = 'https://mri.radiology.uiowa.edu/website_documents/visible_human_tar_files/{}{}.tar.gz' # noqa: E501, FS003 |
12
|
|
|
|
13
|
|
|
def __init__(self, part: str): |
14
|
|
|
self.part = self._parse_part(part) |
15
|
|
|
if not self.cache_part_dir.is_dir(): |
16
|
|
|
tempdir = tempfile.gettempdir() |
17
|
|
|
filename = f'{self.__class__.__name__}-{self.part}.tar.gz' |
18
|
|
|
download_and_extract_archive( |
19
|
|
|
self.url, |
20
|
|
|
tempdir, |
21
|
|
|
filename=filename, |
22
|
|
|
extract_root=self.cache_class_dir, |
23
|
|
|
remove_finished=True, |
24
|
|
|
) |
25
|
|
|
super().__init__({self.part.lower(): ScalarImage(self.cache_part_dir)}) |
26
|
|
|
|
27
|
|
|
@property |
28
|
|
|
def cache_class_dir(self): |
29
|
|
|
return get_torchio_cache_dir() / self.__class__.__name__ |
30
|
|
|
|
31
|
|
|
@property |
32
|
|
|
def cache_part_dir(self): |
33
|
|
|
return self.cache_class_dir / self.part |
34
|
|
|
|
35
|
|
|
@property |
36
|
|
|
def url(self): |
37
|
|
|
return self.URL.format(self.PREFIX, self.part) |
38
|
|
|
|
39
|
|
|
def _parse_part(self, part: str) -> None: |
40
|
|
|
part_capital = part.capitalize() |
41
|
|
|
if part_capital not in self.PARTS: |
42
|
|
|
message = f'Part "{part}" not in available parts: {self.PARTS}' |
43
|
|
|
raise ValueError(message) |
44
|
|
|
return part_capital |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
class VisibleMale(VisibleHuman): |
48
|
|
|
"""Visible Male CT Datasets. |
49
|
|
|
|
50
|
|
|
Args: |
51
|
|
|
part: Can be ``'Head'``, ``'Hip'``, ``'Pelvis'`` or ``'Shoulder'``. |
52
|
|
|
""" |
53
|
|
|
|
54
|
|
|
PREFIX = 'VHMCT1mm_' |
55
|
|
|
PARTS = ( |
56
|
|
|
'Head', |
57
|
|
|
'Hip', |
58
|
|
|
'Pelvis', |
59
|
|
|
'Shoulder', |
60
|
|
|
) |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
class VisibleFemale(VisibleHuman): |
64
|
|
|
"""Visible Female CT Datasets. |
65
|
|
|
|
66
|
|
|
Args: |
67
|
|
|
part: Can be ``'Ankle'``, ``'Head'``, ``'Hip'``, ``'Knee'``, |
68
|
|
|
``'Pelvis'`` or ``'Shoulder'``. |
69
|
|
|
""" |
70
|
|
|
|
71
|
|
|
PREFIX = 'VHF-' |
72
|
|
|
PARTS = VisibleMale.PARTS + ( |
73
|
|
|
'Ankle', |
74
|
|
|
'Knee', |
75
|
|
|
) |
76
|
|
|
|