Skip to content

[BUG]: Cannot use SpaceWarper to go from Native to template spaces#462

Merged
synchon merged 10 commits intomainfrom
update/bold-native-to-mni-warping-fsl
Sep 24, 2025
Merged

[BUG]: Cannot use SpaceWarper to go from Native to template spaces#462
synchon merged 10 commits intomainfrom
update/bold-native-to-mni-warping-fsl

Conversation

@synchon
Copy link
Copy Markdown
Member

@synchon synchon commented Sep 16, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I have a dataset in which I have the BOLD in native space, ref in MNI space and warp files to convert from native to MNI (using fsl).

I would like to compute some markers in MNI space.

I set up a pipeline using a datagrabber, default data reader, space warper and marker, with a parcellation in MNI space.

The pipeline fails:

RuntimeError: Warping to MNI152NLin6Asym space not possible with FSL, use ANTs instead.

Indeed, the traceback indicates that this is because it assumes that we have data in one template space and want to work on another template space.

    233 # Transform to template space with FSL not possible
    234 elif self.using == "fsl" and self.reference != "T1w":
--> 235     raise_error(
    236         (
    237             f"Warping to {self.reference} space not possible with "
    238             "FSL, use ANTs instead."
    239         ),
    240         klass=RuntimeError,
    241     )
    243 return input, None

Looking at the logic, we are not checking the src space, but the dst space. So currently, the SpaceWarper allows to warp to MNI or T1w references, starting always from MNI space.

Expected Behavior

I would expect that the SpaceWarper is able to warp from native to template, provided that the warping/reference files are there.

Steps To Reproduce

  1. With latest junifer
  2. Run
# %%
from junifer.datagrabber.aomic import DataladAOMICID1000
from junifer.utils import configure_logging
from junifer.pipeline import WorkDirManager
from junifer.datareader import DefaultDataReader
from junifer.preprocess import SpaceWarper

configure_logging(level="DEBUG")


element = ("sub-0001")
element_str = "_".join(element)
# %% Load data

dg = DataladAOMICID1000(
    space="native",
    types=["BOLD", "Warp"]
)

reader = DefaultDataReader()
warper = SpaceWarper(reference="MNI152NLin2009cAsym", using="fsl", on="BOLD")


# %%
with dg:
    data = dg[element]    
    data = reader.fit_transform(data)
    data = warper.fit_transform(data)

Environment

junifer:
  version: 0.0.7.dev111
python:
  version: 3.12.7
  implementation: CPython
dependencies:
  click: 8.1.7
  numpy: 1.26.4
  scipy: 1.14.1
  datalad: 1.1.4
  pandas: 2.2.3
  nibabel: 5.3.2
  nilearn: 0.10.4
  sqlalchemy: 2.0.36
  ruamel.yaml: 0.18.6
  templateflow: 24.2.2
  lazy_loader: '0.4'
  looseversion: None
  junifer_data: None
system:
  platform: Linux-6.12.9+bpo-amd64-x86_64-with-glibc2.36
environment:
  PATH: 
    /home/fraimondo/miniforge3/envs/junifer_dev/bin:/home/fraimondo/.local/bin:/home/fraimondo/miniforge3/condabin:/usr/local/bin:/home/fraimondo/.vscode-server/cli/servers/Stable-6f17636121051a53c88d3e605c491d22af2ba755/server/bin/remote-cli:/home/fraimondo/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/home/fraimondo/.vscode-server/extensions/ms-python.debugpy-2025.10.0/bundled/scripts/noConfigScripts:/home/fraimondo/.vscode-server/data/User/globalStorage/github.copilot-chat/debugCommand

Relevant log output

Anything else?

No response

@fraimondo fraimondo added bug Something isn't working triage New issues waiting to be reviewed labels Sep 15, 2025
@synchon
Copy link
Copy Markdown
Member

synchon commented Sep 16, 2025

  • By "ref in MNI space", do you mean T1w in MNI space?
  • Would you like to use T1w as the reference for warping your BOLD?

@fraimondo
Copy link
Copy Markdown
Contributor Author

  • By "ref in MNI space", do you mean T1w in MNI space?

The reference for the warping.

* Would you like to use T1w as the reference for warping your BOLD?

No. Just check the code I've pasted. We have BOLD data in native space, with the files (ref+warp) to warp the BOLD into MNI space. I would like that we are able to use the SpaceWarper to do this transform at preprocessing.

@synchon
Copy link
Copy Markdown
Member

synchon commented Sep 16, 2025

