Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rly opened this issue Jan 22, 2021 · 1 comment

Comments

@rly
Copy link
Owner

rly commented Jan 22, 2021

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`
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
Copy link
Owner Author

rly commented Jan 22, 2021

Thanks to @ttngu207 for the bug report!

@rly rly changed the title Types are missing fields when reading file without first importing package Containers are missing fields after reading file without first importing package Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant