Skip to content

Conversation

@shnizzedy
Copy link
Member

@shnizzedy shnizzedy commented Jun 26, 2025

Fixes

Fixes #2248 by @shnizzedy
Fixes #2257 by @shnizzedy
Fixes #2258 by @shnizzedy
Related to #2225 by @shnizzedy
Related to #2215 by @birajstha

Description

If space-bold_desc-brain_mask is missing when needed for nuisance generation, create it by transforming space-template_desc-bold_mask or space-template_desc-brain_mask to native BOLD space.

Technical details

brain_mask = (
strat_pool.node_data("space-bold_desc-brain_mask")
if strat_pool.check_rpool("space-bold_desc-brain_mask")
else NodeData()
)
if space == "T1w":
prefixes[0] = ""
if strat_pool.check_rpool("from-template_to-T1w_mode-image_desc-linear_xfm"):
reg_tool = strat_pool.reg_tool(
"from-template_to-T1w_mode-image_desc-linear_xfm"
)
if brain_mask.node is NotImplemented:
if reg_tool and strat_pool.check_rpool(
["space-template_desc-bold_mask", "space-template_desc-brain_mask"]
):
outputs["space-bold_desc-brain_mask"] = (
transform_bold_mask_to_native(
wf, strat_pool, cfg, pipe_num, reg_tool
)
)
brain_mask.node, brain_mask.out = outputs[
"space-bold_desc-brain_mask"
]
def transform_bold_mask_to_native(
wf: Workflow,
strat_pool: ResourcePool,
cfg: Configuration,
pipe_num: int,
reg_tool: Literal["ants", "fsl"],
) -> tuple[Workflow, str]:
"""Transform a template-space BOLD mask to native space."""
num_cpus = cast(
int, cfg["pipeline_setup", "system_config", "max_cores_per_participant"]
)
num_ants_cores = cast(
int, cfg["pipeline_setup", "system_config", "num_ants_threads"]
)
apply_xfm = apply_transform(
f"xfm_from-template_to-bold_mask_{pipe_num}",
reg_tool,
time_series=True,
num_cpus=num_cpus,
num_ants_cores=num_ants_cores,
)
apply_xfm.inputs.inputspec.interpolation = cfg[
"registration_workflows",
"functional_registration",
"func_registration_to_template",
f"{'ANTs' if reg_tool == 'ants' else 'FNIRT'}_pipelines",
"interpolation",
]
sbref = strat_pool.node_data("sbref")
bold_mask = strat_pool.node_data(
["space-template_desc-bold_mask", "space-template_desc-brain_mask"]
)
xfm = strat_pool.node_data("from-template_to-bold_mode-image_xfm")
wf.connect(
[
(bold_mask.node, apply_xfm, [(bold_mask.out, "inputspec.input_image")]),
(sbref.node, apply_xfm, [(sbref.out, "inputspec.reference")]),
(xfm.node, apply_xfm, [(xfm.out, "inputspec.transform")]),
]
)
return apply_xfm, "outputspec.output_image"

Tests

Adds an abcd-options smoke test (just one human subject) to the unit test suite:

@pytest.mark.parametrize("preconfig", ["abcd-options"])
def test_config(
caplog: pytest.LogCaptureFixture, preconfig: str, tmp_path: Path
) -> None:
"""Run 'test_config' analysis level."""
caplog.set_level(INFO)
data_config_file = tmp_path / "data_config.yaml"
with data_config_file.open("w") as _f:
yaml.dump(
[
{
"anat": "s3://fcp-indi/data/Projects/ADHD200/RawDataBIDS/KKI/sub-1019436/ses-1/anat/sub-1019436_ses-1_run-1_T1w.nii.gz",
"func": {
"rest_acq-1_run-1": {
"scan": "s3://fcp-indi/data/Projects/ADHD200/RawDataBIDS/KKI/sub-1019436/ses-1/func/sub-1019436_ses-1_task-rest_acq-1_run-1_bold.nii.gz",
"scan_parameters": "s3://fcp-indi/data/Projects/ADHD200/RawDataBIDS/KKI/task-rest_acq-1_bold.json",
}
},
"site": "KKI",
"subject_id": "1019436",
"unique_id": "1",
}
],
_f,
)
# output in tmp_path/outputs
pipeline = Preconfiguration(preconfig)
output_dir = tmp_path / "outputs"
output_dir.mkdir(parents=True, exist_ok=True)
pipeline["pipeline_setup", "log_directory", "path"] = str(output_dir / "log")
pipeline["pipeline_setup", "output_directory", "path"] = str(output_dir / "out")
pipeline["pipeline_setup", "working_directory", "path"] = str(
output_dir / "working"
)
pipeline_file = tmp_path / "pipe_config.yaml"
with pipeline_file.open("w") as _f:
_f.write(create_yaml_from_template(pipeline, preconfig, preconfig, True))
plugin = "MultiProc"
plugin_args: dict[str, int | bool | Callable] = {
"n_procs": 2,
"memory_gb": 10,
"raise_insufficient": True,
"status_callback": log_nodes_cb,
}
tracking = False
exitcode = run(
str(data_config_file),
str(pipeline_file),
plugin=plugin,
plugin_args=plugin_args,
tracking=tracking,
test_config=True,
)
if exitcode != 0:
records = list(caplog.records)
msg: str
msg = str(records[-1])
if hasattr(records[-1], "exc_info"):
exc_info = records[-1].exc_info
if (
exc_info
and exc_info[0]
and exc_info[1]
and hasattr(exc_info[1], "args")
):
msg = exc_info[1].args[0]
raise exc_info[0](exc_info[1])
raise AssertionError(msg)

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.

