Skip to content

Log skipped TUH recordings and accept float rates in EEGAbnormalTUAB - #1474

Merged
solarsys merged 7 commits into
sunlabuiuc:masterfrom
AxelNoun:fix/tuh-task-robustness
Nov 21, 2026
Merged

solarsys merged 7 commits into
sunlabuiuc:masterfrom
AxelNoun:fix/tuh-task-robustness

Conversation

@AxelNoun

@AxelNoun AxelNoun commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Contributor: Axel Coiffard-Donaty (@AxelNoun)

Contribution Type: Bug fix

Description:

Part of #1473.

  • Skipped recordings are now reported. EEGEventsTUEV and EEGAbnormalTUAB used to skip a recording they could not read or convert without any message. TUEV also contains linked-ear recordings, which have no EEG XX-REF channels, so they were dropped silently. The skip itself is unchanged, as in the BIOT preprocessing, so the samples produced are the same. A logger.warning now gives the file and the reason.
  • A TUAB recording without one of the 16 electrodes of the bipolar montage is skipped. convert_to_bipolar ran outside the try block, so the missing channel raised a ValueError that stopped set_task. It is now skipped with a warning, like an unreadable recording (suggestion of the AI review).
  • Float sampling rates work. EEGAbnormalTUAB used fs * 10 as a slice index, so a float resample_rate (the parameter is typed float) raised TypeError: slice indices must be integers. The window length is now an int.
  • Docstrings:
    • TUEV resamples to resample_rate (200 Hz by default, not 256 Hz);
    • both tasks return torch.FloatTensor signals;
    • offending_channel is the channel number from the .rec file, which indexes the 22-channel TCP montage (0-21), not a row of signal.

No public API change. The samples produced from the recordings that were already processed are unchanged.

Note: #1293 also edits the EEGEventsTUEV docstring. The overlap is a few lines and easy to resolve, whichever PR lands first.

Files to Review:

  • pyhealth/tasks/temple_university_EEG_tasks.py: warnings for skipped recordings, int window length in EEGAbnormalTUAB, docstrings.
  • tests/core/test_tuab.py: float resample_rate (200.0, 256.0), and the warnings for an unreadable file and for a recording missing an electrode.
  • tests/core/test_tuev.py: a -REF recording is used, and a -LE recording is skipped with a warning.

Testing:

  • pytest tests/core/test_tuab.py tests/core/test_tuev.py on Linux: 33 passed, 2 subtests passed.
  • Without the change in temple_university_EEG_tasks.py, the new tests fail: 4 failures, including both float-rate subtests. The test for a missing electrode fails with ValueError: 'EEG T5-REF' is not in list without the last commit.
  • The EEG/signal test subset (19 files) on Linux: 219 passed, 1 skipped (it needs a real download), 0 failed.
  • python tools/check_pr_rules.py --base upstream/master --head HEAD: passed.

Claude helped me with this PR.

EEGEventsTUEV and EEGAbnormalTUAB skipped a recording they could not
read or convert without any message. TUEV also contains linked-ear
recordings, which have no EEG XX-REF channels, so the task drops them
without telling the user. Keep the skip, as the BIOT preprocessing does,
but log a warning with the file and the reason.

EEGAbnormalTUAB used fs * 10 as a slice index, so a float resample_rate
(the parameter is typed float) raised TypeError. Compute the window
length as an int.

Fix the docstrings: TUEV resamples to resample_rate (200 Hz by default,
not 256 Hz), both tasks return torch tensors, and offending_channel
indexes the 22-channel TCP montage of the .rec file, not the 16 rows of
signal.
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Test Coverage

Total: 85.64% (42616 / 49764 lines)

