[637b40]: / adpkd_segmentation / data / link_data.py

Download this file

51 lines (36 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# %%
import os
import shutil
from adpkd_segmentation.data.data_utils import get_dcms_paths, get_y_Path
# define data sources in data_config.py
from adpkd_segmentation.data.data_config import (
labeled_dirs,
unlabeled_dirs,
LABELED,
UNLABELED,
)
# %%
def symlink_force(target, link_name):
try:
os.symlink(target, link_name)
except Exception as e:
print(e)
def mkdir_force(dir):
if os.path.exists(dir):
shutil.rmtree(dir)
os.makedirs(dir)
# %%
def makelinks():
mkdir_force(LABELED)
mkdir_force(UNLABELED)
for dcm in get_dcms_paths(labeled_dirs):
mask = get_y_Path(dcm)
if not mask.exists():
raise Exception("Labeled dcm [{}] does not have mask.".format(dcm))
symlink_force(dcm, os.path.join(LABELED, os.path.basename(dcm)))
symlink_force(mask, os.path.join(LABELED, os.path.basename(mask)))
for dcm in get_dcms_paths(unlabeled_dirs):
mask = get_y_Path(dcm)
if mask.exists():
raise Exception("Unlabeled dcm [{}] contains a mask.".format(dcm))
symlink_force(dcm, os.path.join(UNLABELED, os.path.basename(dcm)))