webknossos.annotation
¶
SegmentGroup
¶
Bases: _BaseGroup
A hierarchical container for organizing segments of a volume layer.
Segment groups can be nested. A segment is assigned to a group by setting
SegmentInformation.group; segments with group=None are top-level.
Attributes:
-
name(str) –Name of the group.
-
id(int) –Read-only unique identifier for the group within its volume layer.
-
groups(Iterator[_GroupT]) –Iterator over immediate subgroups.
-
segments(dict[int, SegmentInformation]) –Immediate segments of this group.
Examples:
volume_layer = annotation.get_volume_layer("segmentation")
neuron = volume_layer.add_segment_group("neuron_42")
dendrites = neuron.add_group("dendrites")
volume_layer.segments[1] = wk.SegmentInformation(
name="dendrite fragment",
anchor_position=None,
color=None,
metadata={},
group=dendrites,
)
print(neuron.flattened_segments())
Notes
- Groups should be created with
VolumeLayer.add_segment_grouporadd_grouprather than directly.
See Also
- VolumeLayer: Volume annotation layer owning the groups and segments
- SegmentInformation: Per-segment information, including its group
groups
property
¶
groups: Iterator[_GroupT]
Returns all (immediate) group children as an iterator. Use flattened_groups if you also need groups within subgroups.
segments
property
¶
segments: dict[int, SegmentInformation]
Returns the (immediate) segments of this group, keyed by segment id. Use flattened_segments if you also need segments within subgroups.
add_group
¶
add_group(
name: str, _enforced_id: int | None = None
) -> SegmentGroup
Creates and adds a new subgroup to this group.
Parameters:
-
name(str) –Name for the new group.
-
_enforced_id(int | None, default:None) –Optional specific ID for the group (internal use).
Returns:
-
SegmentGroup(SegmentGroup) –The newly created group.
Raises:
-
ValueError–If
_enforced_idis negative or already used by another group of the layer.
flattened_groups
¶
flattened_groups() -> Iterator[_GroupT]
Returns an iterator of all groups within this group (and its subgroups).
flattened_segments
¶
flattened_segments() -> dict[int, SegmentInformation]
Returns all segments of this group and its subgroups, keyed by segment id.
get_group_by_id
¶
get_group_by_id(group_id: int) -> _GroupT
Returns the group within this group (and its subgroups) which has the specified id.
- Get Help
- Community Forums
- Email Support