Skip to content

Commit bc54009

Browse files
committed
Merge remote-tracking branch 'origin/convert_to_nwb' into convert_to_nwb
2 parents 3971fe6 + 842beec commit bc54009

File tree

1 file changed

+9
-6
lines changed
  • element_array_ephys/export/nwb

1 file changed

+9
-6
lines changed

element_array_ephys/export/nwb/nwb.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414
from spikeinterface import extractors
1515
from tqdm import tqdm
16-
16+
import warnings
1717
from ... import probe, ephys_acute
1818

1919
assert probe.schema.is_activated(), 'probe not yet activated'
@@ -113,8 +113,8 @@ def add_electrodes_to_nwb(session_key: dict, nwbfile: pynwb.NWBFile):
113113
for this_probe in (ephys.ProbeInsertion * probe.Probe & session_key).fetch(
114114
as_dict=True
115115
):
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:
118118
insert_location = json.dumps(
119119
{
120120
k: v
@@ -123,8 +123,10 @@ def add_electrodes_to_nwb(session_key: dict, nwbfile: pynwb.NWBFile):
123123
},
124124
cls=DecimalEncoder,
125125
)
126-
else:
126+
elif len(insertion_record)==0:
127127
insert_location = "unknown"
128+
else:
129+
raise DataJointError(f'Found multiple insertion locations for {this_probe}')
128130

129131
device = nwbfile.create_device(
130132
name=this_probe["probe"],
@@ -194,6 +196,8 @@ def create_units_table(
194196
mapping = get_electrodes_mapping(nwbfile.electrodes)
195197

196198
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
197201
for additional_attribute in ["cluster_quality_label", "spike_depths"]:
198202
units_table.add_column(
199203
name=units_query.heading.attributes[additional_attribute].name,
@@ -268,13 +272,12 @@ def add_ephys_units_to_nwb(
268272
"""
269273

270274
if not ephys.ClusteringTask & session_key:
275+
warnings.warn(f'No unit data exists for session:{session_key}')
271276
return
272277

273278
if nwbfile.electrodes is None:
274279
add_electrodes_to_nwb(session_key, nwbfile)
275280

276-
# add additional columns to the units table
277-
units_query = ephys.CuratedClustering.Unit() & session_key
278281

279282
for paramset_record in (
280283
ephys.ClusteringParamSet & ephys.CuratedClustering & session_key

0 commit comments

Comments
 (0)