Modified file Coverage Lines
pyhealth/autoimprove/__init__.py 100.00% 10 / 10
pyhealth/autoimprove/llm.py 97.09% 100 / 103
pyhealth/calib/predictionset/__init__.py 100.00% 10 / 10
pyhealth/calib/predictionset/group_conditional.py 95.04% 115 / 121
pyhealth/datasets/__init__.py 100.00% 68 / 68
pyhealth/datasets/cardiology.py 98.61% 71 / 72
pyhealth/datasets/chapman_shaoxing.py 91.45% 107 / 117
pyhealth/datasets/helsinki_neonatal.py 97.06% 66 / 68
pyhealth/datasets/hup_ieeg.py 96.00% 96 / 100
pyhealth/datasets/isic2020.py 96.00% 96 / 100
pyhealth/datasets/meds.py 93.67% 74 / 79
pyhealth/datasets/pad_ufes_20.py 95.89% 70 / 73
pyhealth/datasets/pbc.py 96.77% 30 / 31
pyhealth/datasets/tcga_rna_seq.py 92.31% 24 / 26
pyhealth/metrics/__init__.py 100.00% 16 / 16
pyhealth/metrics/competing_risks.py 97.22% 70 / 72
pyhealth/models/__init__.py 100.00% 87 / 87
pyhealth/models/behrt.py 93.37% 183 / 196
pyhealth/models/bitenet.py 92.96% 251 / 270
pyhealth/models/bulk_rna_bert.py 95.77% 68 / 71
pyhealth/models/clmbr.py 95.70% 289 / 302
pyhealth/models/daft.py 93.64% 221 / 236
pyhealth/models/dearllm.py 93.55% 145 / 155
pyhealth/models/deepsleepnet.py 99.22% 127 / 128
pyhealth/models/descemb.py 91.32% 284 / 311
pyhealth/models/ehr_fm.py 91.95% 297 / 323
pyhealth/models/generators/__init__.py 100.00% 8 / 8
pyhealth/models/generators/tardiff.py 99.56% 226 / 227
pyhealth/models/maestro.py 95.14% 176 / 185
pyhealth/models/neural_fine_gray.py 92.59% 125 / 135
pyhealth/models/sleepkd.py 98.80% 82 / 83
pyhealth/models/udc.py 92.34% 229 / 248
pyhealth/tasks/__init__.py 97.53% 79 / 81
pyhealth/tasks/cardiology_detect.py 100.00% 134 / 134
pyhealth/tasks/chaos_segmentation.py 97.98% 97 / 99
pyhealth/tasks/chapman_shaoxing_classification.py 94.38% 84 / 89
pyhealth/tasks/competing_risks.py 88.46% 46 / 52
pyhealth/tasks/competing_risks_pbc.py 100.00% 56 / 56
pyhealth/tasks/dearllm_mortality.py 98.29% 115 / 117
pyhealth/tasks/ehr_foundation_model.py 94.12% 112 / 119
pyhealth/tasks/ethos_tasks.py 100.00% 86 / 86
pyhealth/tasks/isic2020_melanoma_classification.py 100.00% 12 / 12
pyhealth/tasks/maestro_mortality_mimic4.py 95.00% 38 / 40
pyhealth/tasks/medmod_decompensation_mimic4.py 95.40% 83 / 87
pyhealth/tasks/meds_outcome_tasks.py 100.00% 125 / 125
pyhealth/tasks/pad_ufes_20_classification.py 96.55% 28 / 29
pyhealth/tasks/rsna_pneumonia_classification.py 92.31% 12 / 13
pyhealth/tasks/seizure_detection_helsinki.py 100.00% 149 / 149
pyhealth/tasks/sleep_staging_isruc.py 100.00% 121 / 121
pyhealth/tasks/sleep_staging_v2.py 98.75% 79 / 80
pyhealth/tasks/soz_localization_hup.py 98.96% 190 / 192
pyhealth/tasks/survival_time_to_event.py 95.10% 136 / 143
pyhealth/tasks/tcga_survival_prediction.py 84.21% 48 / 57
pyhealth/tasks/temple_university_EEG_tasks.py 82.49% 146 / 177

Workflow run · 1e9638a

Copy link
Copy Markdown
Collaborator

/review


Generated by Claude Code

@solarsys solarsys added the status: automatic The PR will go through automatic review process. label Nov 16, 2026
@solarsys

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

Reviewed commit 560d5c0

github-actions[bot]
github-actions Bot previously approved these changes Nov 16, 2026

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

AI Review

