Skip to content

Commit 52bf88d

Browse files
authored
Add converter to voxel_size factor. (#1139)
* Add converter to voxel_size factor. * Update changelog. * Update converter to pass typecheck.
1 parent 017b02d commit 52bf88d

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

webknossos/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
1919
### Changed
2020

2121
### Fixed
22+
- Add a converter to the VoxelSize field `factor`, to ensure it is a tuple.
2223

2324

2425
## [0.14.25](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.14.25) - 2024-07-18

webknossos/webknossos/dataset/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def __init__(
359359
else:
360360
assert (
361361
self.voxel_size_with_unit == voxel_size_with_unit
362-
), f"Cannot open Dataset: The dataset {dataset_path} already exists, but the voxel_sizes do not match ({self.voxel_size} != {voxel_size})"
362+
), f"Cannot open Dataset: The dataset {dataset_path} already exists, but the voxel_sizes do not match ({self.voxel_size_with_unit} != {voxel_size_with_unit})"
363363
if name is not None:
364364
assert (
365365
self.name == name

webknossos/webknossos/dataset/properties.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Any,
55
Callable,
66
Dict,
7+
Iterable,
78
List,
89
Optional,
910
Tuple,
@@ -65,6 +66,18 @@ def _extract_num_channels(
6566
return array.info.num_channels
6667

6768

69+
def float_tpl(voxel_size: Union[List, Tuple]) -> Iterable:
70+
# Fix for mypy bug https://github.com/python/mypy/issues/5313.
71+
# Solution based on other issue for the same bug: https://github.com/python/mypy/issues/8389.
72+
return tuple(
73+
(
74+
voxel_size[0],
75+
voxel_size[1],
76+
voxel_size[2],
77+
)
78+
)
79+
80+
6881
_properties_floating_type_to_python_type: Dict[Union[str, type], np.dtype] = {
6982
"float": np.dtype("float32"),
7083
# np.float: np.dtype("float32"), # np.float is an alias for float
@@ -183,7 +196,7 @@ class SegmentationLayerProperties(LayerProperties):
183196

184197
@attr.define
185198
class VoxelSize:
186-
factor: Tuple[float, float, float]
199+
factor: Tuple[float, float, float] = attr.field(converter=float_tpl)
187200
unit: LengthUnit = DEFAULT_LENGTH_UNIT
188201

189202
def to_nanometer(self) -> Tuple[float, float, float]:

0 commit comments

Comments
 (0)