Repository navigation
Description
Summary
SHHSDataset (pyhealth/datasets/shhs.py) still subclasses the 1.x stub
BaseSignalDataset and defines no __init__. The stub only emits a
DeprecationWarning, so root, dev and filepath are never set, and the
first call to process_EEG_data() raises AttributeError. The class cannot be
used at all on master. #1201 records this in its Group A table; #1451 makes
the failure explicit and notes that porting the remaining 1.x datasets is
separate work.
I propose to port SHHS to the 2.0 API, as tracked in #340, following TUEVDataset
as the reference port. This is engineering bounty E3. It mirrors #1468
(ISRUC), the other sleep-staging port in flight.
Dataset
- Name: Sleep Heart Health Study (SHHS), visits 1 and 2 (NSRR).
- Source: https://sleepdata.org/datasets/shhs
- References: Quan SF et al., "The Sleep Heart Health Study: design,
rationale, and methods", Sleep 20(12), 1997; Redline S et al., "Methods for
obtaining and analyzing unattended polysomnography data for a multicenter
study", Sleep 21(7), 1998. - Access: restricted. An NSRR account plus an approved data access request
(manual approval). Download via the NSRR CLI (gem install nsrr, then
nsrr download shhs/polysomnography). Data are not redistributable. - Content: overnight polysomnography, 6,441 participants at visit 1 and
3,295 re-studied at visit 2. Each recording is scored in 30 s epochs with
stages 0-4 (W, N1, N2, N3, REM). - Size: hundreds of GB.
dev=Trueshould remain the documented path for a
first run.
Current state
SHHSDatasethas no__init__.process_EEG_data()readsself.root,
self.devandself.filepath, none of which exist.process_EEG_data()returns the 1.x shape, a dict of
patient_id -> [{"load_from_path", "signal_file", "label_file", "save_to_path"}],
whichBaseDataset.set_task()does not consume.sleep_staging_shhs_fn(pyhealth/tasks/sleep_staging.py) is a plain
function that writes one pickle per epoch and returnsepoch_path. It
hardcodesSAMPLE_RATE = 125, returns labels as strings"0"-"4", and
selects channels positionally (X[[2, 7]]after dropping rows by index for
the 15- and 16-channel layouts).- The class docstring example calls
dataset.stat()anddataset.info().
BaseDatasetprovidesstats(); neither name is correct as written. - Suspected path bug: shhs2 annotation files are looked up under
annotations-events-profusion/label/shhs2-{pid}-profusion.xml, while shhs1
uses theshhs1/sibling. The published NSRR layout hasshhs1/and
shhs2/. I will confirm against the released data and report the result.
Proposed change
Following the pattern of TUEVDataset / SleepEDFDataset:
pyhealth/datasets/shhs.py:SHHSDataset(BaseDataset)with- a YAML config (
configs/shhs.yaml), one table per visit; - a metadata CSV (one row per recording: visit, participant, signal file,
annotation file) written through the helpers inmetadata_csv.py, so a
read-only root and a non-writablerootare handled; - a
prepare_metadata()that is idempotent and skips already-listed files; - a "Getting the data" section in the class docstring, already present, kept
as is; default_taskreturning the new task.
- a YAML config (
pyhealth/tasks/sleep_staging_shhs.py: aSleepStagingSHHS(BaseTask),
modeled onSleepStagingSleepEDF, with options forepoch_seconds(default 30, the scoring resolution);- which channels to use, by name;
- stage mapping to W/N1/N2/N3/REM, with unmapped or unscored labels dropped
and counted in a log message rather than silently; - labels emitted as
int, sincemulticlasscannot consume"0"-"4".
- Tests (
tests/core/): synthetic EDF and annotation fixtures built in the
test, no network access. They check metadata construction, epoch count and
label alignment, the channel-missing path, unmapped-label handling, and a
non-writable root.tests/core/test_sleep_staging_shhs.pyalready covers the
XML parser and channel selection and will be updated rather than replaced. - Docs and example: a task page under
docs/api/tasks/, an entry in
docs/api/tasks.rst, and the existing
examples/eeg/sleep_staging/sleep_staging_shhs_contrawr.pyupdated for the
2.0 task (it passesrefresh_cache, a 1.x keyword that no longer exists).
No change to BaseDataset, the Trainer or other shared code.
Points I would like maintainers to confirm
patient_idacross visits. SHHS visit 2 re-studies 3,295 of the visit 1
participants, so a numeric participant id groups two recordings under one
Patient. Shouldpatient_idbe the numeric participant (200001, two
events) or visit-qualified (shhs1-200001, one recording per patient)? The
former avoids the same participant landing on both sides of a split; the
latter matches the 1.xepoch_pathnaming. I lean to the numeric id.- Signal units.
mnereturns volts.EEGEventsTUEVreads in microvolts.
Should the SHHS task emit microvolts for consistency with TUEV? - Channel selection. Name-based selection with a documented positional
fallback, or keep the 1.xX[[2, 7]]? The 1.x indices assume a specific
montage order that I would like to verify on the released files first. epoch_seconds. The 1.x function accepts it but silently misaligns
labels for anything other than 30, since the annotations are 30 s. Should the
2.0 task restrict it to divisors of 30, as Port ISRUCDataset to the PyHealth 2.0 dataset API (part of #340) #1468 proposes for ISRUC?- Scope. Whether to keep
sleep_staging_shhs_fnimportable as
documented-deprecated (as done for the legacy drug-recommendation functions
in Add DrugRecommendationOMOP task #1203), or replace it outright. I lean to keeping it, with the docs
stating it cannot run throughset_task().
The epoch and task structure overlaps #1468's SleepStagingISRUC. I am happy
to build on whatever shape that PR settles on, or to have both share a common
epoch-extraction helper, if that is preferred over two similar tasks.
I will verify the on-disk layout (file names, annotation format, channel names,
the shhs2 label/ path above) on the released data before writing the
fixtures, and report any discrepancy with the 1.x loader in the PR.
I am picking up E3 from the bounty list and will open a draft PR that links this
issue.
Activity
solarsys commentedon Nov 16, 2026
Related: #1425 adds a new
NSRRSleepDataset(pyhealth/datasets/nsrr_sleep.py) that reads SHHS and MESA for cardio-respiratory sleep staging. It doesn't port the existingSHHSDataset, but the two overlap in what they load, so it's worth checking whether this port should share config or tests with it, or stay separate.[BTY-23] Port SHHSDataset to the PyHealth 2.0 BaseDataset
Port SHHSDataset to the 2.0 BaseDataset API
Add SleepStagingSHHS(BaseTask) for the 2.0 SHHS dataset
Test and document the SHHS 2.0 dataset and task
Port SHHSDataset to the 2.0 BaseDataset API
Add SleepStagingSHHS(BaseTask) for the 2.0 SHHS dataset
Test and document the SHHS 2.0 dataset and task