When an NWBFile containing a LabeledEvents or TTLs type is read using PyNWB without first calling import ndx_events, then it is missing the timestamps dataset which should be inherited from Events. Interestingly, the description attribute is correctly inherited from Events.
Example code:
from pynwb import NWBHDF5IO
# import ndx_events
with NWBHDF5IO('nwbfile.nwb', 'r', load_namespaces=True) as io:
nwbfile = io.read()
print(nwbfile.acquisition['LabeledEvents'])
Output without importing ndx_events (missing timestamps field):
LabeledEvents abc.LabeledEvents at 0x1745887195848
Fields:
data: <HDF5 dataset "data": shape (3,), type "<u4">
data__labels: ['a' 'b' 'c']
description: behavioral events of the experimental paradigm
Output with importing ndx_events (contains timestamps field):
LabeledEvents ndx_events.events.LabeledEvents at 0x2565438502472
Fields:
data: <HDF5 dataset "data": shape (3,), type "<u4">
description: behavioral events of the experimental paradigm
labels: ['a' 'b' 'c']
timestamps: <HDF5 dataset "timestamps": shape (3,), type "<f4">
unit: seconds
This is likely an issue of within-spec spec resolution when handling load_namespaces=True and has to be addressed within HDMF.
MWE to generate a file with `LabeledEvents`
```python
from pynwb import NWBFile, NWBHDF5IO, validate
import datetime
from ndx_events import LabeledEvents
nwbfile = NWBFile(
session_description='session_description',
identifier='identifier',
session_start_time=datetime.datetime.now(datetime.timezone.utc),
)
labeled_events = LabeledEvents(name='LabeledEvents',
description='behavioral events of the experimental paradigm',
timestamps=[1, 2, 3],
data=[2, 1, 0],
labels=['a', 'b', 'c'])
nwbfile.add_acquisition(labeled_events)
filename = 'nwbfile.nwb'
with NWBHDF5IO(filename, 'w') as io:
io.write(nwbfile)
with NWBHDF5IO(filename, 'r') as io:
errors = validate(io)
print(errors)
nwbfile = io.read()
print(nwbfile)
print(nwbfile.acquisition['LabeledEvents'])
```
When an
NWBFile
containing aLabeledEvents
orTTLs
type is read using PyNWB without first callingimport ndx_events
, then it is missing thetimestamps
dataset which should be inherited fromEvents
. Interestingly, thedescription
attribute is correctly inherited fromEvents
.Example code:
Output without importing ndx_events (missing
timestamps
field):Output with importing ndx_events (contains
timestamps
field):This is likely an issue of within-spec spec resolution when handling
load_namespaces=True
and has to be addressed within HDMF.MWE to generate a file with `LabeledEvents`
```python from pynwb import NWBFile, NWBHDF5IO, validate import datetime from ndx_events import LabeledEvents nwbfile = NWBFile( session_description='session_description', identifier='identifier', session_start_time=datetime.datetime.now(datetime.timezone.utc), ) labeled_events = LabeledEvents(name='LabeledEvents', description='behavioral events of the experimental paradigm', timestamps=[1, 2, 3], data=[2, 1, 0], labels=['a', 'b', 'c']) nwbfile.add_acquisition(labeled_events) filename = 'nwbfile.nwb' with NWBHDF5IO(filename, 'w') as io: io.write(nwbfile) with NWBHDF5IO(filename, 'r') as io: errors = validate(io) print(errors) nwbfile = io.read() print(nwbfile) print(nwbfile.acquisition['LabeledEvents']) ```