Skip to content

Commit 75a00da

Browse files
Added more doc strings (#1225)
* update docsstrings * more doc strings * doc strings for tree class * docstrings for skeleton class * more docs for view.py * more docstrings for view.py * format and lint * more docstrings for view.py * docstrigns for magview * fix merge error * fix example formatting * applied PR feedback * small update to index * Update webknossos/webknossos/dataset/mag_view.py Co-authored-by: Mark Bader <[email protected]> * Update webknossos/webknossos/dataset/mag_view.py Co-authored-by: Mark Bader <[email protected]> * Update webknossos/webknossos/dataset/view.py Co-authored-by: Mark Bader <[email protected]> * Update webknossos/webknossos/dataset/view.py Co-authored-by: Mark Bader <[email protected]> * Update webknossos/webknossos/dataset/view.py Co-authored-by: Mark Bader <[email protected]> * Update webknossos/webknossos/dataset/mag_view.py Co-authored-by: Mark Bader <[email protected]> * Update webknossos/webknossos/dataset/mag_view.py Co-authored-by: Mark Bader <[email protected]> * applied PR feedback --------- Co-authored-by: Mark Bader <[email protected]>
1 parent ce9c8b0 commit 75a00da

File tree

12 files changed

+1595
-444
lines changed

12 files changed

+1595
-444
lines changed

docs/mkdocs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ plugins:
9393
show_if_no_docstring: true
9494
signature_crossrefs: true
9595
parameter_headings: false
96-
summary: true
9796
unwrap_annotated: true
9897
line_length: 60
9998
filters:

docs/src/webknossos-py/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ To get started, check out the [installation instructions](installation.md) and t
2222
- Up/downsample layers
2323
- Compress layers
2424
- Add/remove magnifications
25-
- Execute any of the `wkCuber` operations from your code
25+
- Execute any of the `webknossos` CLI operations from your code
2626
- Manipulation of WEBKNOSSOS skeleton annotations (*.nml) as Python objects
2727
- Access to nodes, comments, trees, bounding boxes, metadata, etc.
2828
- Create new skeleton annotation from Graph structures or Python objects
2929
- Interaction, connection & scripting with your WEBKNOSSOS instance over the REST API
3030
- Up- & downloading annotations and datasets
31+
- Read datasets from the WEBKNOSSOS server in a streaming fashion
3132

3233
## Source Code
3334

webknossos/Changelog.md

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

1717
### Added
1818
- Added .nrrd and .nhdr to supported suffixes. [#1228](https://github.com/scalableminds/webknossos-libs/pull/1228)
19+
- Added more docstrings for many public classes and methods. [#1225](https://github.com/scalableminds/webknossos-libs/pull/1225)
1920

2021
### Changed
2122
- Removes vcr-py from developer dependencies for testing and adds proxay for recording and replaying API requests. [#1198](https://github.com/scalableminds/webknossos-libs/pull/1198)

webknossos/webknossos/_nml/nml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def write(self, file: BinaryIO) -> None:
3939
Arguments:
4040
file (BinaryIO): A Python file handle
4141
42-
Example:
42+
Examples:
4343
```
4444
with open("out.nml", "wb") as f:
4545
nml.write(f, nml)
@@ -90,7 +90,7 @@ def parse(cls, file: IO[bytes]) -> "Nml":
9090
Return:
9191
NML: A WEBKNOSSOS skeleton annotation as Python NML object
9292
93-
Example:
93+
Examples:
9494
```
9595
with open("input.nml", "rb") as f:
9696
nml = Nml.parse(f)

webknossos/webknossos/annotation/annotation.py

Lines changed: 75 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,42 @@
1-
"""Annotations can contain annotated data in two forms:
2-
3-
- [skeleton data](/webknossos/skeleton_annotation/index.html), as provided by the `Skeleton` class, and
4-
- [volume annotation layers](/webknossos/volume_annotation/index.html) (or volume layers short),
5-
which can be exported as a `SegmentationLayer`, see `export_volume_layer_to_dataset()`
6-
and `temporary_volume_layer_copy()`.
7-
8-
Usually, annotations should be created manually in the WEBKNOSSOS interface and can be downloaded using
9-
`Annotation.download()`. The downloaded instance is not persisted to disk automatically, please use `save()`
10-
for this purpose. The general purpose file format is `.zip` files containing an `.nml` file with
11-
meta-information and the skeleton data and also containing inner `.zip` files for the volume layers.
12-
For skeleton-only annotations without volume layers `.nml` files can be used directly. Both formats
13-
are compatible with the WEBKNOSSOS up- and downloads.
14-
15-
To prepare volume annotations in the code for correction of segmentation data in the WEBKNOSSOS interface,
16-
please use `add_volume_layer()` with the `fallback_layer` argument, referencing a segmentation layer that
17-
is available on WEBKNOSSOS (e.g. using the `Dataset` upload before).
18-
Correcting segmentations using fallback layers is much more efficient, adding volume
19-
annotation data programmatically is discouraged therefore.
1+
"""WEBKNOSSOS annotation module for working with skeleton and volume data.
2+
3+
This module provides the Annotation class for handling WEBKNOSSOS annotations, which can
4+
contain two types of data:
5+
6+
1. Skeleton Data: Represented by the `Skeleton` class, e.g. for annotating neural pathways
7+
and structures.
8+
2. Volume Annotation Layers: Used for segmentation data, can be exported as
9+
`SegmentationLayer` objects.
10+
11+
The module supports various operations including:
12+
* Loading/saving annotations from/to .nml or .zip files
13+
* Downloading/uploading annotations from/to WEBKNOSSOS
14+
* Working with skeleton data and volume layers
15+
* Exporting volume layers to datasets
16+
17+
Typical usage Examples:
18+
```python
19+
# Download an annotation from WEBKNOSSOS
20+
annotation = Annotation.download("annotation_id")
21+
22+
# Add a volume layer with fallback for efficient processing
23+
annotation.add_volume_layer(
24+
name="segmentation",
25+
fallback_layer="original_segmentation"
26+
)
27+
28+
# Save the annotation locally
29+
annotation.save("my_annotation.zip")
30+
```
31+
32+
Notes:
33+
For volume annotations, using fallback layers is recommended for better performance
34+
in WEBKNOSSOS. Adding volume annotation data programmatically should be avoided
35+
when possible.
36+
37+
See Also:
38+
* Skeleton documentation: /webknossos/skeleton_annotation/index.html
39+
* Volume annotation documentation: /webknossos/volume_annotation/index.html
2040
"""
2141

2242
import json
@@ -489,6 +509,40 @@ def open_as_remote_dataset(
489509
annotation_type: Union[str, "AnnotationType", None] = None,
490510
webknossos_url: Optional[str] = None,
491511
) -> Dataset:
512+
"""Opens an annotation directly as a remote dataset from WEBKNOSSOS.
513+
514+
This is a convenience method that combines downloading an annotation and converting it
515+
to a remote dataset in one step. It's useful when you want to work with the annotation
516+
data as a dataset without storing it locally.
517+
518+
Args:
519+
annotation_id_or_url: Either an annotation ID or complete WEBKNOSSOS URL.
520+
Example URL: https://webknossos.org/annotations/[id]
521+
annotation_type: ⚠️ Deprecated and no longer required.
522+
Optional type of annotation (Explorational, Task, etc.).
523+
webknossos_url: Optional custom WEBKNOSSOS instance URL.
524+
525+
Returns:
526+
Dataset: A remote dataset instance representing the annotation.
527+
528+
Examples:
529+
```python
530+
# Open by ID
531+
dataset = Annotation.open_as_remote_dataset("5f7d3a...")
532+
533+
# Open by URL
534+
dataset = Annotation.open_as_remote_dataset(
535+
"https://webknossos.org/annotations/5f7d3a..."
536+
)
537+
538+
# Access layers
539+
layer = dataset.get_layer("segmentation")
540+
```
541+
542+
Notes:
543+
This method automatically skips downloading volume data locally for efficiency,
544+
as the data will be streamed from the remote source.
545+
"""
492546
(
493547
annotation,
494548
context,
@@ -857,7 +911,7 @@ def get_remote_annotation_dataset(self) -> Dataset:
857911
# Access layers
858912
layer = dataset.get_layer("segmentation")
859913
```
860-
Note:
914+
Notes:
861915
After an agglomerate mapping was activated in WEBKNOSSOS, it is applied to this method as soon
862916
as the first volume editing action is done. Note that this behavior might change
863917
in the future.
@@ -1277,7 +1331,7 @@ def get_volume_layer_segments(
12771331
# Update segment name
12781332
segments[1].name = "Cell A"
12791333
```
1280-
Note:
1334+
Notes:
12811335
Any changes performed on the online version of the annotaiton in webknossos are not
12821336
synced automatically. The annotation needs to be re-downloaded to update segment information.
12831337
"""
@@ -1350,12 +1404,3 @@ def open_annotation(annotation_path: Union[str, PathLike]) -> "Annotation":
13501404
), f"Called open_annotation with a path-like, but {annotation_path} does not exist."
13511405
warn_deprecated("open_annotation", "Annotation.download")
13521406
return Annotation.download(annotation_path)
1353-
1354-
1355-
def _parse_filename_from_header(value: str) -> str:
1356-
# Adapted from https://peps.python.org/pep-0594/#cgi
1357-
from email.message import Message
1358-
1359-
m = Message()
1360-
m["content-type"] = value
1361-
return dict(m.get_params() or []).get("filename", "")

webknossos/webknossos/dataset/layer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ def downsample(
10411041
RuntimeError: If sampling scheme produces invalid magnifications
10421042
AttributeError: If sampling_mode is invalid
10431043
1044-
Example:
1044+
Examples:
10451045
```python
10461046
from webknossos import SamplingModes
10471047

0 commit comments

Comments
 (0)