Skip to content

Commit

Permalink
moved packages out of src and set up auto version
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Mar 25, 2024
1 parent 9985b1a commit dc54ad7
Show file tree
Hide file tree
Showing 49 changed files with 629 additions and 211 deletions.
38 changes: 38 additions & 0 deletions pydra/tasks/fsl/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
This is a basic doctest demonstrating that the package and pydra can both be successfully
imported.
>>> import pydra.engine
>>> import pydra.tasks.fsl
"""

from warnings import warn
from pathlib import Path

pkg_path = Path(__file__).parent.parent

try:
from ._version import __version__
except ImportError:
raise RuntimeError(
"pydra-fsl has not been properly installed, please run "
f"`pip install -e {str(pkg_path)}` to install a development version"
)
if "nipype" not in __version__:
try:
from .auto._version import nipype_version, nipype2pydra_version
except ImportError:
warn(
"Nipype interfaces haven't been automatically converted from their specs in "
f"`nipype-auto-conv`. Please run `{str(pkg_path / 'nipype-auto-conv' / 'generate')}` "
"to generated the converted Nipype interfaces in pydra.tasks.fsl.auto"
)
else:
n_ver = nipype_version.replace(".", "_")
n2p_ver = nipype2pydra_version.replace(".", "_")
__version__ += (
"_" if "+" in __version__ else "+"
) + f"nipype{n_ver}_nipype2pydra{n2p_ver}"


__all__ = ["__version__"]
3 changes: 3 additions & 0 deletions pydra/tasks/fsl/latest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PACKAGE_VERSION = "v6_0"

from .v6_0 import * # noqa
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ class BETSpec(pydra.specs.ShellSpec):
metadata={"help_string": "save brain surface outline", "argstr": "-o"}
)

save_brain_mask: bool = attrs.field(metadata={"help_string": "save binary brain mask", "argstr": "-m"})
save_brain_mask: bool = attrs.field(
metadata={"help_string": "save binary brain mask", "argstr": "-m"}
)

save_skull_image: bool = attrs.field(metadata={"help_string": "save approximate skull image", "argstr": "-s"})
save_skull_image: bool = attrs.field(
metadata={"help_string": "save approximate skull image", "argstr": "-s"}
)

save_brain_surface_mesh: bool = attrs.field(
metadata={
Expand Down Expand Up @@ -74,7 +78,8 @@ class BETSpec(pydra.specs.ShellSpec):

head_radius: float = attrs.field(
metadata={
"help_string": "Head radius (in millimeters)." " Initial surface sphere is set to half of this value.",
"help_string": "Head radius (in millimeters)."
" Initial surface sphere is set to half of this value.",
"argstr": "-r",
}
)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def _to_input_index(field: Union[int, Sequence[int]]) -> str:
return f"--inindex={','.join(str(index) for index in indexes)}"


def _to_topup_basename(fieldmap_image: PathLike, field_coefficients_image: PathLike) -> str:
def _to_topup_basename(
fieldmap_image: PathLike, field_coefficients_image: PathLike
) -> str:
if field_coefficients_image:
path = PurePath(field_coefficients_image)
basename = path.parent / path.name.split("_fieldcoef", 1)[0]
Expand Down Expand Up @@ -123,7 +125,11 @@ class ApplyTopupSpec(ShellSpec):
)

fieldmap_image: PathLike = field(
metadata={"help_string": "fieldmap image", "mandatory": True, "xor": {"field_coefficients_image"}}
metadata={
"help_string": "fieldmap image",
"mandatory": True,
"xor": {"field_coefficients_image"},
}
)

field_coefficients_image: PathLike = field(
Expand All @@ -135,10 +141,16 @@ class ApplyTopupSpec(ShellSpec):
}
)

movement_parameters_file: PathLike = field(metadata={"help_string": "movement parameters file computed by topup"})
movement_parameters_file: PathLike = field(
metadata={"help_string": "movement parameters file computed by topup"}
)

output_image: PathLike = field(
metadata={"help_string": "output image", "argstr": "--out", "formatter": _to_output_image}
metadata={
"help_string": "output image",
"argstr": "--out",
"formatter": _to_output_image,
}
)

method: str = field(
Expand Down Expand Up @@ -168,7 +180,9 @@ class ApplyTopupSpec(ShellSpec):
},
)

verbose: bool = field(metadata={"help_string": "enable verbose logging", "argstr": "--verbose"})
verbose: bool = field(
metadata={"help_string": "enable verbose logging", "argstr": "--verbose"}
)


class ApplyTopup(ShellCommandTask):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class EddySpec(ShellSpec):
}
)

fieldmap_image: PathLike = field(metadata={"help_string": "fieldmap image", "argstr": "--field={fieldmap_image}"})
fieldmap_image: PathLike = field(
metadata={"help_string": "fieldmap image", "argstr": "--field={fieldmap_image}"}
)

fieldmap_matrix: PathLike = field(
metadata={
Expand All @@ -95,7 +97,10 @@ class EddySpec(ShellSpec):
)

no_peas: bool = field(
metadata={"help_string": "do not perform post-Eddy alignment of shells", "argstr": "--dont_peas"}
metadata={
"help_string": "do not perform post-Eddy alignment of shells",
"argstr": "--dont_peas",
}
)

# Parameters specifying names of output-files.
Expand Down Expand Up @@ -142,7 +147,9 @@ class EddySpec(ShellSpec):
},
)

fill_empty_planes: bool = field(metadata={"help_string": "detect and fill empty planes", "argstr": "--fep"})
fill_empty_planes: bool = field(
metadata={"help_string": "detect and fill empty planes", "argstr": "--fep"}
)

interpolation: str = field(
default="spline",
Expand Down Expand Up @@ -179,7 +186,9 @@ class EddySpec(ShellSpec):
)

# Parameters for outlier replacement (ol)
replace_outliers: bool = field(metadata={"help_string": "replace outliers", "argstr": "--repol"})
replace_outliers: bool = field(
metadata={"help_string": "replace outliers", "argstr": "--repol"}
)

outlier_num_stdevs: int = field(
metadata={
Expand All @@ -206,7 +215,12 @@ class EddySpec(ShellSpec):
}
)

multiband_factor: int = field(metadata={"help_string": "multiband factor", "argstr": "--mb={multiband_factor}"})
multiband_factor: int = field(
metadata={
"help_string": "multiband factor",
"argstr": "--mb={multiband_factor}",
}
)

multiband_offset: int = field(
metadata={
Expand Down Expand Up @@ -297,18 +311,33 @@ class EddySpec(ShellSpec):

# Miscellaneous parameters.
data_is_shelled: bool = field(
metadata={"help_string": "bypass checks for data shelling", "argstr": "--data_is_shelled"}
metadata={
"help_string": "bypass checks for data shelling",
"argstr": "--data_is_shelled",
}
)

random_seed: int = field(
metadata={"help_string": "random seed for voxel selection", "argstr": "--initrand={random_seed}"}
metadata={
"help_string": "random seed for voxel selection",
"argstr": "--initrand={random_seed}",
}
)

save_cnr_maps: bool = field(metadata={"help_string": "save shell-wise CNR maps", "argstr": "--cnr_maps"})
save_cnr_maps: bool = field(
metadata={"help_string": "save shell-wise CNR maps", "argstr": "--cnr_maps"}
)

save_residuals: bool = field(metadata={"help_string": "save residuals for all scans", "argstr": "--residuals"})
save_residuals: bool = field(
metadata={
"help_string": "save residuals for all scans",
"argstr": "--residuals",
}
)

verbose: bool = field(metadata={"help_string": "enable verbose logging", "argstr": "--verbose"})
verbose: bool = field(
metadata={"help_string": "enable verbose logging", "argstr": "--verbose"}
)


@define(slots=False, kw_only=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ class TopupSpec(ShellSpec):
"""Specifications for topup."""

input_image: PathLike = field(
metadata={"help_string": "input image", "mandatory": True, "argstr": "--imain={input_image}"}
metadata={
"help_string": "input image",
"mandatory": True,
"argstr": "--imain={input_image}",
}
)

encoding_file: PathLike = field(
Expand Down Expand Up @@ -204,10 +208,16 @@ class TopupSpec(ShellSpec):
)

num_threads: int = field(
default=1, metadata={"help_string": "number of threads to use", "argstr": "--nthr={num_threads}"}
default=1,
metadata={
"help_string": "number of threads to use",
"argstr": "--nthr={num_threads}",
},
)

verbose: bool = field(metadata={"help_string": "enable verbose logging", "argstr": "--verbose"})
verbose: bool = field(
metadata={"help_string": "enable verbose logging", "argstr": "--verbose"}
)


@define(slots=False, kw_only=True)
Expand Down
4 changes: 3 additions & 1 deletion src/pydra/tasks/fsl/fast.py → pydra/tasks/fsl/v6_0/fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class FASTSpec(pydra.specs.ShellSpec):
"help_string": "type of input image (T1, T2 or PD)",
"argstr": "-t",
"allowed_values": {"T1", "T2", "PD"},
"formatter": lambda image_type: "-t {:d}".format({"T1": 1, "T2": 2, "PD": 3}.get(image_type)),
"formatter": lambda image_type: "-t {:d}".format(
{"T1": 1, "T2": 2, "PD": 3}.get(image_type)
),
},
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,19 @@ class ConvertXFMSpec(BaseSpec):
"""Specifications for convert_xfm."""

fixscaleskew_matrix: os.PathLike = attrs.field(
metadata={"help_string": " fix scaling and skewness with this matrix", "argstr": "-fixscaleskew"}
metadata={
"help_string": " fix scaling and skewness with this matrix",
"argstr": "-fixscaleskew",
}
)

concat_matrix: os.PathLike = attrs.field(
metadata={"help_string": "concatenate with this matrix", "argstr": "-concat"}
)

inverse: bool = attrs.field(metadata={"help_string": "invert the resulting matrix", "argstr": "-inverse"})
inverse: bool = attrs.field(
metadata={"help_string": "invert the resulting matrix", "argstr": "-inverse"}
)


class ConvertXFM(pydra.engine.ShellCommandTask):
Expand All @@ -89,7 +94,11 @@ class ConcatXFMSpec(BaseSpec):
"""Specifications for concat_xfm."""

concat_matrix: os.PathLike = attrs.field(
metadata={"help_string": "concatenate with this matrix", "mandatory": True, "argstr": "-concat"}
metadata={
"help_string": "concatenate with this matrix",
"mandatory": True,
"argstr": "-concat",
}
)


Expand All @@ -103,7 +112,10 @@ class ConcatXFM(ConvertXFM):
class InvertXFMSpec(BaseSpec):
"""Specifications for invert_xfm."""

inverse: bool = attrs.field(default=True, metadata={"help_string": "invert the input matrix", "argstr": "-inverse"})
inverse: bool = attrs.field(
default=True,
metadata={"help_string": "invert the input matrix", "argstr": "-inverse"},
)


class InvertXFM(ConvertXFM):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,20 @@
class BaseSpec(ShellSpec):
"""Common specifications for FLIRT-based tasks."""

input_image: PathLike = field(metadata={"help_string": "input image", "mandatory": True, "argstr": "-in"})
input_image: PathLike = field(
metadata={"help_string": "input image", "mandatory": True, "argstr": "-in"}
)

reference_image: PathLike = field(metadata={"help_string": "reference image", "mandatory": True, "argstr": "-ref"})
reference_image: PathLike = field(
metadata={"help_string": "reference image", "mandatory": True, "argstr": "-ref"}
)

output_image: str = field(
metadata={"help_string": "output image", "argstr": "-out", "output_file_template": "{input_image}_flirt"}
metadata={
"help_string": "output image",
"argstr": "-out",
"output_file_template": "{input_image}_flirt",
}
)

output_datatype: str = field(
Expand All @@ -96,14 +104,22 @@ class FLIRTSpec(BaseSpec):
"""Specifications for FLIRT."""

input_weights: PathLike = field(
metadata={"help_string": "voxel-wise weighting for input image", "argstr": "-inweight"}
metadata={
"help_string": "voxel-wise weighting for input image",
"argstr": "-inweight",
}
)

reference_weights: PathLike = field(
metadata={"help_string": "voxel-wise weighting for reference image", "argstr": "-refweight"}
metadata={
"help_string": "voxel-wise weighting for reference image",
"argstr": "-refweight",
}
)

initial_matrix: PathLike = field(metadata={"help_string": "initial transformation matrix", "argstr": "-init"})
initial_matrix: PathLike = field(
metadata={"help_string": "initial transformation matrix", "argstr": "-init"}
)

output_matrix: str = field(
metadata={
Expand Down Expand Up @@ -155,23 +171,33 @@ class ApplyXFMSpec(BaseSpec):
"""Specifications for ApplyXFM."""

initial_matrix: PathLike = field(
metadata={"help_string": "initial transformation matrix", "mandatory": True, "argstr": "-init"}
metadata={
"help_string": "initial transformation matrix",
"mandatory": True,
"argstr": "-init",
}
)

isotropic_resolution: float = field(
default=0.0,
metadata={
"help_string": "force resampling to isotropic resolution",
"formatter": lambda isotropic_resolution: (
f"-applyisoxfm {isotropic_resolution}" if isotropic_resolution else "-applyxfm"
f"-applyisoxfm {isotropic_resolution}"
if isotropic_resolution
else "-applyxfm"
),
},
)

padding_size: float = field(metadata={"help_string": "padding size in voxels", "argstr": "-paddingsize"})
padding_size: float = field(
metadata={"help_string": "padding size in voxels", "argstr": "-paddingsize"}
)


class ApplyXFM(FLIRT):
"""Task definition for ApplyXFM."""

input_spec = SpecInfo(name="Input", bases=(ApplyXFMSpec, specs.InterpolationSpec, specs.VerboseSpec))
input_spec = SpecInfo(
name="Input", bases=(ApplyXFMSpec, specs.InterpolationSpec, specs.VerboseSpec)
)
Loading

0 comments on commit dc54ad7

Please sign in to comment.