From 8e0fcf5d0192c6c9863aa2705665eece233ecad6 Mon Sep 17 00:00:00 2001 From: Fede Raimondo Date: Wed, 28 Jan 2026 09:06:40 +0100 Subject: [PATCH 1/5] Fix logic in SpaceWarper --- junifer/preprocess/warping/space_warper.py | 71 ++++++++-------------- 1 file changed, 26 insertions(+), 45 deletions(-) diff --git a/junifer/preprocess/warping/space_warper.py b/junifer/preprocess/warping/space_warper.py index 8dc02febb..fd8521af7 100644 --- a/junifer/preprocess/warping/space_warper.py +++ b/junifer/preprocess/warping/space_warper.py @@ -140,9 +140,7 @@ class SpaceWarper(BasePreprocessor): """ logger.info(f"Warping to {self.reference} space using SpaceWarper") # Transform to native space - if ( - self.using in ["fsl", "ants", "auto"] and self.reference == "T1w" - ): # pragma: no cover + if self.reference == "T1w": # pragma: no cover # Check for extra inputs if extra_input is None: raise_error( @@ -150,20 +148,8 @@ class SpaceWarper(BasePreprocessor): f"`{self.reference}` data types in particular." ) # Conditional preprocessor - if self.using == "fsl": - input = FSLWarper().preprocess( - input=input, - extra_input=extra_input, - reference=self.reference, - ) - elif self.using == "ants": - input = ANTsWarper().preprocess( - input=input, - extra_input=extra_input, - reference=self.reference, - ) - elif self.using == "auto": - warper = None + warper = None + if self.using == "auto": for entry in extra_input["Warp"]: if entry["dst"] == "native": warper = entry["warper"] @@ -171,34 +157,24 @@ class SpaceWarper(BasePreprocessor): raise_error( klass=RuntimeError, msg="Could not find correct warper" ) - if warper == "fsl": - input = FSLWarper().preprocess( - input=input, - extra_input=extra_input, - reference=self.reference, - ) - elif warper == "ants": - input = ANTsWarper().preprocess( - input=input, - extra_input=extra_input, - reference=self.reference, - ) - # Transform to template space - if self.using in ["fsl", "ants"] and self.reference != "T1w": - input_space = input["space"] - # Check pre-requirements for space manipulation - if self.using == "ants" and self.reference == input_space: - raise_error( - ( - f"The target data is in {self.reference} space " - "and thus warping will not be performed, hence you " - "should remove the SpaceWarper from the preprocess " - "step." - ), - klass=RuntimeError, + else: + warper = self.using + if warper == "fsl": + input = FSLWarper().preprocess( + input=input, + extra_input=extra_input, + reference=self.reference, ) - # Transform from native to MNI possible conditionally - if input_space == "native": # pragma: no cover + elif warper == "ants": + input = ANTsWarper().preprocess( + input=input, + extra_input=extra_input, + reference=self.reference, + ) + else: + input_space = input["space"] + # Transform from native space + if input_space == "native": # Check for reference as no T1w available if input.get("reference") is None: raise_error( @@ -257,5 +233,10 @@ class SpaceWarper(BasePreprocessor): extra_input={}, reference=self.reference, ) - + logger.debug("Completed warping step") + logger.debug("Warped data types: ") + for k, v in input.items(): + if k in ["data", "meta"]: + continue + logger.debug(f"\t{k}: {v}") return input -- 2.52.0 From 82bb182baa1712a317d5cf20be7e4f6bdb126d71 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 29 Jan 2026 11:53:28 +0100 Subject: [PATCH 2/5] fix: revert no warp check when src and dst template spaces are same This reverts commit 18a54c7b933920c80cc518bae18a5fd84a67c339. --- junifer/preprocess/warping/space_warper.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/junifer/preprocess/warping/space_warper.py b/junifer/preprocess/warping/space_warper.py index fd8521af7..bafacb678 100644 --- a/junifer/preprocess/warping/space_warper.py +++ b/junifer/preprocess/warping/space_warper.py @@ -173,8 +173,19 @@ class SpaceWarper(BasePreprocessor): ) else: input_space = input["space"] - # Transform from native space - if input_space == "native": + # Check pre-requirements for space manipulation + if self.using == "ants" and self.reference == input_space: + raise_error( + ( + f"The target data is in {self.reference} space " + "and thus warping will not be performed, hence you " + "should remove the SpaceWarper from the preprocess " + "step." + ), + klass=RuntimeError, + ) + # Transform from native to MNI possible conditionally + if input_space == "native": # pragma: no cover # Check for reference as no T1w available if input.get("reference") is None: raise_error( -- 2.52.0 From 8df9aefe20a0ba373b9c19ea8d44401c5eefe3ae Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 29 Jan 2026 12:22:08 +0100 Subject: [PATCH 3/5] update: block use of "auto" for template to template space conversion in SpaceWarper --- junifer/preprocess/warping/space_warper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/junifer/preprocess/warping/space_warper.py b/junifer/preprocess/warping/space_warper.py index bafacb678..b2713414b 100644 --- a/junifer/preprocess/warping/space_warper.py +++ b/junifer/preprocess/warping/space_warper.py @@ -228,12 +228,12 @@ class SpaceWarper(BasePreprocessor): ) else: # Transform from MNI to MNI template space not possible - if self.using == "fsl": + if self.using in ["fsl", "auto"]: raise_error( ( f"Warping from {input_space} space to " f"{self.reference} space not possible with " - "FSL, use ANTs instead." + f"{self.using}, use ANTs instead." ), klass=RuntimeError, ) -- 2.52.0 From e4a420836fd575d1b29b6086c9e1c529594813fa Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 29 Jan 2026 12:22:45 +0100 Subject: [PATCH 4/5] chore: update docstring for SpaceWarper --- junifer/preprocess/warping/space_warper.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/junifer/preprocess/warping/space_warper.py b/junifer/preprocess/warping/space_warper.py index b2713414b..171b4b45a 100644 --- a/junifer/preprocess/warping/space_warper.py +++ b/junifer/preprocess/warping/space_warper.py @@ -129,13 +129,16 @@ class SpaceWarper(BasePreprocessor): ------ ValueError If ``extra_input`` is None when transforming to native space - i.e., using ``"T1w"`` as reference. + i.e., using ``"T1w"`` as reference or converting from native to + template space or + if the ``reference`` key is missing from ``input`` when converting + from native to template space. RuntimeError If warper could not be found in ``extra_input`` when ``using="auto"`` or converting from native space or if the data is in the correct space and does not require warping or - if FSL is used when ``reference="T1w"``. + if FSL or "auto" is used when ``reference!="T1w"``. """ logger.info(f"Warping to {self.reference} space using SpaceWarper") -- 2.52.0 From 6c48e06369325dc0797869cbbe8f142dcdb500c0 Mon Sep 17 00:00:00 2001 From: Synchon Mandal Date: Thu, 29 Jan 2026 13:05:03 +0100 Subject: [PATCH 5/5] chore: add changelog 482.bugfix --- docs/changes/newsfragments/482.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/newsfragments/482.bugfix diff --git a/docs/changes/newsfragments/482.bugfix b/docs/changes/newsfragments/482.bugfix new file mode 100644 index 000000000..68870b7bc --- /dev/null +++ b/docs/changes/newsfragments/482.bugfix @@ -0,0 +1 @@ +Allow :class:`.SpaceWarper` to convert data from native to template space when ``using="auto"`` by `Fede Raimondo`_ and `Synchon Mandal`_ -- 2.52.0