Skip to content

Commit

Permalink
Fix unreadable NWBs #136
Browse files Browse the repository at this point in the history
  • Loading branch information
bjhardcastle committed Sep 26, 2024
1 parent cdd2057 commit b6e24f9
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/npc_sessions/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def nwb_from_cache(self) -> pynwb.NWBFile | None:

@property
def nwb(self) -> pynwb.NWBFile:
return pynwb.NWBFile(
nwb = pynwb.NWBFile(
session_id=self.session_id,
session_description=self.session_description,
experiment_description=self.experiment_description,
Expand All @@ -341,14 +341,24 @@ def nwb(self) -> pynwb.NWBFile:
), # we have one session without trials (670248_2023-08-02)
intervals=self._intervals,
acquisition=self._acquisition,
processing=tuple(self.processing.values()),
# processing=tuple(self.processing.values()), # unsupported:
# causes recursive references in the hdf5 file on disk
analysis=self._analysis,
devices=self._devices if self._devices else None,
electrode_groups=self._electrode_groups if self.is_ephys else None,
electrodes=self.electrodes if self.is_ephys else None,
units=self.units if self.is_sorted else None,
)

#! keep the following in-sync with in-memory view at `self.processing`:
for module_name in ("behavior",) + (("ecephys",) if self.is_ephys else ()):
module = getattr(self, f"_{module_name}")
_ = nwb.create_processing_module(
name=module_name,
description=f"processed {module_name} data",
data_interfaces=module,
)
return nwb

def write_nwb(
self,
path: str | npc_io.PathLike | None = None,
Expand Down Expand Up @@ -723,6 +733,9 @@ def processing(
"""Data after processing and filtering - raw data goes in
`acquisition`.
"""
#! keep the following in-sync with nwb construction in `self.nwb`
# - cannot pass modules to NWBFile.__init__ as it causes recursive
# references in the hdf5 file on disk
processing = pynwb.core.LabelledDict(label="processing", key_attr="name")
for module_name in ("behavior",) + (("ecephys",) if self.is_ephys else ()):
module = getattr(self, f"_{module_name}")
Expand Down

0 comments on commit b6e24f9

Please sign in to comment.