Skip to content

Commit 9b18298

Browse files
committed
testing
1 parent be23538 commit 9b18298

7 files changed

Lines changed: 107 additions & 24 deletions

File tree

src/rbc/cli/all.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class AllArgs(BaseArgs):
5151
def validate_namespace(cls, ns: argparse.Namespace) -> AllArgs:
5252
"""Validate all-workflow arguments."""
5353
_validate_task(ns.task)
54+
if ns.smooth is not None:
55+
_validate_positive(ns.smooth, "smooth")
5456
_validate_positive(ns.start_tr, "Start TR")
5557
_validate_positive(ns.tr, "TR")
5658
atlas_files = _resolve_atlas_args(ns.atlas)

src/rbc/cli/functional.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class FunctionalArgs(BaseArgs):
4545
def validate_namespace(cls, ns: argparse.Namespace) -> FunctionalArgs:
4646
"""Validation of functional workflow specific arguments to NamedTuple."""
4747
_validate_task(ns.task)
48+
if ns.smooth is not None:
49+
_validate_positive(ns.smooth, "smooth")
4850
_validate_positive(ns.tr, "TR")
4951
return cls(
5052
**BaseArgs.validate_namespace(ns).__dict__,

src/rbc/cli/metrics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class MetricsArgs(BaseArgs):
5959
def validate_namespace(cls, ns: argparse.Namespace) -> MetricsArgs:
6060
"""Validate metrics-specific arguments."""
6161
_validate_task(ns.task)
62+
if ns.smooth is not None:
63+
_validate_positive(ns.smooth, "smooth")
6264
_validate_positive(ns.tr, "TR")
6365
atlas_files = _resolve_atlas_args(ns.atlas)
6466
return cls(

tests/unit/bids/test_exports.py

Lines changed: 83 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ def _make_func_outputs(w: Path, regressors: list[str]) -> FunctionalOutputs:
7373
template_bold=_dummy(w, "template_bold.nii.gz"),
7474
regressed_bold={r: _dummy(w, f"regressed_{r}.nii.gz") for r in regressors},
7575
cleaned_bold={r: _dummy(w, f"cleaned_{r}.nii.gz") for r in regressors},
76-
cleaned_bold_smooth={
77-
r: _dummy(w, f"cleaned_{r}_smooth.nii.gz") for r in regressors
78-
},
76+
cleaned_bold_smooth=None,
7977
regressor_file={r: _dummy(w, f"regressors_{r}.1D") for r in regressors},
8078
template_brain_mask=_dummy(w, "template_mask.nii.gz"),
8179
)
@@ -222,6 +220,31 @@ def test_file_count_two_regressors(
222220
saved = list(pipe_ctx.output_dir.rglob("*.*"))
223221
assert len(saved) == 16
224222

223+
def test_bold_smooth_not_exported_if_none(
224+
self, func_bids: Bids, workdir: Path, pipe_ctx: RunContext
225+
) -> None:
226+
"""No smoothed BOLD files are exported when cleaned_bold_smooth is None."""
227+
outputs = _make_func_outputs(workdir, ["36-parameter"])
228+
export_functional(func_bids, outputs, regressors=["36-parameter"])
229+
saved = [p.name for p in pipe_ctx.output_dir.rglob("*.nii.gz")]
230+
assert not any("desc-sm" in name for name in saved)
231+
232+
def test_cleaned_bold_smooth_exported_with_correct_desc(
233+
self, func_bids: Bids, workdir: Path, pipe_ctx: RunContext
234+
) -> None:
235+
"""Smoothed BOLD is exported with correct fwhm label."""
236+
smooth_outputs = _make_func_outputs(workdir, ["36-parameter"])._replace(
237+
cleaned_bold_smooth={
238+
"36-parameter": _dummy(workdir, "cleaned_smooth.nii.gz")
239+
}
240+
)
241+
export_functional(
242+
func_bids, smooth_outputs, regressors=["36-parameter"], smooth=8.0
243+
)
244+
saved = [p.name for p in pipe_ctx.output_dir.rglob("*.nii.gz")]
245+
sm_files = [n for n in saved if "desc-sm8preproc" in n]
246+
assert len(sm_files) == 1
247+
225248

226249
# ---------------------------------------------------------------------------
227250
# Metrics exports
@@ -238,7 +261,11 @@ def test_sanitizes_atlas_labels(
238261
mni = func_bids.derive(space="MNI152NLin6Asym")
239262
outputs = _make_metrics_outputs(workdir, ["schaefer_200"])
240263
export_metrics(
241-
mni, outputs, regressor="36-parameter", atlases=["schaefer_200"], smooth=6.0
264+
mni,
265+
outputs,
266+
regressor="36-parameter",
267+
atlases=["schaefer_200"],
268+
smooth=None,
242269
)
243270
atlas_files = [
244271
p.name for p in pipe_ctx.output_dir.rglob("*.*") if "atlas-" in p.name
@@ -255,7 +282,7 @@ def test_sanitizes_regressor_labels(
255282
mni = func_bids.derive(space="MNI152NLin6Asym")
256283
outputs = _make_metrics_outputs(workdir, ["aal"])
257284
export_metrics(
258-
mni, outputs, regressor="36-parameter", atlases=["aal"], smooth=6.0
285+
mni, outputs, regressor="36-parameter", atlases=["aal"], smooth=None
259286
)
260287
all_names = [p.name for p in pipe_ctx.output_dir.rglob("*.*")]
261288
reg_files = [n for n in all_names if "reg-" in n]
@@ -270,7 +297,7 @@ def test_file_count_single_atlas(
270297
mni = func_bids.derive(space="MNI152NLin6Asym")
271298
outputs = _make_metrics_outputs(workdir, ["schaefer_200"])
272299
export_metrics(
273-
mni, outputs, regressor="aCompCor", atlases=["schaefer_200"], smooth=6.0
300+
mni, outputs, regressor="aCompCor", atlases=["schaefer_200"], smooth=None
274301
)
275302
saved = list(pipe_ctx.output_dir.rglob("*.*"))
276303
assert len(saved) == 8
@@ -282,10 +309,59 @@ def test_file_count_multiple_atlases(
282309
atlases = ["schaefer_200", "aal"]
283310
mni = func_bids.derive(space="MNI152NLin6Asym")
284311
outputs = _make_metrics_outputs(workdir, atlases)
285-
export_metrics(mni, outputs, regressor="aCompCor", atlases=atlases, smooth=6.0)
312+
export_metrics(mni, outputs, regressor="aCompCor", atlases=atlases, smooth=None)
286313
saved = list(pipe_ctx.output_dir.rglob("*.*"))
287314
assert len(saved) == 10
288315

316+
def test_file_count_single_atlas_with_smooth(
317+
self, func_bids: Bids, workdir: Path, pipe_ctx: RunContext
318+
) -> None:
319+
"""3 raw + 3 zscored + 3 smooth + 3 smooth zscored + 2 atlas files = 14."""
320+
mni = func_bids.derive(space="MNI152NLin6Asym")
321+
smooth_outputs = _make_metrics_outputs(workdir, ["schaefer_200"])._replace(
322+
alff_smooth=_dummy(workdir, "alff_sm.nii.gz"),
323+
falff_smooth=_dummy(workdir, "falff_sm.nii.gz"),
324+
reho_smooth=_dummy(workdir, "reho_sm.nii.gz"),
325+
alff_smooth_zscored=_dummy(workdir, "alff_sm_z.nii.gz"),
326+
falff_smooth_zscored=_dummy(workdir, "falff_sm_z.nii.gz"),
327+
reho_smooth_zscored=_dummy(workdir, "reho_sm_z.nii.gz"),
328+
)
329+
export_metrics(
330+
mni,
331+
smooth_outputs,
332+
regressor="aCompCor",
333+
atlases=["schaefer_200"],
334+
smooth=6.0,
335+
)
336+
saved = list(pipe_ctx.output_dir.rglob("*.*"))
337+
assert len(saved) == 14
338+
339+
def test_smooth_maps_have_correct_desc(
340+
self, func_bids: Bids, workdir: Path, pipe_ctx: RunContext
341+
) -> None:
342+
"""Smoothed maps are exported with correct fwhm labels."""
343+
mni = func_bids.derive(space="MNI152NLin6Asym")
344+
smooth_outputs = _make_metrics_outputs(workdir, ["schaefer_200"])._replace(
345+
alff_smooth=_dummy(workdir, "alff_sm.nii.gz"),
346+
falff_smooth=_dummy(workdir, "falff_sm.nii.gz"),
347+
reho_smooth=_dummy(workdir, "reho_sm.nii.gz"),
348+
alff_smooth_zscored=_dummy(workdir, "alff_sm_z.nii.gz"),
349+
falff_smooth_zscored=_dummy(workdir, "falff_sm_z.nii.gz"),
350+
reho_smooth_zscored=_dummy(workdir, "reho_sm_z.nii.gz"),
351+
)
352+
export_metrics(
353+
mni,
354+
smooth_outputs,
355+
regressor="aCompCor",
356+
atlases=["schaefer_200"],
357+
smooth=8.0,
358+
)
359+
saved = [p.name for p in pipe_ctx.output_dir.rglob("*.nii.gz")]
360+
sm_only = [n for n in saved if "desc-sm8" in n and "Zstd" not in n]
361+
sm_zstd = [n for n in saved if "desc-sm8Zstd" in n]
362+
assert len(sm_only) == 3
363+
assert len(sm_zstd) == 3
364+
289365

290366
# ---------------------------------------------------------------------------
291367
# QC exports

tests/unit/cli/test_all.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def base_args(tmp_path: Path) -> argparse.Namespace:
3030
regressor=["36-parameter"],
3131
task=None,
3232
atlas=["schaefer_200"],
33-
fwhm=6.0,
33+
smooth=None,
3434
start_tr=2,
3535
tr=None,
3636
tmp_dir=None,
@@ -64,7 +64,7 @@ def test_defaults(self, base_args: argparse.Namespace) -> None:
6464
assert args.regressor == ["36-parameter"]
6565
assert args.task is None
6666
assert "schaefer_200" in args.atlas_files
67-
assert args.smooth == 6.0
67+
assert args.smooth is None
6868
assert args.start_tr == 2
6969
assert args.participant_label == []
7070
assert args.session_label == []
@@ -184,11 +184,11 @@ def test_all_parser_atlas_choices(self) -> None:
184184
args = parser.parse_args(["all", "/input", "-o", "/output", "--atlas", "aal"])
185185
assert args.atlas == ["aal"]
186186

187-
def test_all_parser_has_fwhm(self) -> None:
188-
"""Test all subparser includes --fwhm argument."""
187+
def test_all_parser_has_smooth(self) -> None:
188+
"""Test all subparser includes --smooth argument."""
189189
parser = create_parser()
190-
args = parser.parse_args(["all", "/input", "-o", "/output", "--fwhm", "8.0"])
191-
assert args.fwhm == 8.0
190+
args = parser.parse_args(["all", "/input", "-o", "/output", "--smooth", "8.0"])
191+
assert args.smooth == 8.0
192192

193193
def test_all_parser_has_start_tr(self) -> None:
194194
"""Test all subparser includes --start-tr argument."""
@@ -203,10 +203,10 @@ def test_all_parser_task_default_none(self) -> None:
203203
assert args.task is None
204204

205205
def test_all_parser_fwhm_default(self) -> None:
206-
"""Test all subparser --fwhm defaults to 6.0."""
206+
"""Test all subparser --smooth defaults to None."""
207207
parser = create_parser()
208208
args = parser.parse_args(["all", "/input", "-o", "/output"])
209-
assert args.fwhm == 6.0
209+
assert args.smooth is None
210210

211211
def test_all_parser_start_tr_default(self) -> None:
212212
"""Test all subparser --start-tr defaults to 2."""

tests/unit/cli/test_functional.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def func_namespace(self, tmp_path: Path) -> argparse.Namespace:
3333
regressor=["36-parameter"],
3434
task=None,
3535
tr=None,
36+
smooth=None,
3637
tmp_dir=None,
3738
func_template=None,
3839
func_template_mask=None,

tests/unit/cli/test_metrics.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def base_args(tmp_path: Path) -> argparse.Namespace:
2929
session_label=[],
3030
task=None,
3131
atlas=["schaefer_200"],
32-
fwhm=6.0,
32+
smooth=None,
3333
regressor=["36-parameter"],
3434
tr=None,
3535
tmp_dir=None,
@@ -55,7 +55,7 @@ def test_defaults(self, base_args: argparse.Namespace) -> None:
5555
args = MetricsArgs.validate_namespace(base_args)
5656
assert args.task is None
5757
assert "schaefer_200" in args.atlas_files
58-
assert args.smooth == 6.0
58+
assert args.smooth is None
5959
assert args.regressor == ["36-parameter"]
6060
assert args.participant_label == []
6161
assert args.session_label == []
@@ -150,13 +150,13 @@ def test_metrics_parser_atlas_choices(self) -> None:
150150
)
151151
assert args.atlas == ["aal"]
152152

153-
def test_metrics_parser_has_fwhm(self) -> None:
154-
"""Test metrics subparser includes --fwhm argument."""
153+
def test_metrics_parser_has_smooth(self) -> None:
154+
"""Test metrics subparser includes --smooth argument."""
155155
parser = create_parser()
156156
args = parser.parse_args(
157-
["metrics", "/input", "-o", "/output", "--fwhm", "8.0"]
157+
["metrics", "/input", "-o", "/output", "--smooth", "8.0"]
158158
)
159-
assert args.fwhm == 8.0
159+
assert args.smooth == 8.0
160160

161161
def test_metrics_parser_has_task(self) -> None:
162162
"""Test metrics subparser includes --task argument."""
@@ -178,11 +178,11 @@ def test_metrics_parser_task_default_none(self) -> None:
178178
args = parser.parse_args(["metrics", "/input", "-o", "/output"])
179179
assert args.task is None
180180

181-
def test_metrics_parser_fwhm_default(self) -> None:
182-
"""Test metrics subparser --fwhm defaults to 6.0."""
181+
def test_metrics_parser_smooth_default(self) -> None:
182+
"""Test metrics subparser --smooth defaults to None."""
183183
parser = create_parser()
184184
args = parser.parse_args(["metrics", "/input", "-o", "/output"])
185-
assert args.fwhm == 6.0
185+
assert args.smooth is None
186186

187187

188188
class TestResolveAtlasArgs:

0 commit comments

Comments
 (0)