diff --git a/CHANGELOG.md b/CHANGELOG.md index cd857ba61..131779763 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), [#1436](../../pull/1436)) +- Better filter DICOM adjacent files to ensure they share series instance IDs ([#1424](../../pull/1424), [#1436](../../pull/1436), [#1442](../../pull/1442)) - 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), [#1437](../../pull/1437), [#1438](../../pull/1438), [#1439](../../pull/1439)) - 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 32d714530..ad3065a5a 100644 --- a/sources/dicom/large_image_source_dicom/__init__.py +++ b/sources/dicom/large_image_source_dicom/__init__.py @@ -53,6 +53,7 @@ def _lazyImportPydicom(): if pydicom is None: import pydicom + return pydicom def dicom_to_dict(ds, base=None): @@ -138,6 +139,12 @@ def __init__(self, path, **kwargs): if not os.path.isfile(path): raise TileSourceFileNotFoundError(path) from None root = os.path.dirname(path) or '.' + try: + _lazyImportPydicom() + pydicom.filereader.dcmread(path, stop_before_pixels=True) + except Exception as exc: + msg = f'File cannot be opened via dicom tile source ({exc}).' + raise TileSourceError(msg) self._largeImagePath = [ os.path.join(root, entry) for entry in os.listdir(root) if os.path.isfile(os.path.join(root, entry)) and diff --git a/sources/dicom/large_image_source_dicom/girder_source.py b/sources/dicom/large_image_source_dicom/girder_source.py index 731e72df8..53491bfd7 100644 --- a/sources/dicom/large_image_source_dicom/girder_source.py +++ b/sources/dicom/large_image_source_dicom/girder_source.py @@ -5,8 +5,9 @@ from girder.models.folder import Folder from girder.models.item import Item from girder.utility import assetstore_utilities +from large_image.exceptions import TileSourceError -from . import DICOMFileTileSource +from . import DICOMFileTileSource, _lazyImportPydicom from .assetstore import DICOMWEB_META_KEY @@ -46,8 +47,13 @@ def _getFilesystemLargeImagePath(self): filelist = [ File().getLocalFilePath(file) for file in Item().childFiles(self.item) if self._pathMightBeDicom(file['name'])] - if len(filelist) > 1: + if len(filelist) != 1: return filelist + try: + _lazyImportPydicom().filereader.dcmread(filelist[0], stop_before_pixels=True) + except Exception as exc: + msg = f'File cannot be opened via dicom tile source ({exc}).' + raise TileSourceError(msg) filelist = [] folder = Folder().load(self.item['folderId'], force=True) for item in Folder().childItems(folder):