Repository navigation
Size TUEV event windows with round() so float resample rates work - #1600
Conversation
BuildEvents sized its buffer with int(fs) * 5 and sliced from start - 2*int(fs) to end + 2*int(fs). At a non-integer rate the two lengths differ and the assignment raised a broadcast ValueError, which stopped set_task because BuildEvents runs outside the try in __call__. The window is now round(5 * fs) samples starting round(2 * fs) samples before the event onset, as sunlabuiuc#1474 did with round(10 * fs) for TUAB. At an integer rate the windows are unchanged. Fixes sunlabuiuc#1522
Test CoverageTotal: 86.66% (48004 / 55396 lines)
|
|
/review |
| chan = int(EventData[i, 0]) | ||
| start = np.where((times) >= EventData[i, 1])[0][0] | ||
| end = np.where((times) >= EventData[i, 2])[0][0] | ||
| first = offset + start - pre |
There was a problem hiding this comment.
Done in 7389ffa. The docstring now says that the window length is fixed and that the end time in the .rec file is not used. test_window_length_does_not_depend_on_the_event_end pins this on a 2 s event; it fails on master, where that event raised the broadcast ValueError.
There was a problem hiding this comment.
Previous review
AI Review
suggestion: approve
decision: approve
Thank you for this fix, Axel. Sizing the TUEV event windows with round() stops BuildEvents from crashing at non-integer resample rates, and it matches the approach used for TUAB.
The change looks ready to merge. The window is round(5 * fs) samples, starting round(2 * fs) samples before the onset. At integer rates it gives the same slice as before for 1 s events, and a test pins that. The new tests cover several float rates, the 2 s pre-event offset, and an end-to-end call run. The docstring matches the code. Coverage is 82.68% for the modified file and 86.23% for the whole repository, which meets the bar.
Optional suggestions:
- Events whose duration is not 1 s used to raise a broadcast ValueError. They now silently produce a fixed 5 s window around the onset. A sentence in the description or docstring about this would make the behaviour change explicit.
Reviewed commit b07b1e7
The window is round(5 * fs) samples from 2 s before the onset, so the end time in the .rec file is no longer used. Say so in the docstring and pin it with a test on a 2 s event, which the old slicing rejected with a broadcast ValueError. Nested with statements in the tests of this PR are merged into one (ruff SIM117).
| chan = int(EventData[i, 0]) | ||
| start = np.where((times) >= EventData[i, 1])[0][0] | ||
| end = np.where((times) >= EventData[i, 2])[0][0] | ||
| first = offset + start - pre |
There was a problem hiding this comment.
Done in 7389ffa. The docstring now says that the window length is fixed and that the end time in the .rec file is not used. test_window_length_does_not_depend_on_the_event_end pins this on a 2 s event; it fails on master, where that event raised the broadcast ValueError.
|
/review |
| chan = int(EventData[i, 0]) | ||
| start = np.where((times) >= EventData[i, 1])[0][0] | ||
| end = np.where((times) >= EventData[i, 2])[0][0] | ||
| first = offset + start - pre |
There was a problem hiding this comment.
[low] Event duration is no longer checked; non-1 s events are silently windowed
Before this change, an event whose .rec end time was not exactly one resample period after its onset made the slice length differ from the buffer, so BuildEvents raised a ValueError. The new code always takes a fixed window from the onset and ignores EventData[i, 2], so such events are now accepted without any warning, and the label may refer to a span the window does not contain. The docstring says the end time is not used, and BIOT does the same, so this is a conscious choice. Consider either logging a warning when the .rec duration differs from 1 s, or stating in the PR description that TUEV events are assumed to be 1 s long.
There was a problem hiding this comment.
Left as is. The previous code accepted only 1 s events: any other duration raised the broadcast ValueError and stopped set_task, so no TUEV run that worked before had such an event. The fixed 5 s window from the onset is the option agreed in #1522, and the docstring states that the end time is not used.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: approve
Thank you for this fix. Sizing the TUEV event windows with round() makes EEGEventsTUEV.BuildEvents work at non-integer resample rates, and it matches what #1474 did for TUAB.
The change looks ready to merge.
- Scope: It is confined to the self-contained EEGEventsTUEV task. It doesn't touch base classes or shared utilities, and it adds no links between components.
- Behavior: At integer rates the window is the same as the old slice for 1 s events. A test pins this.
- Tests: The new tests cover non-integer rates, where the window starts, a 2 s event, and
__call__end to end at 256.5 Hz. - Coverage: The whole repository is at 86.66%, above the 60% bar.
temple_university_EEG_tasks.pyis at 82.68%, above the 80% bar. - Docs: The docstring matches the new code.
Optional suggestions:
- Events longer or shorter than 1 s used to raise an error at integer rates. They are now accepted silently, with a fixed 5 s window. The docstring says so. You could also log a warning when the event duration isn't about 1 s.
Reviewed commit 7389ffa
…nlabuiuc#1600) * Size TUEV event windows with round() so float resample rates work BuildEvents sized its buffer with int(fs) * 5 and sliced from start - 2*int(fs) to end + 2*int(fs). At a non-integer rate the two lengths differ and the assignment raised a broadcast ValueError, which stopped set_task because BuildEvents runs outside the try in __call__. The window is now round(5 * fs) samples starting round(2 * fs) samples before the event onset, as sunlabuiuc#1474 did with round(10 * fs) for TUAB. At an integer rate the windows are unchanged. Fixes sunlabuiuc#1522 * Document that TUEV windows ignore the event end time The window is round(5 * fs) samples from 2 s before the onset, so the end time in the .rec file is no longer used. Say so in the docstring and pin it with a test on a 2 s event, which the old slicing rejected with a broadcast ValueError. Nested with statements in the tests of this PR are merged into one (ruff SIM117).
Contributor: Axel Coiffard-Donaty (@AxelNoun)
Contribution Type: Bug fix
Fixes #1522.
Problem
EEGEventsTUEV.BuildEventssized its buffer withint(fs) * 5and sliced the signal fromstart - 2*int(fs)toend + 2*int(fs). At a non-integerresample_rate(documented as a float), the two lengths differ and the assignment raises a broadcastValueError.BuildEventsruns outside thetryin__call__, so the error stopsset_task.Change
As agreed in the issue (option 1), and like #1474 did for TUAB with
round(10 * fs):round(5 * fs)samples, startinground(2 * fs)samples before the event onset;At an integer rate the windows are the same as before: a TUEV event lasts 1 s, so
[start - 2 fs, end + 2 fs)and[start - 2 fs, start - 2 fs + 5 fs)are the same slice. A test pins this.Tests
New
TestEEGEventsTUEVFloatResampleRateintests/core/test_tuev.py:(16, round(5 * fs))windows;__call__runs end to end at 256.5 Hz.Six of these checks fail on master and pass with the change.
tests/core/test_tuev.pyandtests/core/test_tuab.py: 38 passed.python tools/check_pr_rules.py --base master --head HEADpasses.This branch and the one for #1521 touch the same file in different places; I checked that they merge together cleanly (46 tests pass on the merge).
Files to Review
pyhealth/tasks/temple_university_EEG_tasks.py:EEGEventsTUEV.BuildEventsand the class docstring.tests/core/test_tuev.py: the new test class.