99}
1010inverted_unit_map = {v : k for k , v in unit_map .items ()}
1111
12- shape_words = ['radius' , 'width' , 'width/height' ]
1312
1413def from_probe (probe : Probe ):
1514 """
@@ -19,10 +18,10 @@ def from_probe(probe: Probe):
1918 ----------
2019 probe_or_probegroup: Probe or ProbeGroup
2120 Probe or ProbeGroup to convert to ndx-probeinterface Probe devices
22-
21+
2322 Returns
2423 -------
25- devices: ndx_probeinterface.Probe
24+ devices: ndx_probeinterface.Probe
2625 The ndx-probeinterface Probe device
2726 """
2827 assert isinstance (probe , Probe )
@@ -50,69 +49,89 @@ def from_probegroup(probegroup: ProbeGroup):
5049 return devices
5150
5251
53- def to_probeinterface (ndx_Probe ) -> Probe :
52+ def to_probeinterface (ndx_probe ) -> Probe :
5453 """
5554 Construct a probeinterface.Probe from ndx_probeinterface.Probe
5655
5756 Parameters
5857 ----------
59- ndx_Probe : ndx_probeinterface.Probe
60- ndx_probeinterface.Probe to convert to probeinterface.Probe
61-
58+ ndx_probe : ndx_probeinterface.Probe
59+ ndx_probeinterface.Probe to convert to probeinterface.Probe
60+
6261 Returns
6362 -------
64- Probe: probeinterface.Probe
63+ Probe: probeinterface.Probe
6564 """
66- ndim = ndx_Probe .ndim
67- unit = inverted_unit_map [ndx_Probe .unit ]
68- polygon = ndx_Probe .planar_contour
69-
65+ ndim = ndx_probe .ndim
66+ unit = inverted_unit_map [ndx_probe .unit ]
67+ polygon = ndx_probe .planar_contour
68+
7069 positions = []
71- contact_ids = []
7270 shapes = []
73- shape_params = []
74- shank_ids = []
75- plane_axes = []
76- channel_indices = []
77- for shank in ndx_Probe .shanks .values ():
78- positions .append (shank .contact_table ['contact_position' ][:])
79- contact_ids .append (shank .contact_table ['contact_id' ][:])
80- shapes .append (shank .contact_table ['contact_shape' ][:])
81- channel_indices .append (shank .contact_table ['device_channel_index' ][:])
82- plane_axes .append (shank .contact_table ['contact_plane_axes' ][:])
83- shank_ids .append ([int (shank .shank_id )] * len (shank .contact_table ))
84- # WARNING: currently assumes that all the contacts have the same shape
85- shape_word = [shape for shape in shape_words if shape in shank .contact_table [:].columns ][0 ]
86- shape_params .append ([{shape_word : val } for val in shank .contact_table [shape_word ][:]])
71+
72+ contact_ids = None
73+ shape_params = None
74+ shank_ids = None
75+ plane_axes = None
76+ device_channel_indices = None
77+
78+ possible_shape_keys = ["radius" , "width" , "height" ]
79+ for shank in ndx_probe .shanks .values ():
80+ positions .append (shank .contact_table ["contact_position" ][:])
81+ shapes .append (shank .contact_table ["contact_shape" ][:])
82+ if "contact_id" in shank .contact_table .colnames :
83+ if contact_ids is None :
84+ contact_ids = []
85+ contact_ids .append (shank .contact_table ["contact_id" ][:])
86+ if "device_channel_index_pi" in shank .contact_table .colnames :
87+ if device_channel_indices is None :
88+ device_channel_indices = []
89+ device_channel_indices .append (shank .contact_table ["device_channel_index_pi" ][:])
90+ if "contact_plane_axes" in shank .contact_table .colnames :
91+ if plane_axes is None :
92+ plane_axes = []
93+ plane_axes .append (shank .contact_table ["contact_plane_axes" ][:])
94+ if shank_ids is None :
95+ shank_ids = []
96+ shank_ids .append ([str (shank .shank_id )] * len (shank .contact_table ))
97+ for possible_shape_key in possible_shape_keys :
98+ if possible_shape_key in shank .contact_table .colnames :
99+ if shape_params is None :
100+ shape_params = []
101+ shape_params .append ([{possible_shape_key : val } for val in shank .contact_table [possible_shape_key ][:]])
87102
88103 positions = [item for sublist in positions for item in sublist ]
89- contact_ids = [item for sublist in contact_ids for item in sublist ]
90104 shapes = [item for sublist in shapes for item in sublist ]
91- plane_axes = [item for sublist in plane_axes for item in sublist ]
92- shank_ids = [item for sublist in shank_ids for item in sublist ]
93- channel_indices = [item for sublist in channel_indices for item in sublist ]
94- shape_params = [item for sublist in shape_params for item in sublist ]
95105
96- probeinterface_Probe = Probe (ndim = ndim , si_units = unit )
97- probeinterface_Probe .set_contacts (positions = positions ,
98- shapes = shapes ,
99- shape_params = shape_params ,
100- plane_axes = plane_axes ,
101- shank_ids = shank_ids )
102- probeinterface_Probe .set_contact_ids (contact_ids = contact_ids )
103- probeinterface_Probe .set_device_channel_indices (channel_indices = channel_indices )
106+ if contact_ids is not None :
107+ contact_ids = [item for sublist in contact_ids for item in sublist ]
108+ if plane_axes is not None :
109+ plane_axes = [item for sublist in plane_axes for item in sublist ]
110+ if shape_params is not None :
111+ shape_params = [item for sublist in shape_params for item in sublist ]
112+ if shank_ids is not None :
113+ shank_ids = [item for sublist in shank_ids for item in sublist ]
114+ if device_channel_indices is not None :
115+ device_channel_indices = [item for sublist in channel_indices for item in sublist ]
104116
105- probeinterface_Probe .set_planar_contour (polygon )
117+ probeinterface_probe = Probe (ndim = ndim , si_units = unit )
118+ probeinterface_probe .set_contacts (
119+ positions = positions , shapes = shapes , shape_params = shape_params , plane_axes = plane_axes , shank_ids = shank_ids
120+ )
121+ probeinterface_probe .set_contact_ids (contact_ids = contact_ids )
122+ if device_channel_indices is not None :
123+ probeinterface_probe .set_device_channel_indices (channel_indices = device_channel_indices )
124+ probeinterface_probe .set_planar_contour (polygon )
106125
107- return probeinterface_Probe
126+ return probeinterface_probe
108127
109128
110129def _single_probe_to_nwb_device (probe : Probe ):
111130 from pynwb import load_namespaces , get_class
112131
113- Probe = get_class (' Probe' , ' ndx-probeinterface' )
114- Shank = get_class (' Shank' , ' ndx-probeinterface' )
115- ContactTable = get_class (' ContactTable' , ' ndx-probeinterface' )
132+ Probe = get_class (" Probe" , " ndx-probeinterface" )
133+ Shank = get_class (" Shank" , " ndx-probeinterface" )
134+ ContactTable = get_class (" ContactTable" , " ndx-probeinterface" )
116135
117136 contact_positions = probe .contact_positions
118137 contact_plane_axes = probe .contact_plane_axes
@@ -150,13 +169,6 @@ def _single_probe_to_nwb_device(probe: Probe):
150169 name = "ContactTable" ,
151170 description = "Contact Table for ProbeInterface" ,
152171 )
153-
154- if probe .device_channel_indices is not None :
155- contact_table .add_column (name = "device_channel_index" ,
156- description = "Device channel index" )
157- for k in shape_keys :
158- contact_table .add_column (name = k ,
159- description = "Shape parameter for electrode" )
160172
161173 for index in shank_indices :
162174 kwargs = dict (
@@ -168,12 +180,10 @@ def _single_probe_to_nwb_device(probe: Probe):
168180 for k in shape_keys :
169181 kwargs [k ] = contacts_arr [k ][index ]
170182 if probe .device_channel_indices is not None :
171- kwargs ["device_channel_index " ] = probe .device_channel_indices [index ]
183+ kwargs ["device_channel_index_pi " ] = probe .device_channel_indices [index ]
172184 contact_table .add_row (kwargs )
173185 contact_tables .append (contact_table )
174- shank = Shank (name = shank_name ,
175- shank_id = shank_id ,
176- contact_table = contact_table )
186+ shank = Shank (name = shank_name , shank_id = shank_id , contact_table = contact_table )
177187 shanks .append (shank )
178188
179189 if "serial_number" in probe .annotations :
@@ -197,7 +207,7 @@ def _single_probe_to_nwb_device(probe: Probe):
197207 manufacturer = manufacturer ,
198208 ndim = probe .ndim ,
199209 unit = unit_map [probe .si_units ],
200- planar_contour = planar_contour
210+ planar_contour = planar_contour ,
201211 )
202212
203213 return probe_device
0 commit comments