Skip to content

Commit

Permalink
Fixes (#146)
Browse files Browse the repository at this point in the history
* Add KeyError catch

* Allow missing ExtendedDepthOfField

* Lazy-load pyramid metadata
  • Loading branch information
erikogabrielsson committed Jan 12, 2024
1 parent 4b1c61f commit b7d5003
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.18.2] - 2023-11-12

### Fixed

- Missing KeyError in exception catch for Pyramid.get(), that made getting image data for non-existing levels (by downscaling) not work.
- Handle loading metadata if `ExtendedDepthOfField` not set.
- Metadata for pyramid is now lazy loaded.

## [0.18.1] - 2023-11-12

### Fixed
Expand Down Expand Up @@ -294,8 +302,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial release of wsidicom

[Unreleased]: https://github.com/imi-bigpicture/wsidicom/compare/0.18.1..HEAD
[0.18.1]: https://github.com/imi-bigpicture/wsidicom/compare/v0.18.1..v0.18.1
[Unreleased]: https://github.com/imi-bigpicture/wsidicom/compare/0.18.2..HEAD
[0.18.2]: https://github.com/imi-bigpicture/wsidicom/compare/v0.18.1..v0.18.2
[0.18.1]: https://github.com/imi-bigpicture/wsidicom/compare/v0.18.0..v0.18.1
[0.18.0]: https://github.com/imi-bigpicture/wsidicom/compare/v0.17.0..v0.18.0
[0.17.0]: https://github.com/imi-bigpicture/wsidicom/compare/v0.16.0..v0.17.0
[0.16.0]: https://github.com/imi-bigpicture/wsidicom/compare/v0.15.2..v0.16.0
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "wsidicom"
version = "0.18.1"
version = "0.18.2"
description = "Tools for handling DICOM based whole scan images"
authors = ["Erik O Gabrielsson <erik.o.gabrielsson@sectra.com>"]
license = "Apache-2.0"
Expand Down
9 changes: 7 additions & 2 deletions tests/metadata/dicom_schema/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
from wsidicom.metadata.schema.dicom.slide import SlideDicomSchema


@pytest.fixture()
def valid_dicom():
yield True


@pytest.fixture()
def dicom_equipment(equipment: Equipment):
dataset = Dataset()
Expand All @@ -57,7 +62,7 @@ def dicom_equipment(equipment: Equipment):


@pytest.fixture()
def dicom_image(image: Image):
def dicom_image(image: Image, valid_dicom: bool):
dataset = Dataset()
dataset.AcquisitionDateTime = DT(image.acquisition_datetime)
if image.focus_method is not None:
Expand All @@ -79,7 +84,7 @@ def dicom_image(image: Image):
dataset.DistanceBetweenFocalPlanes = (
image.extended_depth_of_field.distance_between_focal_planes
)
else:
elif valid_dicom:
dataset.ExtendedDepthOfField = "NO"
if any(
item is not None
Expand Down
1 change: 1 addition & 0 deletions tests/metadata/dicom_schema/test_dicom_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def test_serialize_default_image(self):
[None, None, None, None, None, None, None, None],
],
)
@pytest.mark.parametrize("valid_dicom", [True, False])
def test_deserialize_image(self, dicom_image: Dataset, image: Image):
# Arrange
schema = ImageDicomSchema()
Expand Down
2 changes: 1 addition & 1 deletion wsidicom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
from wsidicom.web import WsiDicomWebClient
from wsidicom.wsidicom import WsiDicom

__version__ = "0.18.1"
__version__ = "0.18.2"
4 changes: 3 additions & 1 deletion wsidicom/metadata/schema/dicom/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ class ImageDicomSchema(ModuleDicomSchema[Image]):
dump_default=Defaults.focus_method,
load_default=None,
)
extended_depth_of_field_bool = BooleanDicomField(data_key="ExtendedDepthOfField")
extended_depth_of_field_bool = BooleanDicomField(
data_key="ExtendedDepthOfField", load_default=False
)
extended_depth_of_field = FlattenOnDumpNestedDicomField(
ExtendedDepthOfFieldDicomSchema(),
allow_none=True,
Expand Down
5 changes: 1 addition & 4 deletions wsidicom/series/pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from typing import Iterable, List, Optional, OrderedDict


from wsidicom.errors import (
WsiDicomNotFoundError,
WsiDicomOutOfBoundsError,
Expand All @@ -24,7 +23,6 @@
from wsidicom.group.level import BaseLevel
from wsidicom.instance import ImageType, WsiInstance
from wsidicom.metadata import ImageCoordinateSystem
from wsidicom.metadata.schema.dicom.wsi import WsiMetadataDicomSchema
from wsidicom.series.series import Series
from wsidicom.stringprinting import list_pretty_str

Expand Down Expand Up @@ -62,7 +60,6 @@ def __init__(self, levels: Iterable[Level]):
'"Volume" type'
)
self._mm_size = mm_size
self._metadata = WsiMetadataDicomSchema().load(self.datasets[0])

def __repr__(self) -> str:
return f"{type(self).__name__}({self._levels})"
Expand Down Expand Up @@ -96,7 +93,7 @@ def get(self, index: int, pyramid_index: bool = True) -> Level:
if pyramid_index:
return self._levels[index]
return self[index]
except IndexError:
except (KeyError, IndexError):
raise WsiDicomNotFoundError(f"Level index {index}", "pyramid")

@property
Expand Down

0 comments on commit b7d5003

Please sign in to comment.