Skip to content

Commit dc372e3

Browse files
committed
Truncate BOLD to 25 volumes in integration test fixture
Copies ds000001 and truncates the BOLD timeseries before running the pipeline, cutting functional processing time significantly while still exercising the full code path (motion correction, nuisance regression, metrics, QC).
1 parent d0e5d03 commit dc372e3

1 file changed

Lines changed: 40 additions & 5 deletions

File tree

tests/integration/test_all.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
individual subcommands in sequence (disk round-trip), then verifies that both
55
approaches complete without errors, produce key derivative files, and yield
66
identical outputs.
7+
8+
The BOLD timeseries is truncated to a small number of volumes so that
9+
functional processing finishes in minutes rather than tens of minutes.
710
"""
811

912
from __future__ import annotations
@@ -13,18 +16,24 @@
1316
from pathlib import Path
1417
from typing import TYPE_CHECKING
1518

19+
import nibabel as nib
20+
import numpy as np
1621
import pytest
1722

1823
if TYPE_CHECKING:
1924
from collections.abc import Sequence
2025

21-
_TEST_DATASET = Path(__file__).parents[1] / "data" / "ds000001"
26+
_ORIG_DATASET = Path(__file__).parents[1] / "data" / "ds000001"
2227

2328
# Subject with no session in ds000001.
2429
_SUB = "01"
2530
_TASK = "balloonanalogrisktask"
2631
_RUN = "01"
2732

33+
# Number of BOLD volumes to keep. Must be enough for nuisance regression
34+
# (after discarding --start-tr 2) but small enough to be fast.
35+
_BOLD_VOLUMES = 25
36+
2837

2938
# ---------------------------------------------------------------------------
3039
# Helpers
@@ -73,14 +82,36 @@ def _runner(request: pytest.FixtureRequest) -> str:
7382

7483

7584
@pytest.fixture(scope="session")
76-
def all_output(tmp_path_factory: pytest.TempPathFactory, _runner: str) -> Path:
85+
def truncated_dataset(tmp_path_factory: pytest.TempPathFactory) -> Path:
86+
"""Copy ds000001 and truncate the BOLD to *_BOLD_VOLUMES* volumes."""
87+
dest = tmp_path_factory.mktemp("ds") / "ds000001"
88+
shutil.copytree(_ORIG_DATASET, dest)
89+
90+
bold = (
91+
dest
92+
/ f"sub-{_SUB}"
93+
/ "func"
94+
/ f"sub-{_SUB}_task-{_TASK}_run-{_RUN}_bold.nii.gz"
95+
)
96+
img = nib.nifti1.load(bold)
97+
data = np.asarray(img.dataobj[:, :, :, :_BOLD_VOLUMES])
98+
nib.nifti1.save(nib.Nifti1Image(data, img.affine, img.header), bold)
99+
return dest
100+
101+
102+
@pytest.fixture(scope="session")
103+
def all_output(
104+
tmp_path_factory: pytest.TempPathFactory,
105+
_runner: str,
106+
truncated_dataset: Path,
107+
) -> Path:
77108
"""Run ``rbc all`` once and return the output directory."""
78109
out = tmp_path_factory.mktemp("all") / "derivatives"
79110
out.mkdir()
80111
_run_rbc(
81112
[
82113
"all",
83-
str(_TEST_DATASET),
114+
str(truncated_dataset),
84115
"-o",
85116
str(out),
86117
"--runner",
@@ -92,13 +123,17 @@ def all_output(tmp_path_factory: pytest.TempPathFactory, _runner: str) -> Path:
92123

93124

94125
@pytest.fixture(scope="session")
95-
def sequential_output(tmp_path_factory: pytest.TempPathFactory, _runner: str) -> Path:
126+
def sequential_output(
127+
tmp_path_factory: pytest.TempPathFactory,
128+
_runner: str,
129+
truncated_dataset: Path,
130+
) -> Path:
96131
"""Run the four individual subcommands in order and return the output dir."""
97132
out = tmp_path_factory.mktemp("sequential") / "derivatives"
98133
out.mkdir()
99134

100135
runner_args = ["--runner", _runner, *_COMMON_ARGS]
101-
raw = str(_TEST_DATASET)
136+
raw = str(truncated_dataset)
102137
deriv = str(out)
103138

104139
# 1. anatomical (raw BIDS only)

0 commit comments

Comments
 (0)