No. Just check the code I've pasted. We have BOLD data in native space, with the files (ref+warp) to warp the BOLD into MNI space. I would like that we are able to use the SpaceWarper to do this transform at preprocessing.

  • From the code you pasted, I see you want to use AOMIC ID1000. If that's the case, I don't understand why you'd want to convert to a template space we already support fetching.
  • If you have your T1w reference in MNI space, you can have your warping like so: SpaceWarper(reference="T1w", using="fsl", on="BOLD")

@synchon
Copy link
Copy Markdown
Member

synchon commented Sep 16, 2025

The error you get is due to the fact that you wanted to convert to a template space named explicitly via FSL. We support this operation via ANTs as we don't have transform files from one MNI template space to other in FSL format.

@fraimondo
Copy link
Copy Markdown
Contributor Author

No. Just check the code I've pasted. We have BOLD data in native space, with the files (ref+warp) to warp the BOLD into MNI space. I would like that we are able to use the SpaceWarper to do this transform at preprocessing.

* From the code you pasted, I see you want to use AOMIC ID1000. If that's the case, I don't understand why you'd want to convert to a template space we already support fetching.

* If you have your T1w reference in MNI space, you can have your warping like so: `SpaceWarper(reference="T1w", using="fsl", on="BOLD")`

That's a working example of the issue we need to solve. The use-case is for UKB data.

It's not converting template space. We have cleaned BOLD in native space and warp files (ref + warp) from native to MNI.

In short, this example should work.

@synchon synchon removed the triage New issues waiting to be reviewed label Sep 16, 2025
@synchon synchon self-assigned this Sep 16, 2025
@synchon synchon added this to the 0.0.7 (alpha 6) milestone Sep 16, 2025
@synchon
Copy link
Copy Markdown
Member

synchon commented Sep 16, 2025

For future reference:

  • BOLD is in native space
  • BOLD.reference is available
  • Warp from native space to MNI space is available
  • T1w is not available
  • BOLD needs to be warped from native space to MNI space using BOLD.reference and Warp
  • Adapt FSLWarper and ANTsWarper to allow warping from native space to MNI space

@github-actions
Copy link
Copy Markdown

github-actions bot commented Sep 16, 2025

PR Preview Action v1.6.2

🚀 View preview at
https://juaml.github.io/junifer/pr-preview/pr-462/

Built to branch gh-pages at 2025-09-24 13:53 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.66%. Comparing base (151631c) to head (afdfdde).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #462      +/-   ##
==========================================
- Coverage   91.67%   91.66%   -0.02%     
==========================================
  Files         146      146              
  Lines        6017     6009       -8     
  Branches      962      961       -1     
==========================================
- Hits         5516     5508       -8     
  Misses        324      324              
  Partials      177      177              
Flag Coverage Δ
docs 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
junifer/preprocess/warping/_ants_warper.py 96.15% <ø> (-0.52%) ⬇️
junifer/preprocess/warping/_fsl_warper.py 100.00% <ø> (ø)
junifer/preprocess/warping/space_warper.py 93.33% <ø> (-0.79%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@synchon synchon force-pushed the update/bold-native-to-mni-warping-fsl branch 2 times, most recently from b0f9400 to 1aaa91e Compare September 16, 2025 19:51
@synchon synchon closed this Sep 19, 2025
@synchon synchon deleted the update/bold-native-to-mni-warping-fsl branch September 19, 2025 13:12
@synchon synchon restored the update/bold-native-to-mni-warping-fsl branch September 19, 2025 13:15
@synchon synchon reopened this Sep 19, 2025
@synchon synchon force-pushed the update/bold-native-to-mni-warping-fsl branch from 3c1b414 to d64db4d Compare September 19, 2025 13:16
@synchon
Copy link
Copy Markdown
Member

synchon commented Sep 19, 2025

@fraimondo Your example now works with the latest commit. Would be great if you could try that for UKB.

@synchon synchon force-pushed the update/bold-native-to-mni-warping-fsl branch 2 times, most recently from 04d6e57 to ee75e4a Compare September 19, 2025 16:30
@synchon synchon force-pushed the update/bold-native-to-mni-warping-fsl branch from ee75e4a to afdfdde Compare September 23, 2025 12:00
@synchon synchon requested a review from fraimondo September 23, 2025 12:46
@synchon synchon added the template-space Issues or pull requests related to template spaces label Sep 23, 2025
@synchon
Copy link
Copy Markdown
Member

synchon commented Sep 23, 2025

Checked ANTs warping with AOMIC ID1000 and FSL warping with UKB. Should be good to go.

@synchon synchon merged commit 0925af8 into main Sep 24, 2025
2 of 10 checks passed
@synchon synchon deleted the update/bold-native-to-mni-warping-fsl branch September 24, 2025 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working template-space Issues or pull requests related to template spaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants