Skip to content

Commit c2d2fc5

Browse files
authored
Merge branch 'main' into add_imro_tests
2 parents b86293e + c631fbb commit c2d2fc5

File tree

3 files changed

+132
-41
lines changed

3 files changed

+132
-41
lines changed

probeinterface/io.py

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -778,16 +778,7 @@ def write_csv(file, probe):
778778
"elec_ids",
779779
),
780780
},
781-
'Ultra': {
782-
"x_pitch": 6,
783-
"y_pitch": 6,
784-
"contact_width": 5,
785-
"stagger": 0.0,
786-
"shank_pitch": 0,
787-
"shank_number": 1,
788-
"ncol": 8
789-
},
790-
#
781+
# Experimental probes previous to 1.0
791782
"Phase3a": {
792783
"probe_name": "Phase3a",
793784
"x_pitch": 32,
@@ -906,6 +897,26 @@ def write_csv(file, probe):
906897
"ap_hp_filters",
907898
),
908899
},
900+
# Ultra probe
901+
1100: {
902+
"probe_name": "Ultra probe",
903+
"x_pitch": 6,
904+
"y_pitch": 6,
905+
"contact_width": 5,
906+
"stagger": 0.0,
907+
"shank_pitch": 0,
908+
"shank_number": 1,
909+
"ncol": 8,
910+
"polygon": polygon_description["default"],
911+
"fields_in_imro_table": (
912+
"channel_ids",
913+
"banks",
914+
"references",
915+
"ap_gains",
916+
"lf_gains",
917+
"ap_hp_filters",
918+
),
919+
},
909920
}
910921

911922

@@ -961,35 +972,36 @@ def _read_imro_string(imro_str: str, imDatPrb_pn: str = None) -> Probe:
961972
elif len(header) == 2:
962973
imDatPrb_type, num_contact = header
963974
else:
964-
raise ValueError(f'read_imro error, the header has a strange length: {len(header)}')
975+
raise ValueError(f'read_imro error, the header has a strange shape: {header}')
965976

966977
if imDatPrb_type in [0, None]:
967978
imDatPrb_type = probe_number_to_probe_type[imDatPrb_pn]
968979

969-
fields = npx_probe[imDatPrb_type]["fields_in_imro_table"]
980+
probe_description = npx_probe[imDatPrb_type]
981+
fields = probe_description["fields_in_imro_table"]
970982
contact_info = {k: [] for k in fields}
971983
for i, part in enumerate(parts):
972984
values = tuple(map(int, part[1:].split(' ')))
973985
for k, v in zip(fields, values):
974986
contact_info[k].append(v)
975987

976988
channel_ids = np.array(contact_info['channel_ids'])
977-
if 'elec_ids' in contact_info:
978-
elec_ids = np.array(contact_info['elec_ids'])
979-
980-
if imDatPrb_type == 0 or imDatPrb_type == 'Phase3a' or (imDatPrb_type in (1015, 1022, 1030, 1031, 1032)):
981-
# for NP1 and previous the elec_id is not in the list
989+
probe_types_without_elec_ids_in_their_imro_table = (0, 1015, 1022, 1030, 1031, 1032, "Phase3a", 1100)
990+
if imDatPrb_type in probe_types_without_elec_ids_in_their_imro_table:
982991
banks = np.array(contact_info['banks'])
983992
elec_ids = banks * 384 + channel_ids
984-
993+
else:
994+
elec_ids = np.array(contact_info['elec_ids'])
995+
985996
# compute position
986-
y_idx, x_idx = np.divmod(elec_ids, npx_probe[imDatPrb_type]["ncol"])
987-
x_pitch = npx_probe[imDatPrb_type ]["x_pitch"]
988-
y_pitch = npx_probe[imDatPrb_type ]["y_pitch"]
997+
y_idx, x_idx = np.divmod(elec_ids, probe_description["ncol"])
998+
x_pitch = probe_description["x_pitch"]
999+
y_pitch = probe_description["y_pitch"]
9891000

990-
stagger = np.mod(y_idx + 1, 2) * npx_probe[imDatPrb_type]["stagger"]
1001+
stagger = np.mod(y_idx + 1, 2) * probe_description["stagger"]
9911002
x_pos = x_idx * x_pitch + stagger
9921003
y_pos = y_idx * y_pitch
1004+
positions = np.stack((x_pos, y_pos), axis=1)
9931005

9941006
if imDatPrb_type == 24:
9951007
shank_ids = np.array(contact_info['shank_id'])
@@ -998,31 +1010,31 @@ def _read_imro_string(imro_str: str, imDatPrb_pn: str = None) -> Probe:
9981010
shank_ids = None
9991011
contact_ids = [f'e{elec_id}' for elec_id in elec_ids]
10001012

1001-
1002-
positions = np.zeros((num_contact, 2), dtype='float64')
1003-
positions[:, 0] = x_pos
1004-
positions[:, 1] = y_pos
1005-
10061013
# construct Probe object
10071014
probe = Probe(ndim=2, si_units='um')
1008-
probe.set_contacts(positions=positions, shapes='square',
1009-
shank_ids=shank_ids,
1010-
shape_params={'width': npx_probe[imDatPrb_type]["contact_width"]})
1015+
probe.set_contacts(
1016+
positions=positions,
1017+
shapes="square",
1018+
shank_ids=shank_ids,
1019+
shape_params={"width": probe_description["contact_width"]},
1020+
)
1021+
10111022
probe.set_contact_ids(contact_ids)
10121023

10131024
# Add planar contour
1014-
polygon = np.array(npx_probe[imDatPrb_type]["polygon"])
1025+
polygon = np.array(probe_description["polygon"])
10151026
contour = []
1016-
for shank_id in range(npx_probe[imDatPrb_type]["shank_number"]):
1017-
shift = [npx_probe[imDatPrb_type]["shank_pitch"] * shank_id, 0]
1027+
shank_pitch = probe_description["shank_pitch"]
1028+
for shank_id in range(probe_description["shank_number"]):
1029+
shift = [shank_pitch * shank_id, 0]
10181030
contour += list(polygon + shift)
10191031

10201032
# shift
10211033
contour = np.array(contour) - [11, 11]
10221034
probe.set_planar_contour(contour)
10231035

10241036
# this is scalar annotations
1025-
probe_name = npx_probe[imDatPrb_type]["probe_name"]
1037+
probe_name = probe_description["probe_name"]
10261038
probe.annotate(
10271039
name=probe_name,
10281040
manufacturer="IMEC",
@@ -1346,7 +1358,7 @@ def read_openephys(
13461358
ptype = 0
13471359
x_shift = -11
13481360
elif "Ultra" in pname:
1349-
ptype = "Ultra"
1361+
ptype = 1100
13501362
x_shift = -8
13511363
else: # Probe type unknown
13521364
ptype = None

0 commit comments

Comments
 (0)