Skip to content

Commit a65affb

Browse files
Update function doc strings
1 parent 686a38a commit a65affb

File tree

6 files changed

+97
-127
lines changed

6 files changed

+97
-127
lines changed

synaptic_reconstruction/ground_truth/matching.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@
44
from skimage.segmentation import relabel_sequential
55

66

7-
def find_additional_objects(ground_truth, segmentation, matching_threshold=0.5):
7+
def find_additional_objects(
8+
ground_truth: np.ndarray,
9+
segmentation: np.ndarray,
10+
matching_threshold: float = 0.5
11+
) -> np.ndarray:
12+
"""Compare ground-truth annotations with a segmentation to find objects not in the annotation.
13+
14+
Args:
15+
ground_trut:
16+
segmentation:
17+
matching_threshold:
18+
19+
Returns:
20+
"""
21+
822
segmentation = relabel_sequential(segmentation)[0]
923

1024
# Match the objects in the segmentation to the ground-truth.

synaptic_reconstruction/ground_truth/region_extraction.py

Lines changed: 0 additions & 106 deletions
This file was deleted.

synaptic_reconstruction/ground_truth/shape_refinement.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def edge_filter(
5252
- "sato": Edges are found with a sato-filter, followed by smoothing and leveling.
5353
per_slice: Compute the filter per slice instead of for the whole volume.
5454
n_threads: Number of threads for parallel computation over the slices.
55+
5556
Returns:
56-
Volume with edge strength.
57+
Edge filter response.
5758
"""
5859
if method not in FILTERS:
5960
raise ValueError(f"Invalid edge filter method: {method}. Expect one of {FILTERS}.")
@@ -100,6 +101,7 @@ def check_filters(
100101
The filter names must match `method` in `edge_filter`.
101102
sigmas: The sigma values to use for the filters.
102103
show: Whether to show the filter responses in napari.
104+
103105
Returns:
104106
Dictionary with the filter responses.
105107
"""
@@ -153,6 +155,7 @@ def refine_vesicle_shapes(
153155
return_seeds: Whether to return the seeds used for the watershed.
154156
compactness: The compactness parameter passed to the watershed function.
155157
Higher compactness leads to more regular sized vesicles.
158+
156159
Returns:
157160
The refined vesicles.
158161
"""

synaptic_reconstruction/imod/export.py

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import shutil
22
import tempfile
33
from subprocess import run
4-
from typing import Dict, Optional
4+
from typing import Dict, List, Optional, Tuple
55

66
import imageio.v3 as imageio
77
import numpy as np
@@ -144,7 +144,23 @@ def export_segmentation(
144144
imageio.imwrite(output_path, segmentation.astype("uint8"), compression="zlib")
145145

146146

147-
def draw_spheres(coordinates, radii, shape, verbose=True):
147+
def draw_spheres(
148+
coordinates: np.ndarray,
149+
radii: np.ndarray,
150+
shape: Tuple[int, int, int],
151+
verbose: bool = True,
152+
) -> np.ndarray:
153+
"""Create a volumetric segmentation by painting spheres around the given coordinates.
154+
155+
Args:
156+
coordinates: The center coordinates of the spheres.
157+
radii: The radii of the spheres.
158+
shape: The shape of the volume.
159+
verbose: Whether to print the progress bar.
160+
161+
Returns:
162+
The segmentation volume with painted spheres.
163+
"""
148164
labels = np.zeros(shape, dtype="uint32")
149165
for label_id, (coord, radius) in tqdm(
150166
enumerate(zip(coordinates, radii), start=1), total=len(coordinates), disable=not verbose
@@ -166,10 +182,35 @@ def draw_spheres(coordinates, radii, shape, verbose=True):
166182

167183

168184
def load_points_from_imodinfo(
169-
imod_path, full_shape, bb=None,
170-
exclude_labels=None, exclude_label_patterns=None,
171-
resolution=None,
172-
):
185+
imod_path: str,
186+
full_shape: Tuple[int, int, int],
187+
bb: Optional[Tuple[slice, slice, slice]] = None,
188+
exclude_labels: Optional[List[int]] = None,
189+
exclude_label_patterns: Optional[List[str]] = None,
190+
resolution: Optional[float] = None,
191+
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, Dict[int, str]]:
192+
"""Load point coordinates, radii and label information from a .mod file.
193+
194+
The coordinates and sizes returned will be scaled so that they are in
195+
the voxel coordinate space if the 'resolution' parameter is passed.
196+
If it is not passed then the radius will be returned in the physical resolution.
197+
198+
Args:
199+
imod_path: The filepath to the .mod file.
200+
full_shape: The voxel shape of the volume.
201+
bb: Optional bounding box to limit the extracted points to.
202+
exclude_labels: Label ids to exclude from the export.
203+
This can be used to exclude specific labels / classes, specifying them by their id.
204+
exclude_label_patterns: Label names to exclude from the export.
205+
This can be used to exclude specific labels / classes, specifying them by their name.
206+
resolution: The resolution / voxel size of the data. Will be used to scale the radii.
207+
208+
Returns:
209+
The center coordinates of the sphere annotations.
210+
The radii of the spheres.
211+
The ids of the semantic labels.
212+
The names of the semantic labels.
213+
"""
173214
coordinates, sizes, labels = [], [], []
174215
label_names = {}
175216

@@ -274,14 +315,33 @@ def load_points_from_imodinfo(
274315

275316

276317
def export_point_annotations(
277-
imod_path,
278-
shape,
279-
bb=None,
280-
exclude_labels=None,
281-
exclude_label_patterns=None,
282-
return_coords_and_radii=False,
283-
resolution=None,
284-
):
318+
imod_path: str,
319+
shape: Tuple[int, int, int],
320+
bb: Optional[Tuple[slice, slice, slice]] = None,
321+
exclude_labels: Optional[List[int]] = None,
322+
exclude_label_patterns: Optional[List[str]] = None,
323+
return_coords_and_radii: bool = False,
324+
resolution: Optional[float] = None,
325+
) -> Tuple[np.ndarray, np.ndarray, Dict[int, str]]:
326+
"""Create a segmentation by drawing spheres corresponding to objects from a .mod file.
327+
328+
Args:
329+
imod_path: The filepath to the .mod file.
330+
shape: The voxel shape of the volume.
331+
bb: Optional bounding box to limit the extracted points to.
332+
exclude_labels: Label ids to exclude from the segmentation.
333+
This can be used to exclude specific labels / classes, specifying them by their id.
334+
exclude_label_patterns: Label names to exclude from the segmentation.
335+
This can be used to exclude specific labels / classes, specifying them by their name.
336+
return_coords_and_radii: Whether to also return the underlying coordinates
337+
and radii of the exported spheres.
338+
resolution: The resolution / voxel size of the data. Will be used to scale the radii.
339+
340+
Returns:
341+
The exported segmentation.
342+
The label ids for the instance ids in the segmentation.
343+
The map of label ids to corresponding obejct names.
344+
"""
285345
coordinates, radii, labels, label_names = load_points_from_imodinfo(
286346
imod_path, shape, bb=bb,
287347
exclude_labels=exclude_labels,

synaptic_reconstruction/imod/to_imod.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def write_segmentation_to_imod(
3838
output_path: str,
3939
segmentation_key: Optional[str] = None,
4040
) -> None:
41-
"""Write a segmentation to a mod file as closed contour objects.
41+
"""Write a segmentation to a mod file as closed contour object(s).
4242
4343
Args:
4444
mrc_path: The filepath to the mrc file from which the segmentation was derived.
@@ -109,8 +109,8 @@ def convert_segmentation_to_spheres(
109109
props: Optional list of regionprops
110110
111111
Returns:
112-
np.array: the center coordinates
113-
np.array: the radii
112+
The center coordinates.
113+
The radii.
114114
"""
115115
num_workers = multiprocessing.cpu_count() if num_workers is None else num_workers
116116
if props is None:

synaptic_reconstruction/inference/actin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ def segment_actin(
2424
scale: Optional[List[float]] = None,
2525
mask: Optional[np.ndarray] = None,
2626
) -> Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]:
27-
"""
28-
Segment actin in an input volume.
27+
"""Segment actin in an input volume.
2928
3029
Args:
3130
input_volume: The input volume to segment.

0 commit comments

Comments
 (0)