Skip to content

Monkeypatch create_cfm to use LPS lesion mask - #1058

Merged
mattcieslak merged 1 commit into
mainfrom
fix-lesion-orientation
Jun 11, 2026
Merged

Monkeypatch create_cfm to use LPS lesion mask#1058
mattcieslak merged 1 commit into
mainfrom
fix-lesion-orientation

Conversation

@tsalo

@tsalo tsalo commented Jun 9, 2026

Copy link
Copy Markdown
Member

Fixes #1023.

When an anatomical lesion ROI (*_label-lesion_roi) is provided, QSIPrep incorporates it into the anatomical-to-template registration as a cost-function mask. The mask was applied in the wrong orientation, so it had no effect at the lesion and instead perturbed the registration elsewhere.

The bug is in niworkflows' create_cfm(), which reorients the lesion to RAS but subtracts it from the LPS moving mask (QSIPrep forces orientation='LPS'), misaligning the voxel arrays. Because QSIPrep pins a released niworkflows, this PR ships the fix immediately as a monkeypatch; the same fix is going upstream in niworkflows (see nipreps/niworkflows#1050).

Changes

  • qsiprep/interfaces/niworkflows.py: add _create_cfm, a corrected copy of niworkflows.interfaces.norm.create_cfm that resamples the lesion into the moving mask's voxel grid (resample_from_to(..., order=0)) instead of reorienting it to RAS, and install it over niworkflows.interfaces.norm.create_cfm at import. SpatialNormalization looks the function up as a module global, so reassigning it is sufficient — no workflow changes required.
  • qsiprep/tests/test_interfaces_niworkflows.py (new): verifies the patch is installed and that a RAS lesion is excluded at the correct world location when in_file is LPS.

The patch carries a comment to remove it (plus the test_create_cfm_patch_installed test) once the niworkflows pin moves past the release containing the upstream fix.

Testing

pytest qsiprep/tests/test_interfaces_niworkflows.py — both tests pass.

@tsalo tsalo added the bug Something isn't working label Jun 9, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.17%. Comparing base (b142af8) to head (f354e01).

Files with missing lines Patch % Lines
qsiprep/interfaces/niworkflows.py 66.66% 3 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1058      +/-   ##
==========================================
+ Coverage   47.13%   47.17%   +0.04%     
==========================================
  Files          66       66              
  Lines        9836     9857      +21     
  Branches     1084     1088       +4     
==========================================
+ Hits         4636     4650      +14     
- Misses       4979     4982       +3     
- Partials      221      225       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mattcieslak
mattcieslak merged commit 039a4ec into main Jun 11, 2026
23 checks passed
@mattcieslak
mattcieslak deleted the fix-lesion-orientation branch June 11, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lesion mask not reoriented to LPS

3 participants