Skip to content

Commit 7921fd4

Browse files
committed
1 parent efd37cb commit 7921fd4

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

src/probeinterface/neuropixels_tools.py

+29-15
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@
483483
None: "0",
484484
# NP1.0
485485
"PRB_1_4_0480_1": "0",
486-
"PRB_1_4_0480_1_C": "0",
486+
"PRB_1_4_0480_1_C": "0", # This is the metal cap version
487487
"PRB_1_2_0480_2": "0",
488488
"NP1010": "0",
489489
# NHP probes lin
@@ -1090,36 +1090,51 @@ def read_openephys(
10901090
raise NotImplementedError(f"Probe part number {probe_part_number} is not supported yet")
10911091
ptype = probe_part_number_to_probe_type[probe_part_number]
10921092

1093+
probe_dict = npx_descriptions[ptype]
1094+
shank_pitch = probe_dict["shank_pitch"]
1095+
10931096
if fix_x_position_for_oe_5 and oe_version < parse("0.6.0") and shank_ids is not None:
1094-
positions[:, 1] = positions[:, 1] - npx_descriptions[ptype]["shank_pitch"] * shank_ids
1097+
positions[:, 1] = positions[:, 1] - shank_pitch * shank_ids
10951098

10961099
# x offset so that the first column is at 0x
10971100
offset = np.min(positions[:, 0])
10981101
# if some shanks are not used, we need to adjust the offset
10991102
if shank_ids is not None:
1100-
offset -= np.min(shank_ids) * npx_descriptions[ptype]["shank_pitch"]
1103+
offset -= np.min(shank_ids) * shank_pitch
11011104
positions[:, 0] -= offset
11021105

11031106
contact_ids = []
1107+
y_pitch = probe_dict["y_pitch"] # Vertical spacing between the centers of adjacent contacts
1108+
x_pitch = probe_dict["x_pitch"] # Horizontal spacing between the centers of contacts within the same row
1109+
number_of_columns = probe_dict["ncol"]
1110+
probe_stagger = probe_dict["stagger"]
1111+
shank_number = probe_dict["shank_number"]
1112+
11041113
for i, pos in enumerate(positions):
1114+
# Do not calculate contact ids if the probe type is not known
11051115
if ptype is None:
11061116
contact_ids = None
11071117
break
11081118

1109-
stagger = np.mod(pos[1] / npx_descriptions[ptype]["y_pitch"] + 1, 2) * npx_descriptions[ptype]["stagger"]
1110-
shank_id = shank_ids[i] if npx_descriptions[ptype]["shank_number"] > 1 else 0
1119+
x_pos = pos[0]
1120+
y_pos = pos[1]
1121+
1122+
# Adds a shift to rows in the staggered configuration
1123+
is_row_staggered = np.mod(y_pos / y_pitch + 1, 2) == 1
1124+
row_stagger = probe_stagger if is_row_staggered else 0
1125+
1126+
# Map the positions to the contacts ids
1127+
shank_id = shank_ids[i] if shank_number > 1 else 0
11111128

11121129
contact_id = int(
1113-
(pos[0] - stagger - npx_descriptions[ptype]["shank_pitch"] * shank_id)
1114-
/ npx_descriptions[ptype]["x_pitch"]
1115-
+ npx_descriptions[ptype]["ncols_per_shank"] * pos[1] / npx_descriptions[ptype]["y_pitch"]
1130+
(x_pos - row_stagger - shank_pitch * shank_id) / x_pitch + number_of_columns * y_pos / y_pitch
11161131
)
1117-
if npx_descriptions[ptype]["shank_number"] > 1:
1132+
if shank_number > 1:
11181133
contact_ids.append(f"s{shank_id}e{contact_id}")
11191134
else:
11201135
contact_ids.append(f"e{contact_id}")
11211136

1122-
model_name = npx_descriptions[ptype]["model_name"] if ptype is not None else "Unknown"
1137+
model_name = probe_dict["model_name"] if ptype is not None else "Unknown"
11231138
np_probe_dict = {
11241139
"model_name": model_name,
11251140
"shank_ids": shank_ids,
@@ -1230,10 +1245,9 @@ def read_openephys(
12301245

12311246
ptype = np_probe_info["ptype"]
12321247
if ptype in npx_descriptions:
1233-
contact_width = npx_descriptions[ptype]["contact_width"]
1234-
shank_pitch = npx_descriptions[ptype]["shank_pitch"]
1235-
num_shanks = npx_descriptions[ptype]["shank_number"]
1236-
contour_description = npx_descriptions[ptype]["contour_description"]
1248+
contact_width = probe_dict["contact_width"]
1249+
num_shanks = probe_dict["shank_number"]
1250+
contour_description = probe_dict["contour_description"]
12371251
else:
12381252
contact_width = 12
12391253
shank_pitch = 250
@@ -1278,7 +1292,7 @@ def read_openephys(
12781292
probe.set_contact_ids(contact_ids)
12791293

12801294
polygon = polygon_contour_description[contour_description]
1281-
contour_shift = np.array(npx_descriptions[ptype]["contour_shift"])
1295+
contour_shift = np.array(probe_dict["contour_shift"])
12821296
if shank_ids is None:
12831297
contour = polygon
12841298
else:

0 commit comments

Comments
 (0)