Skip to content

Commit

Permalink
Explicitly check for -p none and --custom-confounds (#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo authored Aug 2, 2024
1 parent 14de282 commit 8f93b13
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions xcp_d/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,14 @@ def _validate_parameters(opts, build_log, parser):
"you must enable cifti processing (--file-format cifti)."
)

# Warn if the user combines custom confounds with the 'none' parameter set
if opts.params == "none" and opts.custom_confounds:
build_log.warning(
"Custom confounds were provided, but --nuisance-regressors was set to none. "
"Overriding the 'none' value and setting to 'custom'."
)
opts.params = "custom"

if error_messages:
error_message_str = "Errors detected in parameter parsing:\n\t- " + "\n\t- ".join(
error_messages
Expand Down
17 changes: 17 additions & 0 deletions xcp_d/tests/test_cli_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def base_opts():
"mode": "linc",
"file_format": "auto",
"input_type": "auto",
"params": "36P",
"high_pass": 0.01,
"low_pass": 0.1,
"bandpass_filter": True,
Expand Down Expand Up @@ -127,6 +128,22 @@ def test_validate_parameters_06(base_opts, base_parser, capsys):
assert "In order to perform surface normalization" in stderr


def test_validate_parameters_07(base_opts, base_parser, caplog, tmp_path_factory):
"""Test parser._validate_parameters custom confounds + none."""
tmpdir = tmp_path_factory.mktemp("test_validate_parameters_07")
confounds_path = Path(os.path.join(tmpdir, "confounds.tsv"))
confounds_path.touch() # create the file

opts = deepcopy(base_opts)
opts.params = "none"
opts.custom_confounds = confounds_path

opts = parser._validate_parameters(deepcopy(opts), build_log, parser=base_parser)

assert opts.params == "custom"
assert "Overriding the 'none' value and setting to 'custom'" in caplog.text


def test_validate_parameters_motion_filtering(base_opts, base_parser, caplog, capsys):
"""Test parser._validate_parameters."""
opts = deepcopy(base_opts)
Expand Down

0 comments on commit 8f93b13

Please sign in to comment.