Skip to content

Commit

Permalink
ADD: check if no probes found. If so, return None or raise Exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkBCCN committed Mar 29, 2024
1 parent 790bff2 commit fdf725d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/probeinterface/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ def write_imro(file: str | Path, probe: Probe):
f.write("".join(ret))


def read_spikegadgets(file: str | Path) -> ProbeGroup:
def read_spikegadgets(file: str | Path, raise_error: bool = True) -> ProbeGroup:
"""
Find active channels of the given Neuropixels probe from a SpikeGadgets .rec file.
SpikeGadgets headstages support up to three Neuropixels 1.0 probes (as of March 28, 2024),
Expand Down Expand Up @@ -1300,6 +1300,11 @@ def read_spikegadgets(file: str | Path) -> ProbeGroup:
probe_configs = [device for device in hconf if device.attrib["name"] == "NeuroPixels1"]
n_probes = len(probe_configs)

if n_probes == 0:
if raise_error:
raise Exception("No Neuropixels 1.0 probes found")
return None

# Container to store Probe objects
probe_group = ProbeGroup()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_io/test_spikegadgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_parse_meta():


def test_neuropixels_1_reader():
probe_group = read_spikegadgets(data_path / test_file)
probe_group = read_spikegadgets(data_path / test_file, raise_error=False)
assert len(probe_group.probes) == 2
for probe in probe_group.probes:
assert "1.0" in probe.model_name
Expand Down

0 comments on commit fdf725d

Please sign in to comment.