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

[Bug]: Fail to read NWB file where TimeZone is missing from session_start_time #2054

Open
3 tasks done
ehennestad opened this issue Mar 5, 2025 · 1 comment · May be fixed by #2056
Open
3 tasks done

[Bug]: Fail to read NWB file where TimeZone is missing from session_start_time #2054

ehennestad opened this issue Mar 5, 2025 · 1 comment · May be fixed by #2056
Labels
category: proposal proposed enhancements or new features priority: low alternative solution already working and/or relevant to only specific user(s)

Comments

@ehennestad
Copy link

ehennestad commented Mar 5, 2025

What happened?

Not sure if this is a bug, but it seems strict to enforce TimeZone on read.

Steps to Reproduce

In MATLAB:

nwb = NwbFile( ...
    'session_description', 'Simple demo file', ...
    'identifier', 'test_file', ...
    'session_start_time', datetime("now"), ...
    'timestamps_reference_time', datetime("now"));
nwbExport(nwb, 'temp.nwb')

In python:

from pynwb import NWBHDF5IO

io = NWBHDF5IO('temp.nwb', mode="r")
nwbfile = io.read()

Traceback

Error using objectmapper>construct
Python Error: ConstructError: (root GroupBuilder {'attributes': {'namespace': 'core', 'neurodata_type': 'NWBFile', 'nwb_version': '2.8.0',
'object_id': 'ad86c34b-4de3-4352-a698-d112fe26f032'}, 'groups': {'acquisition': root/acquisition GroupBuilder {'attributes': {}, 'groups': {},
'datasets': {}, 'links': {}}, 'analysis': root/analysis GroupBuilder {'attributes': {}, 'groups': {}, 'datasets': {}, 'links': {}}, 'general':
root/general GroupBuilder {'attributes': {}, 'groups': {'devices': root/general/devices GroupBuilder {'attributes': {}, 'groups': {},
'datasets': {}, 'links': {}}, 'extracellular_ephys': root/general/extracellular_ephys GroupBuilder {'attributes': {}, 'groups': {},
'datasets': {}, 'links': {}}, 'intracellular_ephys': root/general/intracellular_ephys GroupBuilder {'attributes': {}, 'groups': {},
'datasets': {}, 'links': {}}, 'optogenetics': root/general/optogenetics GroupBuilder {'attributes': {}, 'groups': {}, 'datasets': {}, 'links':
{}}, 'optophysiology': root/general/optophysiology GroupBuilder {'attributes': {}, 'groups': {}, 'datasets': {}, 'links': {}}}, 'datasets':
{}, 'links': {}}, 'intervals': root/intervals GroupBuilder {'attributes': {}, 'groups': {}, 'datasets': {}, 'links': {}}, 'processing':
root/processing GroupBuilder {'attributes': {}, 'groups': {}, 'datasets': {}, 'links': {}}, 'scratch': root/scratch GroupBuilder
{'attributes': {}, 'groups': {}, 'datasets': {}, 'links': {}}, 'stimulus': root/stimulus GroupBuilder {'attributes': {}, 'groups':
{'presentation': root/stimulus/presentation GroupBuilder {'attributes': {}, 'groups': {}, 'datasets': {}, 'links': {}}, 'templates':
root/stimulus/templates GroupBuilder {'attributes': {}, 'groups': {}, 'datasets': {}, 'links': {}}}, 'datasets': {}, 'links': {}}},
'datasets': {'file_create_date': root/file_create_date DatasetBuilder {'attributes': {}, 'data': <StrDataset for HDF5 dataset
"file_create_date": shape (1,), type "|O">}, 'identifier': root/identifier DatasetBuilder {'attributes': {}, 'data': 'test_file'},
'session_description': root/session_description DatasetBuilder {'attributes': {}, 'data': 'Simple demo file'}, 'session_start_time':
root/session_start_time DatasetBuilder {'attributes': {}, 'data': '2025-03-05T15:08:07.380042'}, 'timestamps_reference_time':
root/timestamps_reference_time DatasetBuilder {'attributes': {}, 'data': '2025-03-05T15:08:07.380880'}}, 'links': {}}, "Could not construct
NWBFile object due to: 'timestamps_reference_time' must be a timezone-aware datetime object.")

Operating System

macOS

Python Executable

Python

Python Version

3.9

Package Versions

No response

Code of Conduct

@stephprince
Copy link
Contributor

stephprince commented Mar 6, 2025

I think in this particular case it would be ok to give a warning about the timestamps_reference_time on read, and error only when creating a new NWBFile without a timezone-aware timestamps_reference_time. However, I am not sure if there are additional downstream implications.

@rly do you have any thoughts? I know at one point timestamps_reference_time was going to be allowed to be timezone-naive in general, but that change had to be reverted in #1908 and was part of other timezone related changes

@stephprince stephprince added category: proposal proposed enhancements or new features priority: low alternative solution already working and/or relevant to only specific user(s) labels Mar 6, 2025
@stephprince stephprince linked a pull request Mar 10, 2025 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: proposal proposed enhancements or new features priority: low alternative solution already working and/or relevant to only specific user(s)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants