Skip to content
Snippets Groups Projects

Write timestamps to file as dataset attributes along with data

Merged Vincent POLLET requested to merge timestamps_writing into master
3 files
+ 30
4
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 13
2
@@ -38,19 +38,30 @@ def test_stream_write():
np.arange(12 * 52).astype(np.float64).reshape((12, 52)),
]
for a_test_data in test_data:
test_timestamps = [
np.linspace(0, 20*test_data[0].shape[0], test_data[0].shape[0]),
np.linspace(10, 10*test_data[1].shape[0], test_data[1].shape[0]),
np.linspace(100, 200*test_data[2].shape[0], test_data[2].shape[0]),
np.linspace(5, 6*test_data[3].shape[0], test_data[3].shape[0]),
]
for a_test_data, a_test_timestamps in zip(test_data, test_timestamps):
with StreamFile(resource_path("test/data/save_test.h5"), mode="w") as output_file:
stream = Stream("test_data")
save_filter = stream.save(output_file)
for i in range(a_test_data.shape[0]):
stream.put(a_test_data[i])
stream.put(a_test_data[i], a_test_timestamps[i])
with StreamFile(resource_path("test/data/save_test.h5"), mode="r") as input_file:
stream = Stream("test_data", input_file)
data = stream.load()
timestamps = input_file.get_stream_timestamps("test_data")
if np.isscalar(timestamps): # if there is only 1 frame, timestamps are returned as a scalar
timestamps = np.array([timestamps])
assert np.array_equal(data, a_test_data)
assert data.dtype == a_test_data.dtype
assert np.array_equal(timestamps, a_test_timestamps)
os.remove(resource_path("test/data/save_test.h5"))
Loading