Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't scan as many files when checking for multi file dicom #1442

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions sources/dicom/large_image_source_dicom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def _lazyImportPydicom():

if pydicom is None:
import pydicom
return pydicom


def dicom_to_dict(ds, base=None):
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions sources/dicom/large_image_source_dicom/girder_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -46,8 +47,13 @@
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)

Check warning on line 56 in sources/dicom/large_image_source_dicom/girder_source.py

View check run for this annotation

Codecov / codecov/patch

sources/dicom/large_image_source_dicom/girder_source.py#L52-L56

Added lines #L52 - L56 were not covered by tests
filelist = []
folder = Folder().load(self.item['folderId'], force=True)
for item in Folder().childItems(folder):
Expand Down