Skip to content

Fix decoding of SR content items with value type WAVEFORM - #473

Merged
CPBridge merged 1 commit into
ImagingDataCommons:masterfrom
DG47:bugfix/sr-waveform-content-item
Oct 22, 2026
Merged

CPBridge merged 1 commit into
ImagingDataCommons:masterfrom
DG47:bugfix/sr-waveform-content-item

Conversation

@DG47

@DG47 DG47 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #472

WaveformContentItem could be constructed but not decoded, so any SR or Key Object Selection document with a WAVEFORM item in its content tree failed to load.

Changes in src/highdicom/sr/value_types.py:

  • WaveformContentItem.from_dataset() checked the dataset against ValueTypeValues.IMAGE. It now checks against ValueTypeValues.WAVEFORM.
  • ValueTypeValues.WAVEFORM was missing from the tables in _assert_value_type() and _get_content_item_class(), so ContentSequence.from_sequence() raised a KeyError on WAVEFORM items. Both tables now include it. Referenced SOP Sequence is the required attribute, as for IMAGE and COMPOSITE.
  • referenced_waveform_channels read ReferencedFrameNumber and so always returned None. It now reads ReferencedWaveformChannels, the attribute the constructor writes.
  • The type hint for the referenced_waveform_channels constructor parameter now matches the docstring and the implementation (Sequence[tuple[int, int]]). Before, it said int | Sequence[int].

There is no change to the public API.

Tests:

  • tests/test_sr.py: construction with and without channels, from_dataset() for a WAVEFORM dataset, rejection of an IMAGE dataset, and decoding a WAVEFORM item nested in a CONTAINER.
  • tests/test_ko.py: KeyObjectSelection.from_sequence() with a WAVEFORM reference, then get_references(value_type=ValueTypeValues.WAVEFORM).

Five of the six new tests fail on master. The one that passes on master is the test without channels. All six pass with this change.

Validation:

  • pytest tests/test_sr.py tests/test_ko.py -k waveform: 6 passed
  • pytest tests: 2044 passed, 153 skipped
  • flake8 --exclude='bin,build,.eggs,.venv': clean

WaveformContentItem.from_dataset() checked the dataset against value
type IMAGE, so WAVEFORM items were rejected while IMAGE items were
accepted. WAVEFORM was also missing from the lookup tables used by
_assert_value_type() and ContentSequence.from_sequence(), so any SR
or KOS document containing a WAVEFORM item failed with a KeyError when
parsed. The referenced_waveform_channels property read the Referenced
Frame Number attribute instead of Referenced Waveform Channels and
therefore always returned None.

@CPBridge CPBridge left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the help @DG47, no concerns from me

@CPBridge CPBridge added the bug Something isn't working label Oct 21, 2026
@CPBridge
CPBridge merged commit fd5bb8c into ImagingDataCommons:master Oct 22, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SR content items with value type WAVEFORM cannot be decoded

2 participants