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]: Reusing data across TimeSeries objects does not seem to work #1765

Closed
3 tasks done
felixp8 opened this issue Aug 23, 2023 · 1 comment · Fixed by #1766
Closed
3 tasks done

[Bug]: Reusing data across TimeSeries objects does not seem to work #1765

felixp8 opened this issue Aug 23, 2023 · 1 comment · Fixed by #1766
Labels
category: bug errors in the code or code behavior priority: low alternative solution already working and/or relevant to only specific user(s)
Milestone

Comments

@felixp8
Copy link

felixp8 commented Aug 23, 2023

What happened?

PyNWB documentation & code seem to suggest that, similar to sharing timestamps between TimeSeries, we can also share data between TimeSeries. Passing a TimeSeries object to the data field of another TimeSeries does not error, but when reading the file back, the data fields don't appear to be linked, though I'd expect that they would be like the timestamps.

Steps to Reproduce

import numpy as np
from pynwb import NWBHDF5IO, NWBFile, TimeSeries
from datetime import datetime
from uuid import uuid4

nwbfile = NWBFile(
    session_description="not a real session",
    identifier=str(uuid4()),
    session_start_time=datetime.now(),
)

timeseries1 = TimeSeries(
    name="timeseries1",
    data=np.random.rand(40),
    unit="n/a",
    timestamps=(np.arange(40) * 1e-2),
)

timeseries2 = TimeSeries(
    name="timeseries2",
    data=timeseries1,
    unit="n/a",
    timestamps=timeseries1,
)

nwbfile.add_acquisition(timeseries1)
nwbfile.add_acquisition(timeseries2)

with NWBHDF5IO('temp.nwb', 'w') as io:
    io.write(nwbfile)

io = NWBHDF5IO('temp.nwb', 'r')
read_nwbfile = io.read()
print(nwbfile.acquisition['timeseries1'].timestamps == nwbfile.acquisition['timeseries2'].timestamps)
print(nwbfile.acquisition['timeseries1'].data == nwbfile.acquisition['timeseries2'].data)
print(nwbfile.acquisition['timeseries1'])
print(nwbfile.acquisition['timeseries2'])

Traceback

True
False
timeseries1 pynwb.base.TimeSeries at 0x140171917956080
Fields:
  comments: no comments
  conversion: 1.0
  data: <HDF5 dataset "data": shape (40,), type "<f8">
  description: no description
  interval: 1
  offset: 0.0
  resolution: -1.0
  timestamp_link: (
    timeseries2 <class 'pynwb.base.TimeSeries'>
  )
  timestamps: <HDF5 dataset "timestamps": shape (40,), type "<f8">
  timestamps_unit: seconds
  unit: n/a
timeseries2 pynwb.base.TimeSeries at 0x140171917958048
Fields:
  comments: no comments
  conversion: 1.0
  data: <HDF5 dataset "data": shape (40,), type "<f8">
  description: no description
  interval: 1
  offset: 0.0
  resolution: -1.0
  timestamps: timeseries1 pynwb.base.TimeSeries at 0x140171917956080
Fields:
  comments: no comments
  conversion: 1.0
  data: <HDF5 dataset "data": shape (40,), type "<f8">
  description: no description
  interval: 1
  offset: 0.0
  resolution: -1.0
  timestamp_link: (
    timeseries2 <class 'pynwb.base.TimeSeries'>
  )
  timestamps: <HDF5 dataset "timestamps": shape (40,), type "<f8">
  timestamps_unit: seconds
  unit: n/a

  timestamps_unit: seconds
  unit: n/a

Operating System

Linux

Python Executable

Python

Python Version

3.10

Package Versions

(run on DANDI hub)
issue_environment.txt

Code of Conduct

@oruebel oruebel added category: bug errors in the code or code behavior priority: low alternative solution already working and/or relevant to only specific user(s) labels Aug 23, 2023
@oruebel oruebel added this to the Next Release milestone Aug 23, 2023
@oruebel
Copy link
Contributor

oruebel commented Aug 23, 2023

Thanks for the bug report. I create a fix for this issue in #1766

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: bug errors in the code or code behavior priority: low alternative solution already working and/or relevant to only specific user(s)
Projects
None yet
2 participants