Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ffrprep/ffrprep_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1561,8 +1561,10 @@ def get_parser():
help=(
"Reference channel(s) for re-referencing. Provide space-separated "
"channel names (e.g. --ref_channels M1 M2). Use 'average' for "
"average reference. Comma-separated single-argument styles are "
"also accepted for backward compatibility (e.g. 'M1,M2')."
"average reference, or 'skip' if the data is already referenced "
"and should not be re-referenced. Comma-separated single-argument "
"styles are also accepted for backward compatibility (e.g. "
"'M1,M2')."
),
nargs="+",
type=str,
Expand Down Expand Up @@ -1813,6 +1815,10 @@ def parse_ref_channels(ref_str):
# Already a sequence; ensure items are stripped and handle
# comma-separated tokens inside any element for backward
# compatibility (e.g. ['M1,M2'] -> ['M1','M2']).
if len(ref_str) == 1 and isinstance(ref_str[0], str) and ref_str[0].strip().lower() == "skip":
return [] # Data is already referenced; do not re-reference
if len(ref_str) == 1 and isinstance(ref_str[0], str) and ref_str[0].strip().lower() == "average":
return None # Average reference
out = []
for item in ref_str:
if isinstance(item, str) and "," in item:
Expand All @@ -1824,6 +1830,8 @@ def parse_ref_channels(ref_str):
s = str(ref_str)
if s.lower() == "average":
return None # Average reference
if s.lower() == "skip":
return [] # Data is already referenced; do not re-reference
if "," in s:
# Split and strip whitespace around channel names
return [c.strip() for c in s.split(",") if c.strip()]
Expand Down
3 changes: 2 additions & 1 deletion ffrprep/preproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ def reference_data(eeg_data=None, ref_channels=None):
Channels to be used as reference. If more than one channel
in list, the average of the channels in `ref_channels` will
be used as the reference. If `None`, all channels will be
averaged as the reference.
averaged as the reference. If an empty list, the data is
marked as already referenced and is not modified.
Default = None.

Returns
Expand Down
21 changes: 21 additions & 0 deletions ffrprep/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ def test_parse_ref_channels_average():
assert parse_ref_channels("Average") is None


def test_parse_ref_channels_average_from_argparse_list():
"""--ref_channels uses nargs='+', so real CLI usage always passes a
list (e.g. ['average']) rather than a bare string."""
assert parse_ref_channels(["average"]) is None
assert parse_ref_channels(["AVERAGE"]) is None


def test_parse_ref_channels_single():
assert parse_ref_channels("Cz") == "Cz"
assert parse_ref_channels("TP9") == "TP9"
Expand All @@ -235,6 +242,20 @@ def test_parse_ref_channels_empty_string():
assert parse_ref_channels("") is None


def test_parse_ref_channels_skip():
"""'skip' normalizes to [] (data already referenced; do not modify)."""
assert parse_ref_channels("skip") == []
assert parse_ref_channels("SKIP") == []
assert parse_ref_channels("Skip") == []


def test_parse_ref_channels_skip_from_argparse_list():
"""--ref_channels uses nargs='+', so real CLI usage always passes a
list (e.g. ['skip']) rather than a bare string."""
assert parse_ref_channels(["skip"]) == []
assert parse_ref_channels(["SKIP"]) == []


# ---------------------------------------------------------------------------
# run_ffrprep — mocked end-to-end behavior
# ---------------------------------------------------------------------------
Expand Down
Loading