From 5ce6459d636317c0553c1cfd4945a9d72a977034 Mon Sep 17 00:00:00 2001 From: Kevin Sitek Date: Fri, 11 Sep 2026 15:38:20 -0500 Subject: [PATCH 1/2] Added option to skip referencing if dataset already referenced --- ffrprep/ffrprep_cli.py | 10 ++++++++-- ffrprep/preproc.py | 3 ++- ffrprep/tests/test_cli.py | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ffrprep/ffrprep_cli.py b/ffrprep/ffrprep_cli.py index b9bd3db..1ce50c5 100644 --- a/ffrprep/ffrprep_cli.py +++ b/ffrprep/ffrprep_cli.py @@ -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, @@ -1813,6 +1815,8 @@ 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 out = [] for item in ref_str: if isinstance(item, str) and "," in item: @@ -1824,6 +1828,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()] diff --git a/ffrprep/preproc.py b/ffrprep/preproc.py index 9b521df..65bc329 100644 --- a/ffrprep/preproc.py +++ b/ffrprep/preproc.py @@ -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 diff --git a/ffrprep/tests/test_cli.py b/ffrprep/tests/test_cli.py index 892ca57..1977ad4 100644 --- a/ffrprep/tests/test_cli.py +++ b/ffrprep/tests/test_cli.py @@ -235,6 +235,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 # --------------------------------------------------------------------------- From f2d3592e2cf81ec6c9ed0a2b065223cb669cfeb1 Mon Sep 17 00:00:00 2001 From: Kevin Sitek Date: Fri, 11 Sep 2026 15:42:38 -0500 Subject: [PATCH 2/2] Fixed 'average' referencing which turned into literal string inside list --- ffrprep/ffrprep_cli.py | 2 ++ ffrprep/tests/test_cli.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/ffrprep/ffrprep_cli.py b/ffrprep/ffrprep_cli.py index 1ce50c5..c64c2cb 100644 --- a/ffrprep/ffrprep_cli.py +++ b/ffrprep/ffrprep_cli.py @@ -1817,6 +1817,8 @@ def parse_ref_channels(ref_str): # 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: diff --git a/ffrprep/tests/test_cli.py b/ffrprep/tests/test_cli.py index 1977ad4..abec3d3 100644 --- a/ffrprep/tests/test_cli.py +++ b/ffrprep/tests/test_cli.py @@ -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"