Skip to content

Commit

Permalink
Fix add existing tree to annotation (#1201)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
MatthisCl and markbader authored Dec 9, 2024
1 parent f0caad7 commit 8498db0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
3 changes: 1 addition & 2 deletions webknossos/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
- 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)

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

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



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

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



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

Expand Down
12 changes: 12 additions & 0 deletions webknossos/tests/test_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,15 @@ def test_add_tree_with_obj_and_properties(tmp_path: Path) -> None:
assert new_tree.color == (1, 2, 3, 1)

skeleton_b.save(output_path)


def test_add_tree_with_group() -> None:
annotation = wk.Annotation(
name="my_annotation", dataset_name="my_dataset", voxel_size=(11, 11, 24)
)
group = annotation.skeleton.add_group("a group")
tree = group.add_tree("a tree")

skeleton_a = create_dummy_skeleton()

skeleton_a.add_tree(tree)
9 changes: 6 additions & 3 deletions webknossos/webknossos/skeleton/group.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import copy
from typing import TYPE_CHECKING, Iterator, Optional, Set, Tuple, Union, cast
from typing import TYPE_CHECKING, Any, Iterator, Optional, Set, Tuple, Union, cast

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

@property
Expand Down Expand Up @@ -430,5 +430,8 @@ def as_nml_group(self) -> wknml.Group:
children=[g.as_nml_group() for g in self._child_groups],
)

def __eq__(self, other: Any) -> bool:
return type(other) is type(self) and self._id == other._id

def __hash__(self) -> int:
return self._id
return id(self)
5 changes: 1 addition & 4 deletions webknossos/webknossos/skeleton/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Vector3 = Tuple[float, float, float]


@attr.define
@attr.define(eq=False)
class Skeleton(Group):
"""A hierarchical representation of skeleton annotations in WEBKNOSSOS.
Expand Down Expand Up @@ -281,6 +281,3 @@ def write(self, out_path: PathLike) -> None:
"""Deprecated. Use Skeleton.save instead."""
warn_deprecated("Skeleton.write", "skeleton.save")
self.save(out_path)

def __hash__(self) -> int:
return id(self)

0 comments on commit 8498db0

Please sign in to comment.