Skip to content

Add opt in force_read option for non-conformant DICOM files - #132

Open
pradeeppeddineni wants to merge 1 commit into
ImagingDataCommons:masterfrom
pradeeppeddineni:fix/dcmread-force-fallback
Open

pradeeppeddineni wants to merge 1 commit into
ImagingDataCommons:masterfrom
pradeeppeddineni:fix/dcmread-force-fallback

Conversation

@pradeeppeddineni

Copy link
Copy Markdown

Fixes #89

This adds an optional force_read argument to DICOMwebClient (default False) and a set_force_read() method. When it's on, retrieved instances are read with pydicom.dcmread(..., force=True), so files from servers that leave out the preamble and DICM prefix can still be loaded. With the default nothing changes and those files still raise InvalidDicomError.

#96 by @ziqiangxu tried this before by always passing force=True. I went with what @pieper and @CPBridge asked for in that review, an opt in constructor argument plus a setter, same style as permissive_uid and set_chunk_size(). It covers both the multipart response and the single part application/dicom fallback so retrieve_instance, retrieve_series and retrieve_study all get it.

Tests are in tests/test_web.py. they strip the preamble from the test file and check it reads fine with force_read=True (multipart, single part and a series using set_force_read) and still raises by default. The forced ones fail on master and pass now. flake8 and mypy are clean and the full suite passes with pillow<13, on Pillow 13 test_file.py::test_retrieve_instance_frames_rendered fails on master too which #131 fixes.

I didn't add a CLI flag for it, happy to if you want one

Some origin servers send instances without the preamble and DICM prefix,
so pydicom raises InvalidDicomError. Add an optional force_read argument
to DICOMwebClient (default False) and a set_force_read() method, and pass
it on as force to pydicom.dcmread() for retrieved instances.

Fixes ImagingDataCommons#89
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

This branch has not been deployed

No deployments
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.

Allow to set force option of dcmread

1 participant