Skip to content

Commit 33acd41

Browse files
committed
updated mrconvert fileformats converter registration
1 parent c1bab09 commit 33acd41

File tree

1 file changed

+27
-57
lines changed

1 file changed

+27
-57
lines changed
Lines changed: 27 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,47 @@
1-
from fileformats.core import converter
1+
import typing as ty
2+
from fileformats.core import converter, FileSet
23
from fileformats.medimage.base import MedicalImage
3-
44
from fileformats.medimage_mrtrix3 import (
55
ImageFormat as MrtrixImage,
66
ImageHeader as MrtrixImageHeader,
77
ImageFormatGz as MrtrixImageGz,
88
)
99

10-
try:
11-
from pydra.tasks.mrtrix3.v3_0 import MrConvert
12-
except ImportError:
13-
from pydra.tasks.mrtrix3.latest import mrconvert as MrConvert
14-
15-
in_out_file_kwargs = {"in_file": "input", "out_file": "output"}
16-
else:
17-
in_out_file_kwargs = {}
10+
from pydra.tasks.mrtrix3.v3_0 import MrConvert
1811

1912

20-
@converter(
21-
source_format=MedicalImage,
22-
target_format=MrtrixImageGz,
23-
out_ext=MrtrixImageGz.ext,
24-
**in_out_file_kwargs,
25-
)
26-
@converter(
27-
source_format=MedicalImage,
28-
target_format=MrtrixImageHeader,
29-
out_ext=MrtrixImageHeader.ext,
30-
**in_out_file_kwargs,
31-
)
32-
@converter(
33-
source_format=MedicalImage,
34-
target_format=MrtrixImage,
35-
out_ext=MrtrixImage.ext,
36-
**in_out_file_kwargs,
37-
)
38-
def mrconvert(name, out_ext: str, **kwargs):
39-
"""Initiate an MRConvert task with the output file extension set
13+
def out_file_template(fileformat: ty.Type[FileSet]) -> str:
14+
"""Return the output file name for a given file format
4015
4116
Parameters
4217
----------
43-
name : str
44-
name of the converter task
45-
out_ext : str
46-
extension of the output file, used by MRConvert to determine the desired format
18+
fileformat : type
19+
the file format class
4720
4821
Returns
4922
-------
50-
pydra.ShellCommandTask
51-
the converter task
23+
str
24+
the output file name
5225
"""
53-
return MrConvert(name=name, out_file="out" + out_ext, **kwargs)
26+
return "out" + fileformat.ext
5427

5528

56-
# @converter(
57-
# source_format=MedicalImage,
58-
# target_format=MrtrixImageHeader,
59-
# out_ext=MrtrixImageHeader.ext,
60-
# **in_out_file_kwargs,
61-
# )
62-
# def mrconvert2(name, out_ext: str, **kwargs):
63-
# """Initiate an MRConvert task with the output file extension set
29+
# Register MrConvert as a converter for MrTrix formats
6430

65-
# Parameters
66-
# ----------
67-
# name : str
68-
# name of the converter task
69-
# out_ext : str
70-
# extension of the output file, used by MRConvert to determine the desired format
31+
converter(
32+
source_format=MedicalImage,
33+
target_format=MrtrixImageGz,
34+
out_file=out_file_template(MrtrixImageGz),
35+
)(MrConvert)
7136

72-
# Returns
73-
# -------
74-
# pydra.ShellCommandTask
75-
# the converter task
76-
# """
77-
# return MrConvert(name=name, out_file="out" + out_ext, **kwargs)
37+
converter(
38+
source_format=MedicalImage,
39+
target_format=MrtrixImageHeader,
40+
out_file=out_file_template(MrtrixImageHeader),
41+
)(MrConvert)
42+
43+
converter(
44+
source_format=MedicalImage,
45+
target_format=MrtrixImage,
46+
out_file=out_file_template(MrtrixImage),
47+
)(MrConvert)

0 commit comments

Comments
 (0)