From e37744337ee8c69dee6785a5161709704b4bca2b Mon Sep 17 00:00:00 2001 From: Lea Waller Date: Fri, 7 Mar 2025 15:00:22 +0100 Subject: [PATCH 1/2] Fix AttributeError for _ApplyCoeffsFieldInputSpec Nipype expects the `xor` attribute for traits to always be a list. If it's just a string, then the individual characters of the string will be iterated, leading to an AttributeError when no single character attribute exists on the spec. --- sdcflows/interfaces/bspline.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdcflows/interfaces/bspline.py b/sdcflows/interfaces/bspline.py index f2b1dfaa14..2f0199fe3b 100644 --- a/sdcflows/interfaces/bspline.py +++ b/sdcflows/interfaces/bspline.py @@ -309,12 +309,12 @@ class _ApplyCoeffsFieldInputSpec(BaseInterfaceInputSpec): fmap2data_xfm = InputMultiObject( File(exists=True), desc="the transform by which the target EPI can be resampled on the fieldmap's grid.", - xor="data2fmap_xfm", + xor=["data2fmap_xfm"], ) data2fmap_xfm = InputMultiObject( File(exists=True), desc="the transform by which the fieldmap can be resampled on the target EPI's grid.", - xor="fmap2data_xfm", + xor=["fmap2data_xfm"], ) in_xfms = traits.List( traits.List(traits.List(traits.Float)), From 9c1c0c0ae30c863481910460f05c5a5f85d44f80 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Fri, 7 Mar 2025 13:40:54 -0500 Subject: [PATCH 2/2] test: Add doctest to ApplyCoeffsField --- sdcflows/conftest.py | 1 + sdcflows/interfaces/bspline.py | 18 ++++++++++++++++++ sdcflows/tests/data/epi2fmap_xfm.txt | 0 sdcflows/tests/data/fmap2epi_xfm.txt | 0 4 files changed, 19 insertions(+) create mode 100644 sdcflows/tests/data/epi2fmap_xfm.txt create mode 100644 sdcflows/tests/data/fmap2epi_xfm.txt diff --git a/sdcflows/conftest.py b/sdcflows/conftest.py index e8f2e709be..bfcc77ae86 100644 --- a/sdcflows/conftest.py +++ b/sdcflows/conftest.py @@ -72,6 +72,7 @@ def doctest_fixture(doctest_namespace, request): dsA_dir=data_dir / "dsA", dsB_dir=data_dir / "dsB", dsC_dir=data_dir / "dsC", + data_dir=data_dir, ) doctest_namespace.update((key, Path(val.root)) for key, val in layouts.items()) diff --git a/sdcflows/interfaces/bspline.py b/sdcflows/interfaces/bspline.py index 2f0199fe3b..4268a18ed5 100644 --- a/sdcflows/interfaces/bspline.py +++ b/sdcflows/interfaces/bspline.py @@ -380,6 +380,24 @@ class ApplyCoeffsField(SimpleInterface): With those coordinates known, interpolation is trivial. 4. Generate a spatial image with the new data. + Example + ------- + + >>> from sdcflows.interfaces.bspline import ApplyCoeffsField + >>> unwarp = ApplyCoeffsField(pe_dir='j', ro_time=0.03125) + >>> unwarp.inputs.in_data = str(data_dir / 'epi.nii.gz') + >>> unwarp.inputs.in_coeff = str(data_dir / 'topup-coeff.nii.gz') + >>> unwarp.inputs.data2fmap_xfm = str(data_dir / 'epi2fmap_xfm.txt') + >>> result = unwarp.run() # doctest: +SKIP + + Inverse transforms may be used instead: + + >>> unwarp = ApplyCoeffsField(pe_dir='j', ro_time=0.03125) + >>> unwarp.inputs.in_data = str(data_dir / 'epi.nii.gz') + >>> unwarp.inputs.in_coeff = str(data_dir / 'topup-coeff.nii.gz') + >>> unwarp.inputs.fmap2data_xfm = str(data_dir / 'fmap2epi_xfm.txt') + >>> result = unwarp.run() # doctest: +SKIP + """ input_spec = _ApplyCoeffsFieldInputSpec diff --git a/sdcflows/tests/data/epi2fmap_xfm.txt b/sdcflows/tests/data/epi2fmap_xfm.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sdcflows/tests/data/fmap2epi_xfm.txt b/sdcflows/tests/data/fmap2epi_xfm.txt new file mode 100644 index 0000000000..e69de29bb2