Skip to content

Commit 64a686d

Browse files
committed
added out_file as Path not str and check for echos
1 parent dcab68b commit 64a686d

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

pydra/tasks/dcm2niix/utils.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os.path
1+
from pathlib import Path
22
from pydra import ShellCommandTask
33
from pydra.engine.specs import ShellSpec, ShellOutSpec, File, Directory, SpecInfo
44

@@ -16,7 +16,21 @@ def dcm2niix_out_file(out_dir, filename, echo, compress):
1616
if compress in ("y", "o", "i"):
1717
out_file += ".gz"
1818

19-
return os.path.abspath(out_file)
19+
out_file = Path(out_file).absolute()
20+
21+
# Check to see if multiple echos exist in the DICOM dataset
22+
if not out_file.exists():
23+
if echos := [
24+
str(p)
25+
for p in out_file.parent.iterdir()
26+
if p.stem.startswith(out_file.stem + "_e")
27+
]:
28+
raise ValueError(
29+
"DICOM dataset contains multiple echos, please specify which "
30+
"echo you want via the 'echo' input:\n"
31+
"\n".join(echos)
32+
)
33+
return out_file
2034

2135

2236
def dcm2niix_out_json(out_dir, filename, echo):
@@ -26,7 +40,7 @@ def dcm2niix_out_json(out_dir, filename, echo):
2640
else:
2741
echo_suffix = ""
2842

29-
return os.path.abspath(f"{out_dir}/{filename}{echo_suffix}.json")
43+
return Path(f"{out_dir}/{filename}{echo_suffix}.json").absolute()
3044

3145

3246
input_fields = [

0 commit comments

Comments
 (0)