nipreps / sdcflows

Susceptibility Distortion Correction (SDC) workflows for EPI MR schemes
https://www.nipreps.org/sdcflows
Apache License 2.0
31 stars 24 forks source link

NodeExecutionError triggered when using `UniformGrid` and images with slightly different affines #442

Closed psadil closed 3 months ago

psadil commented 4 months ago

What happened?

A NodeExecutionError was triggered when I tried to run sdcflows.workflows.fit.pepolar.init_topup_wf with a pair of niftis that had slightly different affine matrices. The error came from the regrid node.

What command did you use?

import nibabel as nb
from sdcflows.interfaces import utils
from nipype.pipeline import engine as pe
import tempfile
import numpy as np

affine = np.eye(4, 4)
dataobj = np.zeros((3, 3, 3))
with tempfile.NamedTemporaryFile(suffix=".nii.gz") as nii1:
    nb.nifti1.Nifti1Image(dataobj, affine).to_filename(nii1.name)
    with tempfile.NamedTemporaryFile(suffix=".nii.gz") as nii2:
        nb.nifti1.Nifti1Image(dataobj, affine * 0.99999).to_filename(
            nii2.name
        )

        regrid = pe.Node(utils.UniformGrid(reference=0), name="regrid")
        regrid.inputs.in_data = [nii1.name, nii2.name]
        regrid.run()

What version of the software are you running?

2.8.1

How are you running this software?

Local installation ("bare-metal")

Is your data BIDS valid?

Yes

Are you reusing any previously computed results?

No

Please copy and paste any relevant log output.

---------------------------------------------------------------------------
NodeExecutionError                        Traceback (most recent call last)
File /Users/psadil/git/a2cps/sdc-3dqwarp-topup/run.py:12
     10 regrid = pe.Node(utils.UniformGrid(reference=0), name="regrid")
     11 regrid.inputs.in_data = [nii1.name, nii2.name]
---> 12 regrid.run()

File ~/mambaforge/envs/sdc/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py:527, in Node.run(self, updatehash)
    524 savepkl(op.join(outdir, "_inputs.pklz"), self.inputs.get_traitsfree())
    526 try:
--> 527     result = self._run_interface(execute=True)
    528 except Exception:
    529     logger.warning('[Node] Error on "%s" (%s)', self.fullname, outdir)

File ~/mambaforge/envs/sdc/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py:645, in Node._run_interface(self, execute, updatehash)
    643     self._update_hash()
    644     return self._load_results()
--> 645 return self._run_command(execute)

File ~/mambaforge/envs/sdc/lib/python3.10/site-packages/nipype/pipeline/engine/nodes.py:771, in Node._run_command(self, execute, copyfiles)
    769     # Always pass along the traceback
    770     msg += f"Traceback:\n{_tab(runtime.traceback)}"
--> 771     raise NodeExecutionError(msg)
    773 return result

NodeExecutionError: Exception raised while executing Node regrid.

Traceback:
    Traceback (most recent call last):
      File "/Users/psadil/mambaforge/envs/sdc/lib/python3.10/site-packages/nipype/interfaces/base/core.py", line 397, in run
        runtime = self._run_interface(runtime)
      File "/Users/psadil/mambaforge/envs/sdc/lib/python3.10/site-packages/sdcflows/interfaces/utils.py", line 143, in _run_interface
        regridded_img = resampler.apply(nii.__class__(np.asanyarray(nii.dataobj), nii.affine))
    AttributeError: 'Affine' object has no attribute 'apply'

Additional information / screenshots

Should line 143 be resampler.map instead?

https://github.com/nipreps/sdcflows/blob/245648997022fabcfa218a3eb4716d7f304ba645/sdcflows/interfaces/utils.py#L124-L143

effigies commented 4 months ago

Do you have an unreleased version of nitransforms installed? That's most likely the problem here.

cc @oesteban @jmarabotto The blast radius from moving apply from a method to a function might be large. We might want to restore a stub into BaseTransform to give projects time to adapt:

def apply(self, *args, **kwargs):
    warnings.warn(f"{self.__class__}.apply() is deprecated; use nitransforms.resampling.apply()", DeprecationWarning)
    nt.resampling.apply(self, *args, **kwargs)
psadil commented 4 months ago

Do you have an unreleased version of nitransforms installed? That's most likely the problem here.

Oh shoot, thanks. Yes, that's the issue. Feel free to close

oesteban commented 4 months ago

nitransforms is experimenstable :D

Can't break things for being stable and at the same time required to be cutting edge.

Thanks for the heads-up @psadil

On Tue, May 28, 2024, 22:33 Patrick Sadil @.***> wrote:

Do you have an unreleased version of nitransforms installed? That's most likely the problem here.

Oh shoot, thanks. Yes, that's the issue. Feel free to close

— Reply to this email directly, view it on GitHub https://github.com/nipreps/sdcflows/issues/442#issuecomment-2136057994, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAESDRSSX3FA4SAWQAGNJ7LZETSYXAVCNFSM6AAAAABINPGHDGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZWGA2TOOJZGQ . You are receiving this because you were mentioned.Message ID: @.***>