Skip to content

Commit b6e24f9

Browse files
committed
Fix unreadable NWBs #136
1 parent cdd2057 commit b6e24f9

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/npc_sessions/sessions.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def nwb_from_cache(self) -> pynwb.NWBFile | None:
318318

319319
@property
320320
def nwb(self) -> pynwb.NWBFile:
321-
return pynwb.NWBFile(
321+
nwb = pynwb.NWBFile(
322322
session_id=self.session_id,
323323
session_description=self.session_description,
324324
experiment_description=self.experiment_description,
@@ -341,14 +341,24 @@ def nwb(self) -> pynwb.NWBFile:
341341
), # we have one session without trials (670248_2023-08-02)
342342
intervals=self._intervals,
343343
acquisition=self._acquisition,
344-
processing=tuple(self.processing.values()),
344+
# processing=tuple(self.processing.values()), # unsupported:
345+
# causes recursive references in the hdf5 file on disk
345346
analysis=self._analysis,
346347
devices=self._devices if self._devices else None,
347348
electrode_groups=self._electrode_groups if self.is_ephys else None,
348349
electrodes=self.electrodes if self.is_ephys else None,
349350
units=self.units if self.is_sorted else None,
350351
)
351-
352+
#! keep the following in-sync with in-memory view at `self.processing`:
353+
for module_name in ("behavior",) + (("ecephys",) if self.is_ephys else ()):
354+
module = getattr(self, f"_{module_name}")
355+
_ = nwb.create_processing_module(
356+
name=module_name,
357+
description=f"processed {module_name} data",
358+
data_interfaces=module,
359+
)
360+
return nwb
361+
352362
def write_nwb(
353363
self,
354364
path: str | npc_io.PathLike | None = None,
@@ -723,6 +733,9 @@ def processing(
723733
"""Data after processing and filtering - raw data goes in
724734
`acquisition`.
725735
"""
736+
#! keep the following in-sync with nwb construction in `self.nwb`
737+
# - cannot pass modules to NWBFile.__init__ as it causes recursive
738+
# references in the hdf5 file on disk
726739
processing = pynwb.core.LabelledDict(label="processing", key_attr="name")
727740
for module_name in ("behavior",) + (("ecephys",) if self.is_ephys else ()):
728741
module = getattr(self, f"_{module_name}")

0 commit comments

Comments
 (0)