diff --git a/HISTORY.md b/HISTORY.md index d2800bc..4475be0 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,9 @@ # History +## 0.9.1 (2022-07-12) + +* Return a `frozenset` for segments + ## 0.9.0 (2022-07-07) * Add `segments` property to the `PanImg` model containing the unique values in the image as a tuple of `int`s. diff --git a/panimg/models.py b/panimg/models.py index 2024b68..e2318b7 100644 --- a/panimg/models.py +++ b/panimg/models.py @@ -4,7 +4,7 @@ import shutil from enum import Enum from pathlib import Path -from typing import Any, Dict, List, NamedTuple, Optional, Set, Tuple +from typing import Any, Dict, FrozenSet, List, NamedTuple, Optional, Set, Tuple from uuid import UUID, uuid4 import numpy as np @@ -155,7 +155,7 @@ class PanImg: series_instance_uid: str = "" study_description: str = "" series_description: str = "" - segments: Optional[Tuple[int, ...]] = None + segments: Optional[FrozenSet[int]] = None @dataclass(frozen=True) @@ -274,14 +274,14 @@ def add_value_range_meta_data(cls, image: Image): # noqa: B902, N805 return image @property - def segments(self) -> Optional[Tuple[int, ...]]: + def segments(self) -> Optional[FrozenSet[int]]: if self.image.GetPixelIDValue() not in MASK_TYPE_PIXEL_IDS: return None segments = np.unique(GetArrayViewFromImage(self.image)) if len(segments) <= MAXIMUM_SEGMENTS_LENGTH: - return tuple(segments) + return frozenset(segments) else: return None diff --git a/pyproject.toml b/pyproject.toml index 06e8442..2c0fbd0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "panimg" -version = "0.9.0" +version = "0.9.1" description = "Conversion of medical images to MHA and TIFF." license = "Apache-2.0" authors = ["James Meakin "] diff --git a/tests/test_models.py b/tests/test_models.py index 0778069..a94a14d 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -168,28 +168,30 @@ def test_sitk_image_value_range( ( "image_min10_max10.mha", image_builders.image_builder_mhd, - ( - -10, - -9, - -8, - -7, - -6, - -5, - -4, - -3, - -2, - -1, - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, + frozenset( + ( + -10, + -9, + -8, + -7, + -6, + -5, + -4, + -3, + -2, + -1, + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + ) ), ), ( # Too many values