Skip to content

Commit efb063d

Browse files
authored
Merge pull request #174 from h-mayorquin/refactor_files
Consolidate neuropixel information in one place
2 parents 391a201 + b20bbdf commit efb063d

File tree

1 file changed

+86
-46
lines changed

1 file changed

+86
-46
lines changed

probeinterface/io.py

Lines changed: 86 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ def write_csv(file, probe):
728728
npx_probe = {
729729
# Neuropixels 1.0
730730
0: {
731+
"probe_name": "Neuropixels 1.0",
731732
"x_pitch": 32,
732733
"y_pitch": 20,
733734
"contact_width": 12,
@@ -736,9 +737,18 @@ def write_csv(file, probe):
736737
"shank_number": 1,
737738
"ncol": 2,
738739
"polygon": polygon_description["default"],
740+
"fields_in_imro_table": (
741+
"channel_ids",
742+
"banks",
743+
"references",
744+
"ap_gains",
745+
"lf_gains",
746+
"ap_hp_filters",
747+
),
739748
},
740-
# Neuropixels 2.0 - Single Shank
749+
# Neuropixels 2.0 - Single Shank
741750
21: {
751+
"probe_name": "Neuropixels 2.0 - Single Shank",
742752
"x_pitch": 32,
743753
"y_pitch": 15,
744754
"contact_width": 12,
@@ -747,9 +757,11 @@ def write_csv(file, probe):
747757
"shank_number": 1,
748758
"ncol": 2,
749759
"polygon": polygon_description["default"],
760+
"fields_in_imro_table": ("channel_ids", "banks", "references", "elec_ids"),
750761
},
751-
# Neuropixels 2.0 - Four Shank
762+
# Neuropixels 2.0 - Four Shank
752763
24: {
764+
"probe_name": "Neuropixels 2.0 - Four Shank",
753765
"x_pitch": 32,
754766
"y_pitch": 15,
755767
"contact_width": 12,
@@ -758,10 +770,17 @@ def write_csv(file, probe):
758770
"shank_number": 4,
759771
"ncol": 2,
760772
"polygon": polygon_description["default"],
773+
"fields_in_imro_table": (
774+
"channel_ids",
775+
"shank_id",
776+
"banks",
777+
"references",
778+
"elec_ids",
779+
),
761780
},
762-
#
763-
'Phase3a': {
764-
781+
#
782+
"Phase3a": {
783+
"probe_name": "Phase3a",
765784
"x_pitch": 32,
766785
"y_pitch": 20,
767786
"contact_width": 12,
@@ -770,9 +789,17 @@ def write_csv(file, probe):
770789
"shank_number": 1,
771790
"ncol": 2,
772791
"polygon": polygon_description["default"],
773-
},
792+
"fields_in_imro_table": (
793+
"channel_ids",
794+
"banks",
795+
"references",
796+
"ap_gains",
797+
"lf_gains",
798+
),
799+
},
774800
# Neuropixels 1.0-NHP Short (10mm)
775801
1015: {
802+
"probe_name": "Neuropixels 1.0-NHP - medium",
776803
"x_pitch": 32,
777804
"y_pitch": 20,
778805
"contact_width": 12,
@@ -781,9 +808,18 @@ def write_csv(file, probe):
781808
"shank_number": 1,
782809
"ncol": 2,
783810
"polygon": polygon_description["default"],
811+
"fields_in_imro_table": (
812+
"channel_ids",
813+
"banks",
814+
"references",
815+
"ap_gains",
816+
"lf_gains",
817+
"ap_hp_filters",
818+
),
784819
},
785820
# Neuropixels 1.0-NHP Medium (25mm)
786821
1022: {
822+
"probe_name": "Neuropixels 1.0-NHP - medium",
787823
"x_pitch": 103,
788824
"y_pitch": 20,
789825
"contact_width": 12,
@@ -792,9 +828,18 @@ def write_csv(file, probe):
792828
"shank_number": 1,
793829
"ncol": 2,
794830
"polygon": polygon_description["nhp125"],
831+
"fields_in_imro_table": (
832+
"channel_ids",
833+
"banks",
834+
"references",
835+
"ap_gains",
836+
"lf_gains",
837+
"ap_hp_filters",
838+
),
795839
},
796-
# Neuropixels 1.0-NHP 45mm SOI90 - NHP long 90um wide, staggered contacts
840+
# Neuropixels 1.0-NHP 45mm SOI90 - NHP long 90um wide, staggered contacts
797841
1030: {
842+
"probe_name": "Neuropixels 1.0-NHP - long SOI90 staggered",
798843
"x_pitch": 56,
799844
"y_pitch": 20,
800845
"stagger": 12,
@@ -803,9 +848,18 @@ def write_csv(file, probe):
803848
"shank_number": 1,
804849
"ncol": 2,
805850
"polygon": polygon_description["nhp90"],
851+
"fields_in_imro_table": (
852+
"channel_ids",
853+
"banks",
854+
"references",
855+
"ap_gains",
856+
"lf_gains",
857+
"ap_hp_filters",
858+
),
806859
},
807860
# Neuropixels 1.0-NHP 45mm SOI125 - NHP long 125um wide, staggered contacts
808861
1031: {
862+
"probe_name": "Neuropixels 1.0-NHP - long SOI125 staggered",
809863
"x_pitch": 91,
810864
"y_pitch": 20,
811865
"contact_width": 12,
@@ -814,9 +868,18 @@ def write_csv(file, probe):
814868
"shank_number": 1,
815869
"ncol": 2,
816870
"polygon": polygon_description["nhp125"],
817-
},
871+
"fields_in_imro_table": (
872+
"channel_ids",
873+
"banks",
874+
"references",
875+
"ap_gains",
876+
"lf_gains",
877+
"ap_hp_filters",
878+
),
879+
},
818880
# 1.0-NHP 45mm SOI115 / 125 linear - NHP long 125um wide, linear contacts
819881
1032: {
882+
"probe_name": "Neuropixels 1.0-NHP - long SOI125 linear",
820883
"x_pitch": 103,
821884
"y_pitch": 20,
822885
"contact_width": 12,
@@ -825,7 +888,15 @@ def write_csv(file, probe):
825888
"shank_number": 1,
826889
"ncol": 2,
827890
"polygon": polygon_description["nhp125"],
828-
}
891+
"fields_in_imro_table": (
892+
"channel_ids",
893+
"banks",
894+
"references",
895+
"ap_gains",
896+
"lf_gains",
897+
"ap_hp_filters",
898+
),
899+
},
829900
}
830901