suggestion: approve
decision: approve

Thank you for this contribution. It makes skipped TUEV and TUAB recordings visible through logged warnings and fixes the TypeError that a float resample_rate caused in EEGAbnormalTUAB. The docstring corrections are also useful.

The change stays inside the two task classes and doesn't touch shared code. The description matches the diff. The new tests cover float rates, the unreadable-file warning, a -REF recording being used, and a -LE recording being skipped with a warning. Coverage of temple_university_EEG_tasks.py is 81.98%, which meets the 80% bar. Whole-repo coverage is 83.31%, which is above the 60% bar. It looks ready to merge.

Optional suggestions:

  • round(fs * 10) shortens the window slightly for non-integer rates such as 200.05. You could note in the docstring that the shape 10 * resample_rate assumes the product is a whole number of samples.
  • In EEGAbnormalTUAB, convert_to_bipolar is outside the try block. A recording missing an electrode would raise instead of being skipped with a warning. This was already the case before your change, so it is fine to leave for a follow-up.

Reviewed commit 560d5c0

Resolve conflicts in the TUAB and TUEV tests by keeping both the new robustness tests and the metadata cache tests from sunlabuiuc#1470.
The window is round(10 * resample_rate) samples, so it is exactly 10 s only when that product is a whole number.
convert_to_bipolar ran outside the try block, so a recording without one
of the 16 EEG XX-REF electrodes raised a ValueError and stopped set_task.
It is now skipped with a warning, like an unreadable recording.
@AxelNoun

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

Reviewed commit 1af4ac3

github-actions[bot]
github-actions Bot previously approved these changes Nov 18, 2026

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

AI Review

suggestion: approve
decision: approve

Thank you for this contribution, Axel. It makes skipped TUEV and TUAB recordings visible through warnings. It also skips TUAB recordings that lack one of the 16 electrodes instead of crashing, lets EEGAbnormalTUAB accept float resample rates, and fixes several docstrings. The change stays inside the two self-contained task classes. It adds no new links between components, and the tests match the described behavior. It looks ready to merge.

Coverage: temple_university_EEG_tasks.py is at 82.39%, above the 80% bar. The whole repository is at 84.95%, above the 60% bar.

Optional suggestions:

  • The TUEV docstring says the signal shape is (16, 5 * resample_rate). That isn't exact for non-integer rates, because BuildEvents uses int(fs). You could add a short note like the one in the TUAB docstring.
  • The missing-electrode warning shows Python's raw "'EEG T5-REF' is not in list" text. A message that names the missing channel directly would read more clearly.

Reviewed commit 1af4ac3

The warning for a TUAB recording without an electrode of the bipolar
montage now names the missing channels instead of quoting list.index.
The EEGEventsTUEV docstring states that resample_rate has to be a whole
number of Hz, since BuildEvents sizes the windows with int().

Copy link
Copy Markdown
Collaborator

/review


Generated by Claude Code

github-actions[bot]
github-actions Bot previously approved these changes Nov 19, 2026

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

AI Review

suggestion: approve
decision: approve

Thank you for this contribution. Skipped TUEV and TUAB recordings are now logged with the file and the reason. A TUAB recording that lacks one of the 16 bipolar electrodes is now skipped instead of stopping set_task. EEGAbnormalTUAB also accepts float resample_rate values, and the docstrings are corrected. It looks ready to merge.

The change stays inside the two self-contained task classes in temple_university_EEG_tasks.py. It adds no cross-component sharing. The tests cover float rates, the unreadable-file warning, the missing-electrode skip, and TUEV -REF and -LE recordings. Coverage for the modified file is 82.49%, which meets the 80% bar. Total repository coverage is 85.08%, above the 60% bar.

Optional suggestions:

  • The TUEV docstring says resample_rate must be a whole number of Hz, but the code doesn't enforce it. You could raise a clear error in __init__, or leave it documented as it is.
  • The TUAB docstring shape round(10 * resample_rate) could be made simpler. For example, state that integer rates give (16, 10 * resample_rate).

Reviewed commit fcad8a7

@solarsys

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

