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

Merged
synchon merged 10 commits from update/bold-native-to-mni-warping-fsl into main 2025-09-24 12:48:10 +00:00
synchon commented 2025-09-16 14:50:37 +00:00 (Migrated from github.com)

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

### Is there an existing issue for this? - [x] 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 ```markdown 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 ```shell ``` ### Anything else? _No response_
synchon commented 2025-09-16 09:53:28 +00:00 (Migrated from github.com)
  • 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?
- 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 commented 2025-09-16 10:01:18 +00:00 (Migrated from github.com)
  • 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.

> * 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 commented 2025-09-16 11:07:49 +00:00 (Migrated from github.com)

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")
> 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 commented 2025-09-16 11:10:19 +00:00 (Migrated from github.com)

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.

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 commented 2025-09-16 11:16:36 +00:00 (Migrated from github.com)

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.

> > 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 commented 2025-09-16 15:19:51 +00:00 (Migrated from github.com)

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
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[bot] commented 2025-09-16 15:33:22 +00:00 (Migrated from github.com)
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.

[PR Preview Action](https://github.com/rossjrw/pr-preview-action) v1.6.2 :---: | <p></p> :rocket: View preview at <br> https://juaml.github.io/junifer/pr-preview/pr-462/ <br><br> | <h6>Built to branch [`gh-pages`](https://github.com/juaml/junifer/tree/gh-pages) at 2025-09-24 13:53 UTC. <br> Preview will be ready when the [GitHub Pages deployment](https://github.com/juaml/junifer/deployments) is complete. <br><br> </h6> <!-- Sticky Pull Request Commentpr-preview -->
codecov[bot] commented 2025-09-16 15:38:16 +00:00 (Migrated from github.com)

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.
## [Codecov](https://app.codecov.io/gh/juaml/junifer/pull/462?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=juaml) Report :white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 91.66%. Comparing base ([`151631c`](https://app.codecov.io/gh/juaml/junifer/commit/151631cf797a63827b44e16e1dada15744cdd641?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=juaml)) to head ([`afdfdde`](https://app.codecov.io/gh/juaml/junifer/commit/afdfdde4bcfa281289b7aad48e424690e6e93a41?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=juaml)). <details><summary>Additional details and impacted files</summary> [![Impacted file tree graph](https://app.codecov.io/gh/juaml/junifer/pull/462/graphs/tree.svg?width=650&height=150&src=pr&token=5H21JuZXMw&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=juaml)](https://app.codecov.io/gh/juaml/junifer/pull/462?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=juaml) ```diff @@ 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](https://app.codecov.io/gh/juaml/junifer/pull/462/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=juaml) | Coverage Δ | | |---|---|---| | [docs](https://app.codecov.io/gh/juaml/junifer/pull/462/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=juaml) | `100.00% <ø> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=juaml#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files with missing lines](https://app.codecov.io/gh/juaml/junifer/pull/462?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=juaml) | Coverage Δ | | |---|---|---| | [junifer/preprocess/warping/\_ants\_warper.py](https://app.codecov.io/gh/juaml/junifer/pull/462?src=pr&el=tree&filepath=junifer%2Fpreprocess%2Fwarping%2F_ants_warper.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=juaml#diff-anVuaWZlci9wcmVwcm9jZXNzL3dhcnBpbmcvX2FudHNfd2FycGVyLnB5) | `96.15% <ø> (-0.52%)` | :arrow_down: | | [junifer/preprocess/warping/\_fsl\_warper.py](https://app.codecov.io/gh/juaml/junifer/pull/462?src=pr&el=tree&filepath=junifer%2Fpreprocess%2Fwarping%2F_fsl_warper.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=juaml#diff-anVuaWZlci9wcmVwcm9jZXNzL3dhcnBpbmcvX2ZzbF93YXJwZXIucHk=) | `100.00% <ø> (ø)` | | | [junifer/preprocess/warping/space\_warper.py](https://app.codecov.io/gh/juaml/junifer/pull/462?src=pr&el=tree&filepath=junifer%2Fpreprocess%2Fwarping%2Fspace_warper.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=juaml#diff-anVuaWZlci9wcmVwcm9jZXNzL3dhcnBpbmcvc3BhY2Vfd2FycGVyLnB5) | `93.33% <ø> (-0.79%)` | :arrow_down: | </details> <details><summary> :rocket: New features to boost your workflow: </summary> - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems. </details>
synchon commented 2025-09-19 14:35:19 +00:00 (Migrated from github.com)

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

@fraimondo Your example now works with the latest commit. Would be great if you could try that for UKB.
synchon commented 2025-09-23 13:51:36 +00:00 (Migrated from github.com)

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

Checked ANTs warping with AOMIC ID1000 and FSL warping with UKB. Should be good to go.
fraimondo (Migrated from github.com) approved these changes 2025-09-24 12:32:39 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
juaml/junifer!462
No description provided.