Skip to content

Commit c346916

Browse files
ghisvailtclose
authored andcommitted
ENH: Drop FSL prefix from utils (#58)
* WIP: Drop FSL prefix from utils Improves consistency with Nipype. Compatibility aliases will be maintained in 0.0.x. * WIP: selectvols and roi * WIP: orient and reorient2std * WIP: merge + fixes * WIP: info and interleave * WIP: chfiletype and fft
1 parent b567f15 commit c346916

23 files changed

+682
-786
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ for FMRI, MRI and DTI brain imaging data.
2626

2727
## Available tasks
2828

29-
| Module | Tasks |
30-
|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
31-
| bet | BET, RobustFOV |
32-
| eddy | Eddy, ApplyTopup, Topup |
33-
| fast | FAST |
34-
| flirt | FLIRT, ApplyXFM, ConcatXFM, ConvertXFM, InvertXFM, FixScaleSkew, Img2ImgCoord, Img2StdCoord, Std2ImgCoord |
35-
| fnirt | FNIRT, FNIRTFileUtils, ApplyWarp, ConvertWarp, InvWarp |
36-
| fugue | FUGUE, FSLPrepareFieldmap, Prelude, SigLoss |
37-
| fslmaths | (**experimental**) FSLMaths, Mul |
38-
| susan | SUSAN |
39-
| utils | FSLFFT, FSLROI, FSLChFileType, FSLInfo, FSLInterleave, FSLMerge, FSLOrient, FSLReorient2Std, FSLSelectVols, FSLSlice, FSLSmoothFill, FSLSplit, FSLSwapDim |
29+
| Module | Tasks |
30+
|----------|--------------------------------------------------------------------------------------------------------------------|
31+
| bet | BET, RobustFOV |
32+
| eddy | Eddy, ApplyTopup, Topup |
33+
| fast | FAST |
34+
| flirt | FLIRT, ApplyXFM, ConcatXFM, ConvertXFM, InvertXFM, FixScaleSkew, Img2ImgCoord, Img2StdCoord, Std2ImgCoord |
35+
| fnirt | FNIRT, FNIRTFileUtils, ApplyWarp, ConvertWarp, InvWarp |
36+
| fugue | FUGUE, FSLPrepareFieldmap, Prelude, SigLoss |
37+
| fslmaths | (**experimental**) FSLMaths, Mul |
38+
| susan | SUSAN |
39+
| utils | ChFileType, FFT, Info, Interleave, Merge, Orient, Reorient2Std, ROI, SelectVols, Slice, SmoothFill, Split, SwapDim |
4040

4141
## Installation
4242

src/pydra/tasks/fsl/__init__.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,32 @@
3636
from .fugue import FUGUE, FSLPrepareFieldmap, Prelude, SigLoss
3737
from .susan import SUSAN
3838
from .utils import (
39-
FSLFFT,
40-
FSLROI,
41-
FSLChFileType,
42-
FSLInfo,
43-
FSLInterleave,
44-
FSLMerge,
45-
FSLOrient,
46-
FSLReorient2Std,
47-
FSLSelectVols,
48-
FSLSlice,
49-
FSLSmoothFill,
50-
FSLSplit,
51-
FSLSwapDim,
39+
FFT,
40+
ROI,
41+
ChFileType,
42+
Info,
43+
Interleave,
44+
Merge,
45+
Orient,
46+
Reorient2Std,
47+
SelectVols,
48+
Slice,
49+
SmoothFill,
50+
Split,
51+
SwapDim,
5252
)
53+
54+
# TODO: Drop compatibility aliases when 0.x is released.
55+
FSLFFT = FFT
56+
FSLROI = ROI
57+
FSLChFileType = ChFileType
58+
FSLInfo = Info
59+
FSLInterleave = Interleave
60+
FSLMerge = Merge
61+
FSLOrient = Orient
62+
FSLReorient2Std = Reorient2Std
63+
FSLSelectVols = SelectVols
64+
FSLSlice = Slice
65+
FSLSmoothFill = SmoothFill
66+
FSLSplit = Split
67+
FSLSwapDim = SwapDim

src/pydra/tasks/fsl/utils/__init__.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22
Utils
33
=====
44
5-
.. automodule:: pydra.tasks.fsl.utils.fslchfiletype
6-
.. automodule:: pydra.tasks.fsl.utils.fslfft
7-
.. automodule:: pydra.tasks.fsl.utils.fslinfo
8-
.. automodule:: pydra.tasks.fsl.utils.fslinterleave
9-
.. automodule:: pydra.tasks.fsl.utils.fslmerge
10-
.. automodule:: pydra.tasks.fsl.utils.fslorient
11-
.. automodule:: pydra.tasks.fsl.utils.fslreorient2std
12-
.. automodule:: pydra.tasks.fsl.utils.fslroi
13-
.. automodule:: pydra.tasks.fsl.utils.fslselectvols
14-
.. automodule:: pydra.tasks.fsl.utils.fslsmoothfill
15-
.. automodule:: pydra.tasks.fsl.utils.fslsplit
16-
.. automodule:: pydra.tasks.fsl.utils.fslswapdim
5+
.. automodule:: pydra.tasks.fsl.utils.chfiletype
6+
.. automodule:: pydra.tasks.fsl.utils.fft
7+
.. automodule:: pydra.tasks.fsl.utils.info
8+
.. automodule:: pydra.tasks.fsl.utils.interleave
9+
.. automodule:: pydra.tasks.fsl.utils.merge
10+
.. automodule:: pydra.tasks.fsl.utils.orient
11+
.. automodule:: pydra.tasks.fsl.utils.reorient2std
12+
.. automodule:: pydra.tasks.fsl.utils.roi
13+
.. automodule:: pydra.tasks.fsl.utils.selectvols
14+
.. automodule:: pydra.tasks.fsl.utils.smoothfill
15+
.. automodule:: pydra.tasks.fsl.utils.split
16+
.. automodule:: pydra.tasks.fsl.utils.swapdim
1717
"""
1818

19-
from .fslchfiletype import FSLChFileType
20-
from .fslfft import FSLFFT
21-
from .fslinfo import FSLInfo
22-
from .fslinterleave import FSLInterleave
23-
from .fslmerge import FSLMerge
24-
from .fslorient import FSLOrient
25-
from .fslreorient2std import FSLReorient2Std
26-
from .fslroi import FSLROI
27-
from .fslselectvols import FSLSelectVols
28-
from .fslsmoothfill import FSLSmoothFill
29-
from .fslsplit import FSLSlice, FSLSplit
30-
from .fslswapdim import FSLSwapDim
19+
from .chfiletype import ChFileType
20+
from .fft import FFT
21+
from .info import Info
22+
from .interleave import Interleave
23+
from .merge import Merge
24+
from .orient import Orient
25+
from .reorient2std import Reorient2Std
26+
from .roi import ROI
27+
from .selectvols import SelectVols
28+
from .smoothfill import SmoothFill
29+
from .split import Slice, Split
30+
from .swapdim import SwapDim
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
"""
2+
ChFileType
3+
==========
4+
5+
Convert image to a different NIfTI file format.
6+
7+
Examples
8+
--------
9+
10+
>>> task = ChFileType(filetype="NIFTI2_GZ", input_image="input.nii", output_basename="output")
11+
>>> task.cmdline
12+
'fslchfiletype NIFTI2_GZ input.nii output'
13+
"""
14+
15+
__all__ = ["ChFileType"]
16+
17+
from os import PathLike
18+
from pathlib import Path
19+
20+
from attrs import define, field
21+
from pydra.engine.specs import File, ShellOutSpec, ShellSpec, SpecInfo
22+
from pydra.engine.task import ShellCommandTask
23+
24+
ALLOWED_FILETYPES = {
25+
"ANALYZE",
26+
"ANALYZE_GZ",
27+
"NIFTI",
28+
"NIFTI_GZ",
29+
"NIFTI_STD::PAIR",
30+
"NIFTI_STD::PAIR_GZ",
31+
"NIFTI2",
32+
"NIFTI2_GZ",
33+
"NIFTI2_STD::PAIR",
34+
"NIFTI2_STD::PAIR_GZ",
35+
}
36+
37+
38+
def _get_output_basename(output_basename, input_image):
39+
return output_basename or Path(input_image).name.split(".", 1)[0]
40+
41+
42+
def _get_output_image(output_basename, input_image, filetype):
43+
output_basename = _get_output_basename(output_basename, input_image)
44+
45+
extension = "img" if any(pat in filetype for pat in ["ANALYZE", "PAIR"]) else "nii"
46+
if "GZ" in filetype:
47+
extension += ".gz"
48+
49+
return Path.cwd() / f"{output_basename}.{extension}"
50+
51+
52+
def _get_output_header(output_basename, input_image, filetype):
53+
output_basename = _get_output_basename(output_basename, input_image)
54+
55+
if any(pat in filetype for pat in ["ANALYZE", "PAIR"]):
56+
extension = "hdr.gz" if "GZ" in filetype else "hdr"
57+
return Path.cwd() / f"{output_basename}.{extension}"
58+
else:
59+
return None
60+
61+
62+
@define(kw_only=True)
63+
class ChFileTypeSpec(ShellSpec):
64+
"""Specifications for fslchfiletype."""
65+
66+
filetype: str = field(
67+
metadata={
68+
"help_string": "change to this file type",
69+
"mandatory": True,
70+
"argstr": "",
71+
"allowed_values": ALLOWED_FILETYPES,
72+
}
73+
)
74+
75+
input_image: PathLike = field(metadata={"help_string": "input image", "mandatory": True, "argstr": ""})
76+
77+
output_basename: str = field(metadata={"help_string": "output basename", "formatter": _get_output_basename})
78+
79+
80+
@define(slots=False, kw_only=True)
81+
class ChFileTypeOutSpec(ShellOutSpec):
82+
"""Output specifications for fslchfiletype."""
83+
84+
output_image: File = field(metadata={"help_string": "output image", "callable": _get_output_image})
85+
86+
output_header: File = field(
87+
metadata={"help_string": "output header for filetypes which support it", "callable": _get_output_header}
88+
)
89+
90+
91+
class ChFileType(ShellCommandTask):
92+
"""Task definition for fslchfiletype."""
93+
94+
executable = "fslchfiletype"
95+
96+
input_spec = SpecInfo(name="Input", bases=(ChFileTypeSpec,))
97+
98+
output_spec = SpecInfo(name="Output", bases=(ChFileTypeOutSpec,))

src/pydra/tasks/fsl/utils/fft.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
FFT (Fast Fourier Transform)
3+
============================
4+
5+
Compute the forward or inverse Fast Fourier Transform of a NIfTI image.
6+
7+
Examples
8+
--------
9+
10+
Compute the forward FFT:
11+
12+
>>> task = FFT(input_image="input.nii")
13+
>>> task.cmdline # doctest: +ELLIPSIS
14+
'fslfft input.nii .../input_fft.nii'
15+
16+
Compute the inverse FFT:
17+
18+
>>> task = FFT(input_image="input.nii", output_image="output.nii", inverse=True)
19+
>>> task.cmdline
20+
'fslfft input.nii output.nii -inv'
21+
"""
22+
23+
__all__ = ["FFT"]
24+
25+
from os import PathLike
26+
27+
from attrs import define, field
28+
from pydra.engine.specs import ShellSpec, SpecInfo
29+
from pydra.engine.task import ShellCommandTask
30+
31+
32+
@define(kw_only=True)
33+
class FFTSpec(ShellSpec):
34+
"""Specifications for fslfft."""
35+
36+
input_image: PathLike = field(metadata={"help_string": "input image", "mandatory": True, "argstr": ""})
37+
38+
output_image: str = field(
39+
metadata={"help_string": "output image", "argstr": "", "output_file_template": "{input_image}_fft"}
40+
)
41+
42+
inverse: bool = field(metadata={"help_string": "compute the inverse FFT", "argstr": "-inv"})
43+
44+
45+
class FFT(ShellCommandTask):
46+
"""Task definition for fslfft."""
47+
48+
executable = "fslfft"
49+
50+
input_spec = SpecInfo(name="Input", bases=(FFTSpec,))

src/pydra/tasks/fsl/utils/fslchfiletype.py

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)