@@ -318,7 +318,7 @@ def nwb_from_cache(self) -> pynwb.NWBFile | None:
318
318
319
319
@property
320
320
def nwb (self ) -> pynwb .NWBFile :
321
- return pynwb .NWBFile (
321
+ nwb = pynwb .NWBFile (
322
322
session_id = self .session_id ,
323
323
session_description = self .session_description ,
324
324
experiment_description = self .experiment_description ,
@@ -341,14 +341,24 @@ def nwb(self) -> pynwb.NWBFile:
341
341
), # we have one session without trials (670248_2023-08-02)
342
342
intervals = self ._intervals ,
343
343
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
345
346
analysis = self ._analysis ,
346
347
devices = self ._devices if self ._devices else None ,
347
348
electrode_groups = self ._electrode_groups if self .is_ephys else None ,
348
349
electrodes = self .electrodes if self .is_ephys else None ,
349
350
units = self .units if self .is_sorted else None ,
350
351
)
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
+
352
362
def write_nwb (
353
363
self ,
354
364
path : str | npc_io .PathLike | None = None ,
@@ -723,6 +733,9 @@ def processing(
723
733
"""Data after processing and filtering - raw data goes in
724
734
`acquisition`.
725
735
"""
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
726
739
processing = pynwb .core .LabelledDict (label = "processing" , key_attr = "name" )
727
740
for module_name in ("behavior" ,) + (("ecephys" ,) if self .is_ephys else ()):
728
741
module = getattr (self , f"_{ module_name } " )
0 commit comments