@@ -36,26 +36,6 @@ def from_probeinterface(probe_or_probegroup: Union[Probe, ProbeGroup]) -> List[D
3636 return devices
3737
3838
39- def from_probegroup (probegroup : ProbeGroup ):
40- """
41- Construct ndx-probeinterface Probe devices from a probeinterface.ProbeGroup
42-
43- Parameters
44- ----------
45- probegroup: ProbeGroup
46- ProbeGroup to convert to ndx-probeinterface Probe devices
47-
48- Returns
49- -------
50- list
51- List of ndx-probeinterface Probe devices
52- """
53- assert isinstance (probegroup , ProbeGroup )
54- devices = []
55- for probe in probegroup .probes :
56- devices .append (_single_probe_to_nwb_device (probe ))
57- return devices
58-
5939
6040def to_probeinterface (ndx_probe ) -> Probe :
6141 """
@@ -84,29 +64,31 @@ def to_probeinterface(ndx_probe) -> Probe:
8464 device_channel_indices = None
8565
8666 possible_shape_keys = ["radius" , "width" , "height" ]
87- for shank in ndx_probe .shanks .values ():
88- positions .append (shank .contact_table ["contact_position" ][:])
89- shapes .append (shank .contact_table ["contact_shape" ][:])
90- if "contact_id" in shank .contact_table .colnames :
91- if contact_ids is None :
92- contact_ids = []
93- contact_ids .append (shank .contact_table ["contact_id" ][:])
94- if "device_channel_index_pi" in shank .contact_table .colnames :
95- if device_channel_indices is None :
96- device_channel_indices = []
97- device_channel_indices .append (shank .contact_table ["device_channel_index_pi" ][:])
98- if "contact_plane_axes" in shank .contact_table .colnames :
99- if plane_axes is None :
100- plane_axes = []
101- plane_axes .append (shank .contact_table ["contact_plane_axes" ][:])
67+ contact_table = ndx_probe .contact_table
68+
69+ positions .append (contact_table ["contact_position" ][:])
70+ shapes .append (contact_table ["contact_shape" ][:])
71+ if "contact_id" in contact_table .colnames :
72+ if contact_ids is None :
73+ contact_ids = []
74+ contact_ids .append (contact_table ["contact_id" ][:])
75+ if "device_channel_index_pi" in contact_table .colnames :
76+ if device_channel_indices is None :
77+ device_channel_indices = []
78+ device_channel_indices .append (contact_table ["device_channel_index_pi" ][:])
79+ if "contact_plane_axes" in contact_table .colnames :
80+ if plane_axes is None :
81+ plane_axes = []
82+ plane_axes .append (contact_table ["contact_plane_axes" ][:])
83+ if "shank_id" in contact_table .colnames :
10284 if shank_ids is None :
10385 shank_ids = []
104- shank_ids .append ([ str ( shank . shank_id )] * len ( shank . contact_table ) )
105- for possible_shape_key in possible_shape_keys :
106- if possible_shape_key in shank . contact_table .colnames :
107- if shape_params is None :
108- shape_params = []
109- shape_params .append ([{possible_shape_key : val } for val in shank . contact_table [possible_shape_key ][:]])
86+ shank_ids .append (contact_table [ " shank_id" ][:] )
87+ for possible_shape_key in possible_shape_keys :
88+ if possible_shape_key in contact_table .colnames :
89+ if shape_params is None :
90+ shape_params = []
91+ shape_params .append ([{possible_shape_key : val } for val in contact_table [possible_shape_key ][:]])
11092
11193 positions = [item for sublist in positions for item in sublist ]
11294 shapes = [item for sublist in shapes for item in sublist ]
@@ -138,7 +120,6 @@ def _single_probe_to_nwb_device(probe: Probe):
138120 from pynwb import load_namespaces , get_class
139121
140122 Probe = get_class ("Probe" , "ndx-probeinterface" )
141- Shank = get_class ("Shank" , "ndx-probeinterface" )
142123 ContactTable = get_class ("ContactTable" , "ndx-probeinterface" )
143124
144125 contact_positions = probe .contact_positions
@@ -160,39 +141,25 @@ def _single_probe_to_nwb_device(probe: Probe):
160141 if k not in shape_keys :
161142 shape_keys .append (k )
162143
163- shanks = []
164- contact_tables = []
165- for i_s , unique_shank in enumerate (unique_shanks ):
166- if shank_ids is not None :
167- shank_indices = np .nonzero (shank_ids == unique_shank )[0 ]
168- pi_shank = probe .get_shanks ()[i_s ]
169- shank_name = f"Shank { pi_shank .shank_id } "
170- shank_id = str (pi_shank .shank_id )
171- else :
172- shank_indices = np .arange (probe .get_contact_count ())
173- shank_name = "Shank 0"
174- shank_id = "0"
175-
176- contact_table = ContactTable (
177- name = "ContactTable" ,
178- description = "Contact Table for ProbeInterface" ,
179- )
144+ contact_table = ContactTable (
145+ name = "ContactTable" ,
146+ description = "Contact Table for ProbeInterface" ,
147+ )
180148
181- for index in shank_indices :
182- kwargs = dict (
183- contact_position = contact_positions [index ],
184- contact_plane_axes = contact_plane_axes [index ],
185- contact_id = contact_ids [index ],
186- contact_shape = contacts_arr ["contact_shapes" ][index ],
187- )
188- for k in shape_keys :
189- kwargs [k ] = contacts_arr [k ][index ]
190- if probe .device_channel_indices is not None :
191- kwargs ["device_channel_index_pi" ] = probe .device_channel_indices [index ]
192- contact_table .add_row (kwargs )
193- contact_tables .append (contact_table )
194- shank = Shank (name = shank_name , shank_id = shank_id , contact_table = contact_table )
195- shanks .append (shank )
149+ for index in np .arange (probe .get_contact_count ()):
150+ kwargs = dict (
151+ contact_position = contact_positions [index ],
152+ contact_plane_axes = contact_plane_axes [index ],
153+ contact_id = contact_ids [index ],
154+ contact_shape = contacts_arr ["contact_shapes" ][index ],
155+ )
156+ for k in shape_keys :
157+ kwargs [k ] = contacts_arr [k ][index ]
158+ if probe .device_channel_indices is not None :
159+ kwargs ["device_channel_index_pi" ] = probe .device_channel_indices [index ]
160+ if probe .shank_ids is not None :
161+ kwargs ["shank_id" ] = probe .shank_ids [index ]
162+ contact_table .add_row (kwargs )
196163
197164 if "serial_number" in probe .annotations :
198165 serial_number = probe .annotations ["serial_number" ]
@@ -209,13 +176,13 @@ def _single_probe_to_nwb_device(probe: Probe):
209176
210177 probe_device = Probe (
211178 name = probe .annotations ["name" ],
212- shanks = shanks ,
213179 model_name = model_name ,
214180 serial_number = serial_number ,
215181 manufacturer = manufacturer ,
216182 ndim = probe .ndim ,
217183 unit = unit_map [probe .si_units ],
218184 planar_contour = planar_contour ,
185+ contact_table = contact_table
219186 )
220187
221188 return probe_device
0 commit comments