nipy / nipype

Workflows and interfaces for neuroimaging packages
https://nipype.readthedocs.org/en/latest/
Other
751 stars 530 forks source link

AFNI Zeropad out_file undefined #3640

Open zachlindsey opened 8 months ago

zachlindsey commented 8 months ago

Summary

It looks like something odd is happening with some of the AFNI input specs. Here is the current one for Zeropad:

    out_file = File(
        name_template="zeropad",
        desc="output dataset prefix name (default 'zeropad')",
        argstr="-prefix %s",
    )

From what I can tell, it makes no sense to provide a name_template that doesn't have any %s characters, and also to provide it when there is no name_source. The underlying AFNI command seems to always just output "zeropad" if you don't provide a prefix, with no reference to the input file at all.

But it gets worse! It also seems like if an input doesn't have a name_source field on the input spec, the out_file field on the outputs will always be undefined!

Actual behavior

When you run the code below in a python interactive environment, it raises an error on the second assertion, and the final line outputs <undefined>. Since the out_file is undefined, if this is a node in a workflow, you cannot connect its output to other nodes without headaches.

Expected behavior

Set the out_file to the full filepath of the padded.nii.gz file. If no output file is specified, set it to the full filepath of the default output file, zeropad+tlrc.BRIK,

How to replicate the behavior

Script/Workflow details

from pathlib import Path
import os
from nipype.interfaces.afni import Zeropad

cwd = os.getcwd()
expected_outfile = Path(cwd) / "test_pad.nii.gz"
if expected_outfile.exists():
    expected_outfile.unlink()

zp = Zeropad(I = 1, out_file = "test_pad.nii.gz")
zp.inputs.in_files = "/your/test/nifii.nii.gz"

result = zp.run()

assert expected_outfile.exists()
assert result.outputs.out_file == expected_outfile

result.outputs.out_file

Platform details:

{'commit_hash': '<not found>',
 'commit_source': '(none found)',
 'networkx_version': '3.2.1',
 'nibabel_version': '5.2.1',
 'nipype_version': '1.8.6',
 'numpy_version': '1.26.4',
 'pkg_path': '/home/epl6876/.cache/pypoetry/virtualenvs/abc-image-processing-bNVxWkFq-py3.9/lib/python3.9/site-packages/nipype',
 'scipy_version': '1.12.0',
 'sys_executable': '/home/epl6876/.cache/pypoetry/virtualenvs/abc-image-processing-bNVxWkFq-py3.9/bin/python',
 'sys_platform': 'linux',
 'sys_version': '3.9.18 (main, Feb  1 2024, 11:48:51) \n[GCC 11.4.0]',
 'traits_version': '6.3.2'}

Execution environment

My python environment outside container

zachlindsey commented 8 months ago

I should mention I think that several other of the AFNI commands suffer from the same problem. If I should fix all of them, I can do that.