Reviewed commit 5fd6efe

github-actions[bot]
github-actions Bot previously approved these changes Nov 19, 2026

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous review

AI Review

suggestion: approve
decision: approve

Thank you for this contribution, Axel. It makes skipped TUEV and TUAB recordings visible through warnings. It also skips TUAB recordings that lack one of the 16 bipolar electrodes, so they no longer abort set_task. And it fixes float resample_rate handling in EEGAbnormalTUAB.

It looks ready to merge. The change stays inside the two self-contained task classes and a module-level logger. The tests cover float rates, unreadable files, a missing electrode, and TUEV -REF versus -LE recordings. Coverage for temple_university_EEG_tasks.py is 82.49%, above the 80% bar, and total repository coverage is 85.11%, above the 60% bar. The description matches the diff, and no components are shared.

Optional suggestions:

  • When several electrodes are missing, the TUAB warning reads "it has no A, B channel". Wording like "it has no A, B channels" would read better.
  • The TUEV docstring shape (16, 5 * resample_rate) assumes an integer rate. You already note this, but you could also say it in the shape line itself.

Reviewed commit 5fd6efe

The warning now reads "channels" when several electrodes are missing,
with a test for that case. The TUEV signal shape line also states that
resample_rate must be a whole number of Hz.

Copy link
Copy Markdown
Collaborator

/review


Generated by Claude Code

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit 1e9638a

- "signal": np.ndarray, shape (16, 256*5)
- "offending_channel": int
- "signal": torch.FloatTensor, shape (16, 5 * resample_rate), with
``resample_rate`` a whole number of Hz. ``BuildEvents`` sizes the windows with ``int(resample_rate)``, so

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] Garbled, duplicated sentence in EEGEventsTUEV docstring

The "signal" entry says the same thing twice in one line: the first half is "with resample_rate a whole number of Hz" and the second half is "BuildEvents sizes the windows with int(resample_rate), so resample_rate has to be a whole number of Hz." The line is also far too long. Merge these into one short sentence, for example: "signal: torch.FloatTensor, shape (16, 5 * resample_rate). BuildEvents uses int(resample_rate) for the window size, so use a whole-number rate."

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review

suggestion: approve
decision: approve

Thank you for this contribution, Axel. Skipped TUEV and TUAB recordings now log a warning, and a TUAB recording missing one of the 16 electrodes is skipped instead of stopping set_task. A float resample_rate also works in EEGAbnormalTUAB. The change looks ready to merge.

  • Scope: The change stays inside the two task classes. It adds no new links between components and doesn't alter any shared code or public API. For integer rates, the output samples are the same as before.
  • Tests: The new tests cover float rates (200.0 and 256.0), the unreadable-file warning, and the missing-electrode warnings (one electrode and several). They also cover TUEV, where a -REF recording is used and a -LE recording is skipped with a warning.
  • Coverage: temple_university_EEG_tasks.py is at 82.49%, above the 80% bar. The whole repository is at 85.64%, above the 60% bar.

Optional suggestions:

  • The EEGEventsTUEV docstring now says the same thing twice: "with resample_rate a whole number of Hz" and "resample_rate has to be a whole number of Hz". You could keep one of the two sentences and wrap the line.
  • The TUAB docstring says "round(10 * resample_rate)" samples for non-integer rates, while the code uses round(fs * 10). These are equivalent, so it's fine as is.

Reviewed commit 1e9638a

@solarsys
solarsys merged commit 6723b97 into sunlabuiuc:master Nov 21, 2026
2 checks passed
@AxelNoun
AxelNoun deleted the fix/tuh-task-robustness branch November 22, 2026 11:39
AxelNoun added a commit to AxelNoun/PyHealth that referenced this pull request Nov 24, 2026
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
solarsys pushed a commit that referenced this pull request Nov 27, 2026
)

* 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 #1474 did with round(10 * fs) for TUAB. At an
integer rate the windows are unchanged.

Fixes #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).
NathanCYee pushed a commit to NathanCYee/PyHealth that referenced this pull request Nov 28, 2026
…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: automatic The PR will go through automatic review process.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants