Skip to content

Commit 35f4603

Browse files
authored
Merge branch 'main' into agg-backend-in-tests
2 parents 554ffb2 + 14d4cf2 commit 35f4603

11 files changed

Lines changed: 46 additions & 20 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ repos:
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
88
- repo: https://github.com/psf/black-pre-commit-mirror
9-
rev: 25.12.0
9+
rev: 26.3.1
1010
hooks:
1111
- id: black
1212
files: ^src/|^tests/
1313
- repo: https://github.com/codespell-project/codespell
1414
# Configuration for codespell is in .pre-commit-config.yaml
15-
rev: v2.4.1
15+
rev: v2.4.2
1616
hooks:
1717
- id: codespell
1818
additional_dependencies:

src/probeinterface/generator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from .probegroup import ProbeGroup
1313
from .utils import combine_probes
1414

15-
1615
_default_shape_to_params = {"circle": "radius", "square": "width", "rect": "height"}
1716

1817

src/probeinterface/neuropixels_tools.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from .probe import Probe
1919
from .utils import import_safely
2020

21-
2221
global _np_probe_features
2322
_np_probe_features = None
2423

@@ -28,7 +27,8 @@ def _load_np_probe_features():
2827
global _np_probe_features
2928
if _np_probe_features is None:
3029
probe_features_filepath = Path(__file__).absolute().parent / Path("resources/neuropixels_probe_features.json")
31-
_np_probe_features = json.load(open(probe_features_filepath, "r"))
30+
with open(probe_features_filepath, "r") as f:
31+
_np_probe_features = json.load(f)
3232
return _np_probe_features
3333

3434

@@ -92,8 +92,7 @@ def _load_np_probe_features():
9292

9393
def get_probe_length(probe_part_number: str) -> int:
9494
"""
95-
Returns the length of a given probe. We assume a length of
96-
1cm (10_000 microns) by default.
95+
Returns the length of a given probe from ProbeTable specifications.
9796
9897
Parameters
9998
----------
@@ -103,12 +102,16 @@ def get_probe_length(probe_part_number: str) -> int:
103102
Returns
104103
-------
105104
probe_length : int
106-
Length of full probe (microns)
105+
Length of full probe shank from tip to base (microns)
107106
"""
107+
np_features = _load_np_probe_features()
108+
probe_spec = np_features["neuropixels_probes"].get(probe_part_number)
108109

109-
probe_length = 10_000
110+
if probe_spec is not None and "shank_tip_to_base_um" in probe_spec:
111+
return int(probe_spec["shank_tip_to_base_um"])
110112

111-
return probe_length
113+
# Fallback for unknown probes or missing field
114+
return 10_000
112115

113116

114117
def make_mux_table_array(mux_information) -> np.array:
@@ -1218,7 +1221,6 @@ def read_openephys(
12181221
"probe": sliced_probe,
12191222
}
12201223
else:
1221-
12221224
channel_names = np.array(list(channels.attrib.keys()))
12231225
channel_ids = np.array([int(ch[2:]) for ch in channel_names])
12241226
channel_order = np.argsort(channel_ids)
@@ -1304,6 +1306,7 @@ def read_openephys(
13041306
np_probe_dict = {
13051307
"shank_ids": shank_ids,
13061308
"elec_ids": elec_ids,
1309+
"channel_names": channel_names,
13071310
"pt_metadata": pt_metadata,
13081311
"slot": slot,
13091312
"port": port,
@@ -1426,6 +1429,9 @@ def read_openephys(
14261429
pt_metadata, probe_part_number, elec_ids, shank_ids=shank_ids, mux_info=mux_info
14271430
)
14281431

1432+
if "channel_names" in np_probe_info:
1433+
probe.annotate_contacts(channel_name=np_probe_info["channel_names"])
1434+
14291435
chans_saved = get_saved_channel_indices_from_openephys_settings(settings_file, stream_name=stream_name)
14301436
if chans_saved is not None:
14311437
probe = probe.get_slice(chans_saved)

src/probeinterface/probe.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,15 @@ def set_contact_ids(self, contact_ids: np.array | list):
570570
self._contact_ids = None
571571
return
572572

573-
assert np.unique(contact_ids).size == contact_ids.size, "Contact ids have to be unique within a Probe"
574-
575573
if contact_ids.size != self.get_contact_count():
576-
ValueError(
574+
raise ValueError(
577575
f"contact_ids {contact_ids.size} do not have the same size "
578576
f"as number of contacts {self.get_contact_count()}"
579577
)
580578

579+
if np.unique(contact_ids).size != contact_ids.size:
580+
raise ValueError("contact_ids must be unique within a Probe")
581+
581582
if contact_ids.dtype.kind != "U":
582583
contact_ids = contact_ids.astype("U")
583584

src/probeinterface/testing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from probeinterface import __version__ as version
55

66
json_schema_file = Path(__file__).absolute().parent / "schema" / "probe.json.schema"
7-
schema = json.load(open(json_schema_file, "r"))
7+
with open(json_schema_file, "r") as f:
8+
schema = json.load(f)
89

910

1011
def validate_probe_dict(probe_dict):

src/probeinterface/wiring.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from __future__ import annotations
66
import numpy as np
77

8-
98
# This code will not be formatted by Black
109
# fmt: off
1110
pathways = {

tests/test_io/test_3brain.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from probeinterface.testing import validate_probe_dict
1010

11-
1211
data_path = Path(__file__).absolute().parent.parent / "data" / "3brain"
1312
brw_files = glob.glob(str(data_path / "*.brw"))
1413

tests/test_io/test_io.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import pytest
1616

17-
1817
data_path = Path(__file__).absolute().parent.parent / "data"
1918

2019

tests/test_io/test_spikegadgets.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from probeinterface.io import parse_spikegadgets_header
66
from probeinterface.testing import validate_probe_dict
77

8-
98
data_path = Path(__file__).absolute().parent.parent / "data" / "spikegadgets"
109
test_file = "SpikeGadgets_test_data_2xNpix1.0_20240318_173658_header_only.rec"
1110

tests/test_library.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
clear_cache,
1616
)
1717

18-
1918
manufacturer = "neuronexus"
2019
probe_name = "A1x32-Poly3-10mm-50-177"
2120

0 commit comments

Comments
 (0)