Skip to content

Commit 49169f4

Browse files
committed
small fixes
1 parent d5adcae commit 49169f4

4 files changed

Lines changed: 23 additions & 3 deletions

File tree

TPTBox/core/nii_poi_abstract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import sys
4-
import warnings
54
from dataclasses import dataclass
65
from typing import TYPE_CHECKING, Any
76

@@ -495,6 +494,7 @@ def local_to_global(self, x: COORDINATE) -> tuple:
495494
Returns:
496495
tuple: World-space coordinate rounded to 7 decimal places.
497496
"""
497+
# TODO ITK version
498498
a = self.rotation @ (np.array(x) * np.array(self.zoom)) + self.origin
499499
return tuple(round(float(v), 7) for v in a)
500500

TPTBox/core/poi_fun/poi_abstract.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,12 +1030,16 @@ def join_left(self, pois: Self, inplace=False, _right_join=False) -> Self:
10301030
Self: The combined set of centroids, either in-place or as a new set, depending on the 'inplace' parameter.
10311031
"""
10321032
ctd_list = self.centroids
1033+
if "label_name" in pois.info and "label_name" not in self.info:
1034+
self.info["label_name"] = {}
10331035
if not inplace:
10341036
ctd_list = ctd_list.copy()
10351037
for x, y, c in pois.items():
10361038
if (x, y) in self and not _right_join:
10371039
continue
10381040
ctd_list[x, y] = c
1041+
if "label_name" in pois.info and f"({x}, {y})" in pois.info["label_name"]:
1042+
self.info["label_name"][f"({x}, {y})"] = pois.info["label_name"][f"({x}, {y})"]
10391043
if inplace:
10401044
return self
10411045
return self.copy(ctd_list)

TPTBox/core/poi_fun/save_load.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,12 @@ def convert(o):
135135
return str(o.absolute())
136136
raise TypeError(type(o))
137137

138-
with open(out_path, "w") as f:
139-
json.dump(json_object, f, default=convert, indent=4)
138+
try:
139+
with open(out_path, "w") as f:
140+
json.dump(json_object, f, default=convert, indent=4)
141+
except TypeError:
142+
Path(out_path).unlink(missing_ok=True)
143+
raise
140144
log.print("POIs saved:", out_path, print_add, ltype=Log_Type.SAVE, verbose=verbose)
141145

142146

unit_tests/test_testsamples.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ def test_POIs_CT(self):
113113
Location.Vertebral_Body_Endplate_Inferior,
114114
Location.Rib_Left,
115115
Location.Rib_Right,
116+
Location.Sacrum_Sacral_Ala_Left,
117+
Location.Sacrum_Sacral_Ala_Right,
118+
Location.Sacrum_Posterior_Sacral_Elements,
119+
Location.Sacrum_Body,
120+
Location.Sacrum_Endplate,
121+
Location.Metal,
116122
]
117123
self.make_POIs(vert_nii, subreg_nii, label, ignore_list)
118124

@@ -134,6 +140,12 @@ def test_POIs_MR(self):
134140
Location.Vertebral_Body_Endplate_Inferior,
135141
Location.Rib_Left,
136142
Location.Rib_Right,
143+
Location.Sacrum_Sacral_Ala_Left,
144+
Location.Sacrum_Sacral_Ala_Right,
145+
Location.Sacrum_Posterior_Sacral_Elements,
146+
Location.Sacrum_Body,
147+
Location.Sacrum_Endplate,
148+
Location.Metal,
137149
]
138150
self.make_POIs(vert_nii, subreg_nii, label, ignore_list)
139151

0 commit comments

Comments
 (0)