NeurodataWithoutBorders / nwbinspector

Tool to help inspect NWB files for compliance with NWB Best Practices
https://nwbinspector.readthedocs.io/
Other
17 stars 10 forks source link

[Add Check]: check timestamps are equal #172

Open bendichter opened 2 years ago

bendichter commented 2 years ago

What would you like to see added to the NWBInspector?

If timestamps are equal between two different TimeSeries, space could be saved by linking from one to another

Pseudocode or other logic of the check

No response

Do you have any interest in helping implement the check function?

No.

Code of Conduct

CodyCBakerPhD commented 2 years ago

@bendichter Are you sure an actual link is formed between the h5py.Dataset objects when you do that? If so do you have some minimal demonstrative code through PyNWB?

I'm trying the following on https://github.com/NeurodataWithoutBorders/nwbinspector/tree/check_timestamps_equal but no luck so far

import pynwb
import numpy as np
from nwbinspector.tools import make_minimal_nwbfile

nwbfile = make_minimal_nwbfile()
nelems = 1000000
time_series_1 = pynwb.TimeSeries(
    name="test_time_series_1", unit="test_units", data=[1, 2, 3], timestamps=np.arange(nelems)
)
time_series_2 = pynwb.TimeSeries(
    name="test_time_series_2", unit="test_units", data=[1, 2, 3], timestamps=time_series_1.timestamps
)
nwbfile.add_acquisition(time_series_1)
nwbfile.add_acquisition(time_series_2)
with pynwb.NWBHDF5IO(path=some_file_path, mode="w") as io:
    io.write(nwbfile)

with pynwb.NWBHDF5IO(path=some_file_path, mode="r") as io:
    nwbfile_in = io.read()

    dataset_level_result = (
        nwbfile_in.acquisition["test_time_series_2"].timestamps == nwbfile_in.acquisition["test_time_series_1"].timestamps 
    )  # False

    array_level_result = np.array_equal(
        nwbfile_in.acquisition["test_time_series_1"].timestamps[:], nwbfile_in.acquisition["test_time_series_2"].timestamps[:]
    )  # True