Skip to content

Add check_identical_time_series and check_redundant_time_series_copies - #794

Open
bendichter wants to merge 2 commits into
NeurodataWithoutBorders:devfrom
bendichter:check-identical-time-series
Open

bendichter wants to merge 2 commits into
NeurodataWithoutBorders:devfrom
bendichter:check-identical-time-series

Conversation

@bendichter

Copy link
Copy Markdown
Contributor

Motivation

Before: two TimeSeries in one file can hold identical data without the inspector noticing. Sometimes this is a wrong-data bug, such as an LFP that is really the raw signal written again, and sometimes it is a redundant copy that should have been a link.

After: two checks share one comparison. check_identical_time_series (CRITICAL) covers identical series of different kinds: a processed series identical to one in acquisition, different neurodata types or units, or two constant event-like series that share explicit timestamps under different names. check_redundant_time_series_copies (BEST_PRACTICE_VIOLATION) covers identical series of the same kind, which are more often redundant copies.

The cases come from our Encore project: a reward series identical to a lick series in 000231, and LFP identical to the acquisition signal in 001539 and 000447 (Encore findings for 000231, 001539 and 000447). An example of the second check is 000041, where UPDecompositionSeries and SpindleDecompositionSeries are identical and both descriptions say channel 13.

How

Series are grouped by data shape and dtype, so most pairs never read data. Candidates are then compared on a hash of a 64 KB block at the start, and only series that agree there are hashed in full (up to 32 MB) or on five sampled 1 MB blocks, in which case the message says so. The grouping is computed once per file and cached for the second check. Pairs whose data are the same HDF5 object (a link) are not reported, nor are constant data on a rate-based time base, such as two empty channels.

The two checks have different importance because the same finding can mean different things, and I could not find a cleaner way to express that than splitting by whether the two series are of the same kind.

This is one of seven PRs split out of a single draft that added checks for data stored twice within one NWB file. Each PR stands on its own and branches off dev. They all carry the same copy of a small helper module, utils/_comparison.py (shape and dtype without reading, hashing, sampling blocks of large datasets, counting repeats), so that they can be reviewed and merged in any order. Git merges the identical copies cleanly, and I checked that all seven merge together without conflicts and that the full test suite passes on the result.

Testing

tests/unit_tests/test_identical_time_series.py covers both checks, a link that should not be reported, and the sampled path. On the DANDI files I streamed for the original draft, the CRITICAL check fired on all files in 000231, 001539 and 000447, and the BEST_PRACTICE_VIOLATION check on the Watson files in 000041. The Watson files are the slowest case, at about 25 s each when streamed, mostly hashing sampled blocks of two 1.5 GB series.

🤖 Generated with Claude Code

…pies`

Added `check_identical_time_series` and
`check_redundant_time_series_copies`, which flag TimeSeries in one file
that hold identical data. The first (CRITICAL) covers series of
different kinds, such as a processed series identical to one in
acquisition, and the second (BEST_PRACTICE_VIOLATION) covers redundant
copies of the same kind, which should be stored once and linked. HDF5
links to the same dataset are not reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.72277% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.24%. Comparing base (1aaa570) to head (a6feed6).

Files with missing lines Patch % Lines
src/nwbinspector/utils/_comparison.py 62.79% 32 Missing ⚠️
src/nwbinspector/checks/_time_series.py 88.79% 13 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #794      +/-   ##
==========================================
+ Coverage   86.46%   88.24%   +1.78%     
==========================================
  Files          48       49       +1     
  Lines        2046     2246     +200     
==========================================
+ Hits         1769     1982     +213     
+ Misses        277      264      -13     
Files with missing lines Coverage Δ
src/nwbinspector/checks/__init__.py 100.00% <ø> (ø)
src/nwbinspector/checks/_time_series.py 90.58% <88.79%> (-1.62%) ⬇️
src/nwbinspector/utils/_comparison.py 62.79% <62.79%> (ø)

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants