Skip to content

Commit

Permalink
imported newly generated auto-conv templates
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Mar 20, 2024
1 parent e36f0a0 commit fdcf89d
Show file tree
Hide file tree
Showing 78 changed files with 4,523 additions and 413 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,18 @@ dmypy.json
# Pycharm
.idea

# Vim
.*.sw[op]

# VS Code
.vscode

# Mac garbarge
.DS_store

# Generated files
/pydra/tasks/ants/_version.py
/related-packages/fileformats/fileformats/medimage_CHANGEME/_version.py
/related-packages/fileformats-extras/fileformats/extras/medimage_CHANGEME/_version.py
/pydra/tasks/ants/auto
/pydra/tasks/ants/_version.py
1 change: 0 additions & 1 deletion README.md

This file was deleted.

25 changes: 17 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
===============================
===========================
Pydra task package for ants
===============================
===========================

.. image:: https://github.com/nipype/pydra-ants/actions/workflows/pythonpackage.yaml/badge.svg
:target: https://github.com/nipype/pydra-ants/actions/workflows/pythonpackage.yaml
.. .. image:: https://codecov.io/gh/nipype/pydra-ants/branch/main/graph/badge.svg?token=UIS0OGPST7
.. :target: https://codecov.io/gh/nipype/pydra-ants
.. image:: https://github.com/nipype/pydra-ants/actions/workflows/ci-cd.yaml/badge.svg
:target: https://github.com/nipype/pydra-ants/actions/workflows/ci-cd.yaml
.. image:: https://codecov.io/gh/nipype/pydra-ants/branch/main/graph/badge.svg?token=UIS0OGPST7
:target: https://codecov.io/gh/nipype/pydra-ants
.. image:: https://img.shields.io/pypi/pyversions/pydra-ants.svg
:target: https://pypi.python.org/pypi/pydra-ants/
:alt: Supported Python versions
Expand Down Expand Up @@ -71,14 +71,22 @@ Contributing to this package
Developer installation
~~~~~~~~~~~~~~~~~~~~~~

Install the `fileformats <https://arcanaframework.github.io/fileformats/>`__ packages
corresponding to AFNI specific file formats


.. code-block::
$ pip install -e ./related-packages/fileformats[dev]
$ pip install -e ./related-packages/fileformats-extras[dev]
Install repo in developer mode from the source directory and install pre-commit to
ensure consistent code-style and quality.

.. code-block::
$ pip install -e .[test,dev]
$ pre-commit install
$ pre-commit install
Next install the requirements for running the auto-conversion script and generate the
Pydra task interfaces from their Nipype counterparts
Expand All @@ -93,7 +101,8 @@ The run the conversion script to convert Nipype interfaces to Pydra
$ nipype-auto-conv/generate
## Methodology
Methodology
~~~~~~~~~~~

The development of this package is expected to have two phases

Expand Down
8 changes: 6 additions & 2 deletions nipype-auto-conv/generate
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ from importlib import import_module
import yaml
import nipype
import nipype2pydra.utils
from nipype2pydra.task import TaskConverter
from nipype2pydra.task import get_converter


SPECS_DIR = Path(__file__).parent / "specs"
Expand All @@ -35,6 +35,7 @@ auto_dir = PKG_ROOT / "pydra" / "tasks" / PKG_NAME / "auto"
if auto_dir.exists():
shutil.rmtree(auto_dir)

all_interfaces = []
for fspath in sorted(SPECS_DIR.glob("**/*.yaml")):
with open(fspath) as f:
spec = yaml.load(f, Loader=yaml.SafeLoader)
Expand All @@ -49,13 +50,14 @@ for fspath in sorted(SPECS_DIR.glob("**/*.yaml")):

module_name = nipype2pydra.utils.to_snake_case(spec["task_name"])

