Skip to content

Comments

♻️ refactoring anatomical_resampled bold masking#2215

Merged
sgiavasis merged 16 commits intodevelopfrom
fix_chipped_mask
Jun 13, 2025
Merged

♻️ refactoring anatomical_resampled bold masking#2215
sgiavasis merged 16 commits intodevelopfrom
fix_chipped_mask

Conversation

@birajstha
Copy link
Contributor

@birajstha birajstha commented Apr 16, 2025

Fixes

Fixes #2209 by @birajstha
Related to #2047 @sgiavasis

Description

This PR refactors the bold_mask_anatomical_resampled nodeblock used in functional masking, aligning its functionality more closely with its original intent of producing template-space BOLD masks only, and removes its generalization for creating native-space masks, which was causing cropped mask outputs.

Technical details

  • Removed support for native-space masking via Anatomical_Resampled, including:
    • The back-transformation of the mask to native space.
    • Associated nodes and connections performing that step.
  • Removed Anatomical_Resampled from the func_masking options in pipeline configs to avoid misuse.
  • Created a new dedicated template_space_bold_masking section, where Anatomical_Resampled is now the only available method tobetter reflect its usage in the ABCD pipeline.
  • Cleaned up unused or misleading components within the nodeblock.
  • Updated the abcd_options preconfig to continue using Anatomical_Resampled for template-space masking only.

Tests

Run CPAC with abcd-options preconfig.

Screenshots

After the fix
image

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the develop branch of the repository.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I updated the changelog.
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@birajstha birajstha marked this pull request as draft April 16, 2025 16:38
@birajstha birajstha linked an issue Apr 16, 2025 that may be closed by this pull request
15 tasks
@birajstha birajstha marked this pull request as ready for review April 25, 2025 19:20
@birajstha birajstha requested review from a team and Copilot April 25, 2025 19:21

This comment was marked as off-topic.

@FCP-INDI FCP-INDI deleted a comment from Copilot AI Apr 25, 2025
@birajstha birajstha requested a review from Copilot April 25, 2025 19:43

This comment was marked as duplicate.

Comment on lines +97 to +104
else:
automask = pe.Node(interface=afni.Automask(), name=f"automask_bold_{pipe_num}")
automask.inputs.dilate = 1
automask.inputs.outputtype = "NIFTI_GZ"

node, out = strat_pool.get_data("desc-preproc_bold")
wf.connect(node, out, automask, "in_file")
wf.connect(automask, "out_file", gen_motion_stats, "inputspec.mask")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, do we want to put automask.out_file in the resource pool as "space-bold_desc-brain_mask" or do we not care to keep it beyond this one connection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this one.
As far as I can tell, its not needed in the abcd-options pipeline as the bold is masked in template space.
I guess it won't hurt to push that into the resource pool anyway. I can check with @sgiavasis in the next meeting.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would lean towards no, but, actually-
Does HCP-ABCD do anything with the BOLD in native space? If so, how do they handle it?
If not - the answer is probably that they just do all of this in template space.

I recommend reviewing their pipeline choices first.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm getting at - it may be that we just need to make that jump to more flexible "native vs. template space" toggles for basically any single nodeblock that can interchangeably be done in any space.

The answer is probably "calculate motion stats in template space after masking in template space."
As always, my mandatory mention: the new engine could do this 😅

},
"template_space_func_masking": {
"run": bool1_1,
"using": [In({"Anatomical_Resampled"})],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why even have using if there's only one option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an attempt to keep it open if we have another method in future, that we may add here.
But, I am open to just make it for "Anatomical_Resampled".

Comment on lines 1336 to 1341
template_space_func_masking:
run: Off
# Anatomical_Resampled: Resample anatomical brain mask in standard space to get BOLD brain mask in standard space. Adapted from DCAN Lab's BOLD mask method from the ABCD pipeline. ("Create fMRI resolution standard space files for T1w image, wmparc, and brain mask […] don't use FLIRT to do spline interpolation with -applyisoxfm for the 2mm and 1mm cases because it doesn't know the peculiarities of the MNI template FOVs")
using: [Anatomical_Resampled]

apply_func_mask_in_template_space: Off
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I (think I) get "run" is generating the mask and "apply_func_mask_in_template_space" is applying the generated mask, but I think we could be clearer if we add some comments in the default and blank configs and/or naming the keys something like "generate" and "apply"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you menan. I think we could remove the switch apply_func_mask_in_template_space: Off, so that run will both generate and apply the mask. Its less confusing that way?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't want / care to allow for generating-but-not-applying, then yeah, I think just one switch makes sense. Otherwise, I just think

  1. it's not clear that run generates but doesn't apply, and
  2. apply_func_mask_in_template_space is unnecessarily long.

But those are just my opinions. I think with some comments saying what the options do, these keys can work fine.

Copy link
Contributor Author

@birajstha birajstha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot changes

@birajstha birajstha marked this pull request as draft April 29, 2025 16:18
@birajstha birajstha marked this pull request as ready for review April 29, 2025 17:10
@sgiavasis sgiavasis merged commit e464b49 into develop Jun 13, 2025
29 checks passed
@codecov
Copy link

codecov bot commented Jun 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.0%. Comparing base (b42fcd6) to head (eeb8915).
Report is 18 commits behind head on develop.

Additional details and impacted files
@@            Coverage Diff             @@
##           develop   #2215      +/-   ##
==========================================
- Coverage     28.2%       0   -28.2%     
==========================================
  Files          230       0     -230     
  Lines        25890       0   -25890     
  Branches      4069       0    -4069     
==========================================
- Hits          7294       0    -7294     
+ Misses       17969       0   -17969     
+ Partials       627       0     -627     

see 230 files with indirect coverage changes

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

🐛 Resampled mask chipped off

3 participants