@shnizzedy shnizzedy changed the title Abcd space bold desc brain mask 🐛 Create missing space-bold_desc-brain_mask on-demand Jun 26, 2025
@shnizzedy shnizzedy self-assigned this Jun 26, 2025
@shnizzedy shnizzedy added bug develop issue on `develop` branch labels Jun 26, 2025
@shnizzedy shnizzedy moved this to 🏗 In progress in C-PAC Development Jun 26, 2025
@shnizzedy shnizzedy added this to the 1.8.8 release milestone Jun 26, 2025
@shnizzedy shnizzedy linked an issue Jun 26, 2025 that may be closed by this pull request
2 tasks
@codecov
Copy link

codecov bot commented Jun 26, 2025

Codecov Report

Attention: Patch coverage is 82.32323% with 35 lines in your changes missing coverage. Please review.

Project coverage is 33.8%. Comparing base (8596775) to head (6e501cc).
Report is 53 commits behind head on develop.

Files with missing lines Patch % Lines
CPAC/pipeline/test/test_connect_pipeline.py 71.1% 12 Missing and 1 partial ⚠️
CPAC/utils/monitoring/monitoring.py 69.0% 5 Missing and 4 partials ⚠️
CPAC/utils/datasource.py 53.8% 4 Missing and 2 partials ⚠️
CPAC/func_preproc/func_preproc.py 62.5% 2 Missing and 1 partial ⚠️
CPAC/utils/test_resources.py 83.3% 2 Missing ⚠️
...PAC/distortion_correction/distortion_correction.py 50.0% 1 Missing ⚠️
CPAC/nuisance/nuisance.py 92.3% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           develop   #2256     +/-   ##
=========================================
+ Coverage     28.4%   33.8%   +5.4%     
=========================================
  Files          230     232      +2     
  Lines        26052   26300    +248     
  Branches      4092    4130     +38     
=========================================
+ Hits          7397    8886   +1489     
+ Misses       18024   16687   -1337     
- Partials       631     727     +96     
Files with missing lines Coverage Δ
CPAC/nuisance/utils/xfm.py 100.0% <100.0%> (ø)
CPAC/pipeline/cpac_runner.py 25.0% <100.0%> (+1.7%) ⬆️
CPAC/registration/registration.py 43.6% <100.0%> (+23.3%) ⬆️
CPAC/utils/monitoring/draw_gantt_chart.py 10.2% <ø> (ø)
CPAC/utils/tests/test_datasource.py 100.0% <100.0%> (+74.2%) ⬆️
...PAC/distortion_correction/distortion_correction.py 7.5% <50.0%> (+<0.1%) ⬆️
CPAC/nuisance/nuisance.py 25.9% <92.3%> (+1.8%) ⬆️
CPAC/utils/test_resources.py 69.7% <83.3%> (+64.4%) ⬆️
CPAC/func_preproc/func_preproc.py 25.9% <62.5%> (+15.5%) ⬆️
CPAC/utils/datasource.py 32.7% <53.8%> (+5.2%) ⬆️
... and 2 more

... and 15 files with indirect coverage changes

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

@shnizzedy shnizzedy requested a review from a team June 30, 2025 14:09
@shnizzedy shnizzedy moved this from 🏗 In progress to 👀 In review in C-PAC Development Jun 30, 2025
@shnizzedy shnizzedy marked this pull request as ready for review June 30, 2025 17:49
Copy link
Collaborator

@sgiavasis sgiavasis left a comment

Choose a reason for hiding this comment

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

I like the handling of the outputs, and that new pipeline connection test 👍

@sgiavasis sgiavasis merged commit c6abb3e into develop Jul 28, 2025
65 of 68 checks passed
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in C-PAC Development Jul 28, 2025
@shnizzedy shnizzedy deleted the abcd-space-bold_desc-brain_mask branch July 29, 2025 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: ✅ Done

3 participants