rly / ndx-events

NWB extension to store event and TTL pulse data
BSD 3-Clause "New" or "Revised" License
4 stars 7 forks source link

Containers are missing fields after reading file without first importing package #3

Open rly opened 3 years ago

rly commented 3 years ago

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']) ```
rly commented 3 years ago

Thanks to @ttngu207 for the bug report!