Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/newsfragments/482.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow :class:`.SpaceWarper` to convert data from native to template space when ``using="auto"`` by `Fede Raimondo`_ and `Synchon Mandal`_
61 changes: 28 additions & 33 deletions junifer/preprocess/warping/space_warper.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,62 +129,52 @@ def preprocess( # noqa: C901
------
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")
# 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(
"No extra input provided, requires `Warp` and "
f"`{self.reference}` data types in particular."
)
# Conditional preprocessor
if self.using == "fsl":
warper = None
if self.using == "auto":
for entry in extra_input["Warp"]:
if entry["dst"] == "native":
warper = entry["warper"]
if warper is None:
raise_error(
klass=RuntimeError, msg="Could not find correct warper"
)
else:
warper = self.using
if warper == "fsl":
input = FSLWarper().preprocess(
input=input,
extra_input=extra_input,
reference=self.reference,
)
elif self.using == "ants":
elif warper == "ants":
input = ANTsWarper().preprocess(
input=input,
extra_input=extra_input,
reference=self.reference,
)
elif self.using == "auto":
warper = None
for entry in extra_input["Warp"]:
if entry["dst"] == "native":
warper = entry["warper"]
if warper is None:
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":
else:
input_space = input["space"]
# Check pre-requirements for space manipulation
if self.using == "ants" and self.reference == input_space:
Expand Down Expand Up @@ -241,12 +231,12 @@ def preprocess( # noqa: C901
)
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,
)
Expand All @@ -257,5 +247,10 @@ def preprocess( # noqa: C901
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
Loading