From 3beb58513452e8ad2625545879ff316132ce557d Mon Sep 17 00:00:00 2001 From: David Manthey Date: Mon, 15 Jan 2024 10:16:01 -0500 Subject: [PATCH] Speed up dicom adjacent file detection when it doesn't succeed --- CHANGELOG.md | 2 +- sources/dicom/large_image_source_dicom/__init__.py | 9 ++++++--- tox.ini | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 582bc9033..1cd929666 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ ### Improvements - Read config values from the environment variables ([#1422](../../pull/1422)) - Optimizing when reading arrays rather than images from tiff files ([#1423](../../pull/1423)) -- Better filter DICOM adjacent files to ensure they share series instance IDs ([#1424](../../pull/1424)) +- Better filter DICOM adjacent files to ensure they share series instance IDs ([#1424](../../pull/1424), [#1436](../../pull/1436)) - Optimizing small getRegion calls and some tiff tile fetches ([#1427](../../pull/1427)) - Started adding python types to the core library ([#1432](../../pull/1432), [#1433](../../pull/1433)) - Use parallelism in computing tile frames ([#1434](../../pull/1434)) diff --git a/sources/dicom/large_image_source_dicom/__init__.py b/sources/dicom/large_image_source_dicom/__init__.py index 11a3146a6..32d714530 100644 --- a/sources/dicom/large_image_source_dicom/__init__.py +++ b/sources/dicom/large_image_source_dicom/__init__.py @@ -242,9 +242,12 @@ def _pathMightBeDicom(self, path, basepath=None): if mightbe and basepath: try: _lazyImportPydicom() - base_series_uid = pydicom.filereader.dcmread( - basepath, stop_before_pixels=True, - )[pydicom.tag.Tag('SeriesInstanceUID')].value + base = pydicom.filereader.dcmread(basepath, stop_before_pixels=True) + except Exception as exc: + msg = f'File cannot be opened via dicom tile source ({exc}).' + raise TileSourceError(msg) + try: + base_series_uid = base[pydicom.tag.Tag('SeriesInstanceUID')].value except Exception: base_series_uid = None if base_series_uid: diff --git a/tox.ini b/tox.ini index e5d2dd851..ae73d6fbf 100644 --- a/tox.ini +++ b/tox.ini @@ -90,7 +90,7 @@ deps = allowlist_externals = {[testenv:test]allowlist_externals} commands = rm -rf build/test/coverage/web_temp - rm ./monkeytype.sqlite3 + -rm ./monkeytype.sqlite3 girder build --dev pytest --numprocesses 0 -m 'not notebook' --no-cov --suppress-no-test-exit-code --monkeytype-output=./monkeytype.sqlite3 {posargs} - npx nyc report --temp-dir build/test/coverage/web_temp --report-dir build/test/coverage --reporter cobertura --reporter text-summary