Skip to content

Commit 7708184

Browse files
authored
Merge pull request #169 from h-mayorquin/add_nph_support_II
Add second nhp probe test data
2 parents 83c4f8b + 1b4b6fd commit 7708184

File tree

3 files changed

+144
-11
lines changed

3 files changed

+144
-11
lines changed

probeinterface/io.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,10 @@ 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
729+
# This probably should be None or something else because NOT ONLY the neuropixels 1.0 have that imDatPrb_type
730730
0: {
731731
"probe_name": "Neuropixels 1.0",
732732
"x_pitch": 32,
@@ -808,7 +808,7 @@ def write_csv(file, probe):
808808
},
809809
# Neuropixels 1.0-NHP Short (10mm)
810810
1015: {
811-
"probe_name": "Neuropixels 1.0-NHP - medium",
811+
"probe_name": "Neuropixels 1.0-NHP - short",
812812
"x_pitch": 32,
813813
"y_pitch": 20,
814814
"contact_width": 12,
@@ -908,7 +908,19 @@ def write_csv(file, probe):
908908
},
909909
}
910910

911-
def read_imro(file):
911+
# Map imDatPrb_pn to imDatPrb_type when the latter is missing
912+
probe_number_to_probe_type = {
913+
"PRB_1_4_0480_1": 0,
914+
"PRB_1_4_0480_1_C": 0,
915+
"NP1015": 1015,
916+
"NP1022": 1022,
917+
"NP1030": 1030,
918+
"NP1031": 1031,
919+
"NP1032": 1032,
920+
}
921+
922+
923+
def read_imro(file: Union[str, Path]) -> Probe:
912924
"""
913925
Read probe position from the imro file used in input of SpikeGlx and Open-Ephys for neuropixels probes.
914926
@@ -930,7 +942,7 @@ def read_imro(file):
930942
return _read_imro_string(imro_str)
931943

932944

933-
def _read_imro_string(imro_str: str) -> Probe:
945+
def _read_imro_string(imro_str: str, imDatPrb_pn: str = None) -> Probe:
934946
"""
935947
Low-level function to parse the imro table when presented as a string
936948
@@ -949,6 +961,9 @@ def _read_imro_string(imro_str: str) -> Probe:
949961
else:
950962
raise RuntimeError(f'read_imro error, the header has a strange length: {len(header)}')
951963

964+
if imDatPrb_type in [0, None]:
965+
imDatPrb_type = probe_number_to_probe_type[imDatPrb_pn]
966+
952967
fields = npx_probe[imDatPrb_type]["fields_in_imro_table"]
953968
contact_info = {k: [] for k in fields}
954969
for i, part in enumerate(parts):
@@ -966,8 +981,7 @@ def _read_imro_string(imro_str: str) -> Probe:
966981
elec_ids = banks * 384 + channel_ids
967982

968983
# compute position
969-
x_idx = elec_ids % npx_probe[imDatPrb_type]["ncol"]
970-
y_idx = elec_ids // npx_probe[imDatPrb_type]["ncol"]
984+
y_idx, x_idx = np.divmod(elec_ids, npx_probe[imDatPrb_type]["ncol"])
971985
x_pitch = npx_probe[imDatPrb_type ]["x_pitch"]
972986
y_pitch = npx_probe[imDatPrb_type ]["y_pitch"]
973987

@@ -1000,7 +1014,7 @@ def _read_imro_string(imro_str: str) -> Probe:
10001014
for shank_id in range(npx_probe[imDatPrb_type]["shank_number"]):
10011015
shift = [npx_probe[imDatPrb_type]["shank_pitch"] * shank_id, 0]
10021016
contour += list(polygon + shift)
1003-
1017+
10041018
# shift
10051019
contour = np.array(contour) - [11, 11]
10061020
probe.set_planar_contour(contour)
@@ -1094,8 +1108,9 @@ def read_spikeglx(file: Union[str, Path]) -> Probe:
10941108

10951109
assert "imroTbl" in meta, "Could not find imroTbl field in meta file!"
10961110
imro_table = meta['imroTbl']
1111+
imDatPrb_pn = meta.get("imDatPrb_pn", None)
10971112

1098-
probe = _read_imro_string(imro_table)
1113+
probe = _read_imro_string(imro_str=imro_table, imDatPrb_pn=imDatPrb_pn)
10991114

11001115
# sometimes we need to slice the probe when not all channels are saved
11011116
saved_chans = get_saved_channel_indices_from_spikeglx_meta(meta_file)

0 commit comments

Comments
 (0)