Skip to content

Commit 8498db0

Browse files
MatthisClmarkbader
andauthored
Fix add existing tree to annotation (#1201)
* add test and change hash function * change hash function * fix typo. * Use always id for hash value of Group. * Adapt __eq__ method for group and skeleton. * Update changelog. * Adapt equality check. * Remove __eq__ and __hash__ method in Skeleton class. * Remove unused import. * Add eq=False to attr.define to avoid default equal method. * Run linter. --------- Co-authored-by: markbader <[email protected]>
1 parent f0caad7 commit 8498db0

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

webknossos/Changelog.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
3434
- Refactored the PimsTiffReader to read the data directly from the tiff file without creating a memmap-able copy first. This greatly reduces the time and storage requirements for converting large tiff files. [#1212](https://github.com/scalableminds/webknossos-libs/pull/1212)
3535

3636
### Fixed
37+
- Fixed an issue where adding existing trees to an annotation fails. [#1201](https://github.com/scalableminds/webknossos-libs/pull/1201)
3738
- Fixed unpickling of the SSL_Context to allow for a second or third pickling. [#1223](https://github.com/scalableminds/webknossos-libs/pull/1223)
3839
- Fixed offset error in upsample_cube job [#1209](https://github.com/scalableminds/webknossos-libs/pull/1209)
3940

@@ -50,15 +51,13 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
5051
- Fixed pickling issue that has been introduced in 0.15.9. [#1218](https://github.com/scalableminds/webknossos-libs/pull/1218)
5152

5253

53-
5454
## [0.15.10](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.15.10) - 2024-11-25
5555
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v0.15.9...v0.15.10)
5656

5757
### Fixed
5858
- Fixed pickling issue that has been introduced in 0.15.9. [#1218](https://github.com/scalableminds/webknossos-libs/pull/1218)
5959

6060

61-
6261
## [0.15.9](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.15.9) - 2024-11-25
6362
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v0.15.8...v0.15.9)
6463

webknossos/tests/test_skeleton.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,3 +438,15 @@ def test_add_tree_with_obj_and_properties(tmp_path: Path) -> None:
438438
assert new_tree.color == (1, 2, 3, 1)
439439

440440
skeleton_b.save(output_path)
441+
442+
443+
def test_add_tree_with_group() -> None:
444+
annotation = wk.Annotation(
445+
name="my_annotation", dataset_name="my_dataset", voxel_size=(11, 11, 24)
446+
)
447+
group = annotation.skeleton.add_group("a group")
448+
tree = group.add_tree("a tree")
449+
450+
skeleton_a = create_dummy_skeleton()
451+
452+
skeleton_a.add_tree(tree)

webknossos/webknossos/skeleton/group.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import copy
2-
from typing import TYPE_CHECKING, Iterator, Optional, Set, Tuple, Union, cast
2+
from typing import TYPE_CHECKING, Any, Iterator, Optional, Set, Tuple, Union, cast
33

44
import attr
55
from boltons.strutils import unit_len
@@ -220,7 +220,7 @@ def children(self) -> Iterator[GroupOrTree]:
220220
@property
221221
def trees(self) -> Iterator[Tree]:
222222
"""Returns all (immediate) tree children as an iterator.
223-
Use flattened_trees if you need also need trees within subgroups."""
223+
Use flattened_trees if you also need trees within subgroups."""
224224
return (child for child in self._child_trees)
225225

226226
@property
@@ -430,5 +430,8 @@ def as_nml_group(self) -> wknml.Group:
430430
children=[g.as_nml_group() for g in self._child_groups],
431431
)
432432

433+
def __eq__(self, other: Any) -> bool:
434+
return type(other) is type(self) and self._id == other._id
435+
433436
def __hash__(self) -> int:
434-
return self._id
437+
return id(self)

webknossos/webknossos/skeleton/skeleton.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Vector3 = Tuple[float, float, float]
1313

1414

15-
@attr.define
15+
@attr.define(eq=False)
1616
class Skeleton(Group):
1717
"""A hierarchical representation of skeleton annotations in WEBKNOSSOS.
1818
@@ -281,6 +281,3 @@ def write(self, out_path: PathLike) -> None:
281281
"""Deprecated. Use Skeleton.save instead."""
282282
warn_deprecated("Skeleton.write", "skeleton.save")
283283
self.save(out_path)
284-
285-
def __hash__(self) -> int:
286-
return id(self)

0 commit comments

Comments
 (0)