converter = TaskConverter(
converter = get_converter(
output_module=f"pydra.tasks.{PKG_NAME}.auto.{module_name}",
callables_module=callables, # type: ignore
**spec,
)
converter.generate(PKG_ROOT)
auto_init += f"from .{module_name} import {converter.task_name}\n"
all_interfaces.append(converter.task_name)


with open(PKG_ROOT / "pydra" / "tasks" / PKG_NAME / "auto" / "_version.py", "w") as f:
Expand All @@ -68,5 +70,7 @@ post_release = (nipype_version + nipype2pydra_version).replace(".", "")
"""
)

auto_init += "\n\n__all__ = [\n" + "\n".join(f" \"{i}\"," for i in all_interfaces) + "\n]\n"

with open(PKG_ROOT / "pydra" / "tasks" / PKG_NAME / "auto" / "__init__.py", "w") as f:
f.write(auto_init)
11 changes: 7 additions & 4 deletions nipype-auto-conv/specs/affine_initializer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ inputs:
# type=file|default=<undefined>: reference image
moving_image: medimage/nifti1
# type=file|default=<undefined>: moving image
out_file: generic/file
out_file: Path
# type=file: output transform file
# type=file|default='transform.mat': output transform file
callable_defaults:
# dict[str, str] - names of methods/callable classes defined in the adjacent `*_callables.py`
# to set as the `default` method of input fields
metadata:
# dict[str, dict[str, any]] - additional metadata to set on any of the input fields (e.g. out_file: position: 1)
outputs:
Expand Down Expand Up @@ -88,7 +91,7 @@ tests:
environ:
# type=dict|default={}: Environment variables
imports:
# list[nipype2pydra.task.importstatement] - list import statements required by the test, with each list item
# list[nipype2pydra.task.base.importstatement] - list import statements required by the test, with each list item
# consisting of 'module', 'name', and optionally 'alias' keys
expected_outputs:
# dict[str, str] - expected values for selected outputs, noting that tests will typically
Expand All @@ -110,7 +113,7 @@ tests:
moving_image:
# type=file|default=<undefined>: moving image
imports:
# list[nipype2pydra.task.importstatement] - list import statements required by the test, with each list item
# list[nipype2pydra.task.base.importstatement] - list import statements required by the test, with each list item
# consisting of 'module', 'name', and optionally 'alias' keys
expected_outputs:
# dict[str, str] - expected values for selected outputs, noting that tests will typically
Expand All @@ -136,7 +139,7 @@ doctests:
moving_image:
# type=file|default=<undefined>: moving image
imports:
# list[nipype2pydra.task.importstatement] - list import statements required by the test, with each list item
# list[nipype2pydra.task.base.importstatement] - list import statements required by the test, with each list item
# consisting of 'module', 'name', and optionally 'alias' keys
directive:
# str - any doctest directive to place on the cmdline call, e.g. # doctest: +ELLIPSIS
21 changes: 20 additions & 1 deletion nipype-auto-conv/specs/affine_initializer_callables.py
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
"""Module to put any functions that are referred to in AffineInitializer.yaml"""
"""Module to put any functions that are referred to in the "callables" section of AffineInitializer.yaml"""

import os


def out_file_callable(output_dir, inputs, stdout, stderr):
outputs = _list_outputs(
output_dir=output_dir, inputs=inputs, stdout=stdout, stderr=stderr
)
return outputs["out_file"]


# Original source at L885 of <nipype-install>/interfaces/base/core.py
def _gen_filename(name, inputs=None, stdout=None, stderr=None, output_dir=None):
raise NotImplementedError


# Original source at L834 of <nipype-install>/interfaces/ants/utils.py
def _list_outputs(inputs=None, stdout=None, stderr=None, output_dir=None):
return {"out_file": os.path.abspath(inputs.out_file)}
11 changes: 7 additions & 4 deletions nipype-auto-conv/specs/ai.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ inputs:
# passed to the field in the automatically generated unittests.
fixed_image: generic/file
# type=file|default=<undefined>: Image to which the moving_image should be transformed
moving_image: generic/file
# type=file|default=<undefined>: Image that will be transformed to fixed_image
fixed_image_mask: generic/file
# type=file|default=<undefined>: fixed mage mask
moving_image: generic/file
# type=file|default=<undefined>: Image that will be transformed to fixed_image
moving_image_mask: generic/file
# type=file|default=<undefined>: moving mage mask
output_transform: generic/file
output_transform: Path
# type=file: output file name
# type=file|default='initialization.mat': output file name
callable_defaults:
# dict[str, str] - names of methods/callable classes defined in the adjacent `*_callables.py`
# to set as the `default` method of input fields
metadata:
# dict[str, dict[str, any]] - additional metadata to set on any of the input fields (e.g. out_file: position: 1)
outputs:
Expand Down Expand Up @@ -113,7 +116,7 @@ tests:
environ:
# type=dict|default={}: Environment variables
imports:
# list[nipype2pydra.task.importstatement] - list import statements required by the test, with each list item
# list[nipype2pydra.task.base.importstatement] - list import statements required by the test, with each list item
# consisting of 'module', 'name', and optionally 'alias' keys
expected_outputs:
# dict[str, str] - expected values for selected outputs, noting that tests will typically
Expand Down
19 changes: 18 additions & 1 deletion nipype-auto-conv/specs/ai_callables.py
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
"""Module to put any functions that are referred to in AI.yaml"""
"""Module to put any functions that are referred to in the "callables" section of AI.yaml"""


def output_transform_callable(output_dir, inputs, stdout, stderr):
outputs = _list_outputs(
output_dir=output_dir, inputs=inputs, stdout=stdout, stderr=stderr
)
return outputs["output_transform"]


# Original source at L885 of <nipype-install>/interfaces/base/core.py
def _gen_filename(name, inputs=None, stdout=None, stderr=None, output_dir=None):
raise NotImplementedError


# Original source at L539 of <nipype-install>/interfaces/ants/utils.py
def _list_outputs(inputs=None, stdout=None, stderr=None, output_dir=None):
return getattr(self, "_output")
13 changes: 8 additions & 5 deletions nipype-auto-conv/specs/ants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ inputs:
# type=inputmultiobject|default=[]: image to which the moving image is warped
moving_image: medimage/nifti1+list-of
# type=inputmultiobject|default=[]: image to apply transformation to (generally a coregisteredfunctional)
callable_defaults:
# dict[str, str] - names of methods/callable classes defined in the adjacent `*_callables.py`
# to set as the `default` method of input fields
metadata:
# dict[str, dict[str, any]] - additional metadata to set on any of the input fields (e.g. out_file: position: 1)
outputs:
Expand All @@ -65,14 +68,14 @@ outputs:
# passed to the field in the automatically generated unittests.
affine_transform: generic/file
# type=file: Affine transform file
warp_transform: generic/file
# type=file: Warping deformation field
inverse_warp_transform: generic/file
# type=file: Inverse warping deformation field
metaheader: generic/file
# type=file: VTK metaheader .mhd file
metaheader_raw: generic/file
# type=file: VTK metaheader .raw file
warp_transform: generic/file
# type=file: Warping deformation field
callables:
# dict[str, str] - names of methods/callable classes defined in the adjacent `*_callables.py`
# to set to the `callable` attribute of output fields
Expand Down Expand Up @@ -135,7 +138,7 @@ tests:
environ:
# type=dict|default={}: Environment variables
imports:
# list[nipype2pydra.task.importstatement] - list import statements required by the test, with each list item
# list[nipype2pydra.task.base.importstatement] - list import statements required by the test, with each list item
# consisting of 'module', 'name', and optionally 'alias' keys
expected_outputs:
# dict[str, str] - expected values for selected outputs, noting that tests will typically
Expand Down Expand Up @@ -185,7 +188,7 @@ tests:
number_of_affine_iterations: '[10000,10000,10000,10000,10000]'
# type=list|default=[]:
imports:
# list[nipype2pydra.task.importstatement] - list import statements required by the test, with each list item
# list[nipype2pydra.task.base.importstatement] - list import statements required by the test, with each list item
# consisting of 'module', 'name', and optionally 'alias' keys
expected_outputs:
# dict[str, str] - expected values for selected outputs, noting that tests will typically
Expand Down Expand Up @@ -239,7 +242,7 @@ doctests:
number_of_affine_iterations: '[10000,10000,10000,10000,10000]'
# type=list|default=[]:
imports:
# list[nipype2pydra.task.importstatement] - list import statements required by the test, with each list item
# list[nipype2pydra.task.base.importstatement] - list import statements required by the test, with each list item
# consisting of 'module', 'name', and optionally 'alias' keys
directive:
# str - any doctest directive to place on the cmdline call, e.g. # doctest: +ELLIPSIS
61 changes: 60 additions & 1 deletion nipype-auto-conv/specs/ants_callables.py
Original file line number Diff line number Diff line change
@@ -1 +1,60 @@
"""Module to put any functions that are referred to in ANTS.yaml"""
"""Module to put any functions that are referred to in the "callables" section of ANTS.yaml"""

import os


def affine_transform_callable(output_dir, inputs, stdout, stderr):
outputs = _list_outputs(
output_dir=output_dir, inputs=inputs, stdout=stdout, stderr=stderr
)
return outputs["affine_transform"]


def inverse_warp_transform_callable(output_dir, inputs, stdout, stderr):
outputs = _list_outputs(
output_dir=output_dir, inputs=inputs, stdout=stdout, stderr=stderr
)
return outputs["inverse_warp_transform"]


def metaheader_callable(output_dir, inputs, stdout, stderr):
outputs = _list_outputs(
output_dir=output_dir, inputs=inputs, stdout=stdout, stderr=stderr
)
return outputs["metaheader"]


def metaheader_raw_callable(output_dir, inputs, stdout, stderr):
outputs = _list_outputs(
output_dir=output_dir, inputs=inputs, stdout=stdout, stderr=stderr
)
return outputs["metaheader_raw"]


def warp_transform_callable(output_dir, inputs, stdout, stderr):
outputs = _list_outputs(
output_dir=output_dir, inputs=inputs, stdout=stdout, stderr=stderr
)
return outputs["warp_transform"]


# Original source at L885 of <nipype-install>/interfaces/base/core.py
def _gen_filename(name, inputs=None, stdout=None, stderr=None, output_dir=None):
raise NotImplementedError


# Original source at L242 of <nipype-install>/interfaces/ants/registration.py
def _list_outputs(inputs=None, stdout=None, stderr=None, output_dir=None):
outputs = {}
outputs["affine_transform"] = os.path.abspath(
inputs.output_transform_prefix + "Affine.txt"
)
outputs["warp_transform"] = os.path.abspath(
inputs.output_transform_prefix + "Warp.nii.gz"
)
outputs["inverse_warp_transform"] = os.path.abspath(
inputs.output_transform_prefix + "InverseWarp.nii.gz"
)
# outputs['metaheader'] = os.path.abspath(inputs.output_transform_prefix + 'velocity.mhd')
# outputs['metaheader_raw'] = os.path.abspath(inputs.output_transform_prefix + 'velocity.raw')
return outputs
Loading

0 comments on commit fdcf89d

Please sign in to comment.