-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix reading file with linked TimeSeriesReferenceVectorData (#1865)
- Loading branch information
Showing
3 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
from pynwb.base import TimeSeriesReference | ||
from pynwb import NWBHDF5IO | ||
from pynwb.testing import TestCase | ||
from pynwb.testing.mock.file import mock_NWBFile | ||
from pynwb.testing.mock.base import mock_TimeSeries | ||
|
||
|
||
class TestFileCopy(TestCase): | ||
|
||
def setUp(self): | ||
self.path1 = "test_a.h5" | ||
self.path2 = "test_b.h5" | ||
|
||
def tearDown(self): | ||
if os.path.exists(self.path1): | ||
os.remove(self.path1) | ||
if os.path.exists(self.path2): | ||
os.remove(self.path2) | ||
|
||
def test_copy_file_link_timeintervals_timeseries(self): | ||
"""Test copying a file with a TimeSeriesReference in a TimeIntervals object and reading that copy. | ||
Based on https://github.com/NeurodataWithoutBorders/pynwb/issues/1863 | ||
""" | ||
new_nwb = mock_NWBFile() | ||
test_ts = mock_TimeSeries(name="test_ts", timestamps=[1.0, 2.0, 3.0], data=[1.0, 2.0, 3.0]) | ||
new_nwb.add_acquisition(test_ts) | ||
new_nwb.add_trial(start_time=1.0, stop_time=2.0, timeseries=[test_ts]) | ||
|
||
with NWBHDF5IO(self.path1, 'w') as io: | ||
io.write(new_nwb) | ||
|
||
with NWBHDF5IO(self.path1, 'r') as base_io: | ||
# the TimeIntervals object is copied but the TimeSeriesReferenceVectorData is linked | ||
nwb_add = base_io.read().copy() | ||
with NWBHDF5IO(self.path2, 'w', manager=base_io.manager) as out_io: | ||
out_io.write(nwb_add) | ||
|
||
with NWBHDF5IO(self.path2, 'r') as io: | ||
nwb = io.read() | ||
ts_val = nwb.trials["timeseries"][0][0] | ||
assert isinstance(ts_val, TimeSeriesReference) | ||
assert ts_val.timeseries is nwb.acquisition["test_ts"] |