831902
def read_imro(file):
@@ -852,7 +923,7 @@ def read_imro(file):
852923

853924
def _read_imro_string(imro_str: str) -> Probe:
854925
"""
855-
Low-level function to parse imro string
926+
Low-level function to parse the imro table when presented as a string
856927
857928
See this doc https://billkarsh.github.io/SpikeGLX/help/imroTables/
858929
@@ -869,37 +940,7 @@ def _read_imro_string(imro_str: str) -> Probe:
869940
else:
870941
raise RuntimeError(f'read_imro error, the header has a strange length: {len(header)}')
871942

872-
# disptach values from list in the info dict
873-
if imDatPrb_type == 0:
874-
probe_name = "Neuropixels 1.0"
875-
fields = ('channel_ids', 'banks', 'references', 'ap_gains', 'lf_gains', 'ap_hp_filters')
876-
elif imDatPrb_type == 21:
877-
probe_name = "Neuropixels 2.0 - SingleShank"
878-
fields = ('channel_ids', 'banks', 'references', 'elec_ids')
879-
elif imDatPrb_type == 24:
880-
probe_name = "Neuropixels 2.0 - MultiShank"
881-
fields = ('channel_ids', 'shank_id', 'banks', 'references', 'elec_ids')
882-
elif imDatPrb_type == 'Phase3a':
883-
probe_name = "Neuropixels Phase3a"
884-
fields = ('channel_ids', 'banks', 'references', 'ap_gains', 'lf_gains')
885-
elif imDatPrb_type == 1015:
886-
probe_name = "Neuropixels 1.0-NHP - short"
887-
fields = ('channel_ids', 'banks', 'references', 'ap_gains', 'lf_gains', 'ap_hp_filters')
888-
elif imDatPrb_type == 1022:
889-
probe_name = "Neuropixels 1.0-NHP - medium"
890-
fields = ('channel_ids', 'banks', 'references', 'ap_gains', 'lf_gains', 'ap_hp_filters')
891-
elif imDatPrb_type == 1030:
892-
probe_name = "Neuropixels 1.0-NHP - long SOI90 staggered"
893-
fields = ('channel_ids', 'banks', 'references', 'ap_gains', 'lf_gains', 'ap_hp_filters')
894-
elif imDatPrb_type == 1031:
895-
probe_name = "Neuropixels 1.0-NHP - long SOI125 staggered"
896-
fields = ('channel_ids', 'banks', 'references', 'ap_gains', 'lf_gains', 'ap_hp_filters')
897-
elif imDatPrb_type == 1032:
898-
probe_name = "Neuropixels 1.0-NHP - long SOI125 linear"
899-
fields = ('channel_ids', 'banks', 'references', 'ap_gains', 'lf_gains', 'ap_hp_filters')
900-
else:
901-
raise RuntimeError(f'unsupported imro type : {imDatPrb_type}')
902-
943+
fields = npx_probe[imDatPrb_type]["fields_in_imro_table"]
903944
contact_info = {k: [] for k in fields}
904945
for i, part in enumerate(parts):
905946
values = tuple(map(int, part[1:].split(' ')))
@@ -956,18 +997,17 @@ def _read_imro_string(imro_str: str) -> Probe:
956997
probe.set_planar_contour(contour)
957998

958999
# this is scalar annotations
1000+
probe_name = npx_probe[imDatPrb_type]["probe_name"]
9591001
probe.annotate(
9601002
name=probe_name,
9611003
manufacturer="IMEC",
9621004
probe_type=imDatPrb_type,
9631005
)
9641006

9651007
# this is vector annotations
966-
annotations = {}
967-
for k in ('channel_ids', 'banks', 'references', 'ap_gains', 'lf_gains', 'ap_hp_filters'):
968-
if k in contact_info:
969-
annotations[k] = contact_info[k]
970-
probe.annotate_contacts(**annotations)
1008+
vector_properties = ('channel_ids', 'banks', 'references', 'ap_gains', 'lf_gains', 'ap_hp_filters')
1009+
vector_properties_available = {k: v for k, v in contact_info.items() if k in vector_properties}
1010+
probe.annotate_contacts(**vector_properties_available)
9711011

9721012
# wire it
9731013
probe.set_device_channel_indices(np.arange(positions.shape[0]))

0 commit comments

Comments
 (0)