Skip to content

Commit 1f7dd02

Browse files
committed
first refactor of io
1 parent f640097 commit 1f7dd02

File tree

1 file changed

+38
-27
lines changed

1 file changed

+38
-27
lines changed

probeinterface/io.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,6 @@ def write_csv(file, probe):
723723
],
724724
}
725725

726-
# A map from probe type to geometry_parameters
727726
# A map from probe type to geometry_parameters
728727
npx_probe = {
729728
# Neuropixels 1.0
@@ -778,16 +777,7 @@ def write_csv(file, probe):
778777
"elec_ids",
779778
),
780779
},
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-
#
780+
# Experimental probes previous to 1.0
791781
"Phase3a": {
792782
"probe_name": "Phase3a",
793783
"x_pitch": 32,
@@ -906,6 +896,26 @@ def write_csv(file, probe):
906896
"ap_hp_filters",
907897
),
908898
},
899+
# Ultra probe
900+
1100: {
901+
"probe_name": "Ultra probe",
902+
"x_pitch": 6,
903+
"y_pitch": 6,
904+
"contact_width": 5,
905+
"stagger": 0.0,
906+
"shank_pitch": 0,
907+
"shank_number": 1,
908+
"ncol": 8,
909+
"polygon": polygon_description["default"],
910+
"fields_in_imro_table": (
911+
"channel_ids",
912+
"banks",
913+
"references",
914+
"ap_gains",
915+
"lf_gains",
916+
"ap_hp_filters",
917+
),
918+
},
909919
}
910920

911921
def read_imro(file):
@@ -958,13 +968,13 @@ def _read_imro_string(imro_str: str) -> Probe:
958968
contact_info[k].append(v)
959969

960970
channel_ids = np.array(contact_info['channel_ids'])
961-
if 'elec_ids' in contact_info:
962-
elec_ids = np.array(contact_info['elec_ids'])
963-
964-
if imDatPrb_type == 0 or imDatPrb_type == 'Phase3a' or (imDatPrb_type in (1015, 1022, 1030, 1031, 1032)):
965-
# for NP1 and previous the elec_id is not in the list
971+
probe_types_without_elec_ids_in_their_imro_table = (0, 1015, 1022, 1030, 1031, 1032, "Phase3a", 1100)
972+
if imDatPrb_type in probe_types_without_elec_ids_in_their_imro_table:
966973
banks = np.array(contact_info['banks'])
967974
elec_ids = banks * 384 + channel_ids
975+
else:
976+
elec_ids = np.array(contact_info['elec_ids'])
977+
968978

969979
# compute position
970980
x_idx = elec_ids % probe_information["ncol"]
@@ -975,6 +985,7 @@ def _read_imro_string(imro_str: str) -> Probe:
975985
stagger = np.mod(y_idx + 1, 2) * probe_information["stagger"]
976986
x_pos = x_idx * x_pitch + stagger
977987
y_pos = y_idx * y_pitch
988+
positions = np.stack((x_pos, y_pos), axis=1)
978989

979990
if imDatPrb_type == 24:
980991
shank_ids = np.array(contact_info['shank_id'])
@@ -983,25 +994,25 @@ def _read_imro_string(imro_str: str) -> Probe:
983994
shank_ids = None
984995
contact_ids = [f'e{elec_id}' for elec_id in elec_ids]
985996

986-
987-
positions = np.zeros((num_contact, 2), dtype='float64')
988-
positions[:, 0] = x_pos
989-
positions[:, 1] = y_pos
990-
991997
# construct Probe object
992998
probe = Probe(ndim=2, si_units='um')
993-
probe.set_contacts(positions=positions, shapes='square',
994-
shank_ids=shank_ids,
995-
shape_params={'width': probe_information["contact_width"]})
999+
probe.set_contacts(
1000+
positions=positions,
1001+
shapes="square",
1002+
shank_ids=shank_ids,
1003+
shape_params={"width": probe_information["contact_width"]},
1004+
)
1005+
9961006
probe.set_contact_ids(contact_ids)
9971007

9981008
# Add planar contour
9991009
polygon = np.array(probe_information["polygon"])
10001010
contour = []
1011+
shank_pitch = probe_information["shank_pitch"]
10011012
for shank_id in range(probe_information["shank_number"]):
1002-
shift = [probe_information["shank_pitch"] * shank_id, 0]
1013+
shift = [shank_pitch * shank_id, 0]
10031014
contour += list(polygon + shift)
1004-
1015+
10051016
# shift
10061017
contour = np.array(contour) - [11, 11]
10071018
probe.set_planar_contour(contour)
@@ -1330,7 +1341,7 @@ def read_openephys(
13301341
ptype = 0
13311342
x_shift = -11
13321343
elif "Ultra" in pname:
1333-
ptype = "Ultra"
1344+
ptype = 1100
13341345
x_shift = -8
13351346
else: # Probe type unknown
13361347
ptype = None

0 commit comments

Comments
 (0)