13
13
)
14
14
from spikeinterface import extractors
15
15
from tqdm import tqdm
16
-
16
+ import warnings
17
17
from ... import probe , ephys_acute
18
18
19
19
assert probe .schema .is_activated (), 'probe not yet activated'
@@ -113,8 +113,8 @@ def add_electrodes_to_nwb(session_key: dict, nwbfile: pynwb.NWBFile):
113
113
for this_probe in (ephys .ProbeInsertion * probe .Probe & session_key ).fetch (
114
114
as_dict = True
115
115
):
116
- insertion_record = (ephys .InsertionLocation & this_probe ).fetch1 ()
117
- if insertion_record :
116
+ insertion_record = (ephys .InsertionLocation & this_probe ).fetch ()
117
+ if len ( insertion_record ) == 1 :
118
118
insert_location = json .dumps (
119
119
{
120
120
k : v
@@ -123,8 +123,10 @@ def add_electrodes_to_nwb(session_key: dict, nwbfile: pynwb.NWBFile):
123
123
},
124
124
cls = DecimalEncoder ,
125
125
)
126
- else :
126
+ elif len ( insertion_record ) == 0 :
127
127
insert_location = "unknown"
128
+ else :
129
+ raise DataJointError (f'Found multiple insertion locations for { this_probe } ' )
128
130
129
131
device = nwbfile .create_device (
130
132
name = this_probe ["probe" ],
@@ -194,6 +196,8 @@ def create_units_table(
194
196
mapping = get_electrodes_mapping (nwbfile .electrodes )
195
197
196
198
units_table = pynwb .misc .Units (name = name , description = desc )
199
+ # add additional columns to the units table
200
+ units_query = ephys .CuratedClustering .Unit () & session_key
197
201
for additional_attribute in ["cluster_quality_label" , "spike_depths" ]:
198
202
units_table .add_column (
199
203
name = units_query .heading .attributes [additional_attribute ].name ,
@@ -268,13 +272,12 @@ def add_ephys_units_to_nwb(
268
272
"""
269
273
270
274
if not ephys .ClusteringTask & session_key :
275
+ warnings .warn (f'No unit data exists for session:{ session_key } ' )
271
276
return
272
277
273
278
if nwbfile .electrodes is None :
274
279
add_electrodes_to_nwb (session_key , nwbfile )
275
280
276
- # add additional columns to the units table
277
- units_query = ephys .CuratedClustering .Unit () & session_key
278
281
279
282
for paramset_record in (
280
283
ephys .ClusteringParamSet & ephys .CuratedClustering & session_key
0 commit comments