From c6398c327695d60d47557a92d5e333f77bc84f18 Mon Sep 17 00:00:00 2001 From: James Meakin <12661555+jmsmkn@users.noreply.github.com> Date: Wed, 19 Jul 2023 10:43:28 +0200 Subject: [PATCH] Fix timepoints determination --- HISTORY.md | 4 ++++ panimg/models.py | 8 +++++--- pyproject.toml | 2 +- tests/resources/image10x11x12x13.mha | Bin 398 -> 420 bytes tests/resources/image10x11x12x13.mhd | 4 ++-- tests/resources/image10x11x12x13.zraw | Bin 39 -> 40 bytes tests/test_background_tasks.py | 1 + tests/test_mhd.py | 4 ++-- tests/test_models.py | 17 +++++++++++++++-- 9 files changed, 30 insertions(+), 10 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 4d900b8..3edc541 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,9 @@ # History +## 0.13.1 (2023-07-19) + +* Fix timepoints determination + ## 0.13.0 (2023-07-17) * Increased maximum number of segments to 64 diff --git a/panimg/models.py b/panimg/models.py index 2f6bca4..1da3842 100644 --- a/panimg/models.py +++ b/panimg/models.py @@ -3,6 +3,7 @@ import re import shutil from enum import Enum +from functools import cached_property from pathlib import Path from typing import Any, Dict, FrozenSet, List, NamedTuple, Optional, Set, Tuple from uuid import UUID, uuid4 @@ -230,8 +231,9 @@ def window_width(self) -> Optional[float]: @property def timepoints(self) -> Optional[int]: - if self.image.GetDimension() == 4: - return int(self.image.GetSize()[-1]) + if self.image.GetDimension() == 4 and self.segments is None: + # Only 4D files that are non-segmentations have timepoints + return int(self.image.GetSize()[3]) else: return None @@ -262,7 +264,7 @@ def add_value_range_meta_data(cls, image: Image): # noqa: B902, N805 return image - @property + @cached_property def segments(self) -> Optional[FrozenSet[int]]: if ( self.image.GetNumberOfComponentsPerPixel() != 1 diff --git a/pyproject.toml b/pyproject.toml index abf1d76..d3807ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "panimg" -version = "0.13.0" +version = "0.13.1" description = "Conversion of medical images to MHA and TIFF." license = "Apache-2.0" authors = ["James Meakin "] diff --git a/tests/resources/image10x11x12x13.mha b/tests/resources/image10x11x12x13.mha index 505c4d265fa294a4d7361632c582d16ab31c3940..36531b3477f8c2f4dde1a1352231154c10dc7f19 100644 GIT binary patch delta 81 zcmeBUUcx+~lF7tiV)YIddmxx>#%N?6_kRCgATs1)U|=}B0K#$g2hwst3=~5FK%sny I5+ErE04B&G{{R30 delta 59 zcmZ3&+{ZkjlF8U|V)YK@AV<&1=8Q&abKV{_WMp7qIJDrae=d*w0w5CwJji$EU|<9Q D5IzoT diff --git a/tests/resources/image10x11x12x13.mhd b/tests/resources/image10x11x12x13.mhd index ef9fb1e..5175196 100644 --- a/tests/resources/image10x11x12x13.mhd +++ b/tests/resources/image10x11x12x13.mhd @@ -3,12 +3,12 @@ NDims = 4 BinaryData = True BinaryDataByteOrderMSB = False CompressedData = True -CompressedDataSize = 39 +CompressedDataSize = 40 TransformMatrix = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 Offset = -131 -99 -917 0 CenterOfRotation = 0 0 0 0 ElementSpacing = 0.429 0.429 0.5 1 DimSize = 10 11 12 13 -AnatomicalOrientation = RAI +AnatomicalOrientation = ???? ElementType = MET_UCHAR ElementDataFile = image10x11x12x13.zraw diff --git a/tests/resources/image10x11x12x13.zraw b/tests/resources/image10x11x12x13.zraw index 4a0643cba8379b8fa83d2881fe186ae5d902263a..d4cf999ef1d5c6c7186c0d3d8ed045a1b02cecda 100644 GIT binary patch literal 40 jcmb=3dwbB3mw|!d@PZ}(T>X#9Eda7nz=Qm~i`oPM0`&_e literal 39 icmb=J^Y)-2BLf4&p#@+4b9v+!0GTM@LB2Bw10w+6