Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/copick_utils/cli/segop.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ def segop(
Note: All segmentations are converted to binary for boolean operations.
Voxel spacing applies globally to all inputs and output.

\b
Single-Input Pattern Expansion (union only):
When providing a single -i flag with a pattern, the union operation will
expand the pattern within each run and merge all matching segmentations.
This is useful for combining multiple versions/annotations within each run.

\b
Examples:
# Single-input union: merge all matching segmentations within each run
Expand Down
30 changes: 10 additions & 20 deletions src/copick_utils/converters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
"""Converters for different copick data types."""

from copick_utils.converters.ellipsoid_from_picks import ellipsoid_from_picks, ellipsoid_from_picks_batch
from copick_utils.converters.mesh_from_picks import mesh_from_picks, mesh_from_picks_batch
from copick_utils.converters.mesh_from_segmentation import mesh_from_segmentation, mesh_from_segmentation_batch
from copick_utils.converters.picks_from_mesh import picks_from_mesh, picks_from_mesh_batch
from copick_utils.converters.picks_from_segmentation import picks_from_segmentation, picks_from_segmentation_batch
from copick_utils.converters.plane_from_picks import plane_from_picks, plane_from_picks_batch
from copick_utils.converters.segmentation_from_mesh import segmentation_from_mesh, segmentation_from_mesh_batch
from copick_utils.converters.segmentation_from_picks import segmentation_from_picks, segmentation_from_picks_batch
from copick_utils.converters.sphere_from_picks import sphere_from_picks, sphere_from_picks_batch
from copick_utils.converters.surface_from_picks import surface_from_picks, surface_from_picks_batch
from copick_utils.converters.ellipsoid_from_picks import ellipsoid_from_picks
from copick_utils.converters.mesh_from_picks import mesh_from_picks
from copick_utils.converters.mesh_from_segmentation import mesh_from_segmentation
from copick_utils.converters.picks_from_mesh import picks_from_mesh
from copick_utils.converters.picks_from_segmentation import picks_from_segmentation
from copick_utils.converters.plane_from_picks import plane_from_picks
from copick_utils.converters.segmentation_from_mesh import segmentation_from_mesh
from copick_utils.converters.segmentation_from_picks import segmentation_from_picks
from copick_utils.converters.sphere_from_picks import sphere_from_picks
from copick_utils.converters.surface_from_picks import surface_from_picks

__all__ = [
"mesh_from_segmentation",
"mesh_from_segmentation_batch",
"picks_from_segmentation",
"picks_from_segmentation_batch",
"picks_from_mesh",
"picks_from_mesh_batch",
"segmentation_from_mesh",
"segmentation_from_mesh_batch",
"segmentation_from_picks",
"segmentation_from_picks_batch",
"mesh_from_picks",
"mesh_from_picks_batch",
"sphere_from_picks",
"sphere_from_picks_batch",
"ellipsoid_from_picks",
"ellipsoid_from_picks_batch",
"plane_from_picks",
"plane_from_picks_batch",
"surface_from_picks",
"surface_from_picks_batch",
]
15 changes: 0 additions & 15 deletions src/copick_utils/converters/ellipsoid_from_picks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

from copick_utils.converters.converter_common import (
cluster,
create_batch_converter,
create_batch_worker,
store_mesh_with_stats,
validate_points,
)
Expand Down Expand Up @@ -315,20 +313,7 @@ def create_ellipsoid_from_points(cluster_points):
return None


# Create worker function using common infrastructure
_ellipsoid_from_picks_worker = create_batch_worker(ellipsoid_from_picks, "ellipsoid", min_points=6)


# Create batch converter using common infrastructure
ellipsoid_from_picks_batch = create_batch_converter(
ellipsoid_from_picks,
"Converting picks to ellipsoid meshes",
"ellipsoid",
min_points=6,
)

# Lazy batch converter for new architecture

ellipsoid_from_picks_lazy_batch = create_lazy_batch_converter(
converter_func=ellipsoid_from_picks,
task_description="Converting picks to ellipsoid meshes",
Expand Down
15 changes: 0 additions & 15 deletions src/copick_utils/converters/mesh_from_picks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

from copick_utils.converters.converter_common import (
cluster,
create_batch_converter,
create_batch_worker,
store_mesh_with_stats,
validate_points,
)
Expand Down Expand Up @@ -189,19 +187,6 @@ def create_mesh_from_points(cluster_points):
return None


# Create worker function using common infrastructure
_mesh_from_picks_worker = create_batch_worker(mesh_from_picks, "mesh", "picks", min_points=4)


# Create batch converter using common infrastructure
mesh_from_picks_batch = create_batch_converter(
mesh_from_picks,
"Converting picks to meshes",
"mesh",
"picks",
min_points=4,
)

# Lazy batch converter for new architecture
mesh_from_picks_lazy_batch = create_lazy_batch_converter(
converter_func=mesh_from_picks,
Expand Down
15 changes: 0 additions & 15 deletions src/copick_utils/converters/mesh_from_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from copick.util.log import get_logger

from copick_utils.converters.converter_common import (
create_batch_converter,
create_batch_worker,
store_mesh_with_stats,
)
from copick_utils.converters.lazy_converter import create_lazy_batch_converter
Expand Down Expand Up @@ -99,19 +97,6 @@ def mesh_from_segmentation(
return None


# Create worker function using common infrastructure
_mesh_from_segmentation_worker = create_batch_worker(mesh_from_segmentation, "mesh", "segmentation", min_points=0)


# Create batch converter using common infrastructure
mesh_from_segmentation_batch = create_batch_converter(
mesh_from_segmentation,
"Converting segmentations to meshes",
"mesh",
"segmentation",
min_points=0,
)

# Lazy batch converter for new architecture
mesh_from_segmentation_lazy_batch = create_lazy_batch_converter(
converter_func=mesh_from_segmentation,
Expand Down
80 changes: 2 additions & 78 deletions src/copick_utils/converters/picks_from_mesh.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Tuple
from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, Tuple

import numpy as np
import trimesh as tm
Expand All @@ -8,7 +8,7 @@
from copick_utils.converters.lazy_converter import create_lazy_batch_converter

if TYPE_CHECKING:
from copick.models import CopickMesh, CopickPicks, CopickRoot, CopickRun
from copick.models import CopickMesh, CopickPicks, CopickRun

logger = get_logger(__name__)

Expand Down Expand Up @@ -459,82 +459,6 @@ def picks_from_mesh_standard(
return None


def picks_from_mesh_batch(
root: "CopickRoot",
mesh_object_name: str,
mesh_user_id: str,
mesh_session_id: str,
sampling_type: str,
n_points: int,
pick_object_name: str,
pick_session_id: str,
pick_user_id: str,
voxel_spacing: float,
tomo_type: str = "wbp",
min_dist: Optional[float] = None,
edge_dist: float = 32.0,
include_normals: bool = False,
random_orientations: bool = False,
seed: Optional[int] = None,
run_names: Optional[List[str]] = None,
workers: int = 8,
) -> Dict[str, Any]:
"""
Batch convert meshes to picks across multiple runs.

Args:
root: The copick root containing runs to process.
mesh_object_name: Name of the mesh object to sample from.
mesh_user_id: User ID of the mesh to convert.
mesh_session_id: Session ID of the mesh to convert.
sampling_type: Type of sampling ('inside', 'surface', 'outside', 'vertices').
n_points: Number of points to sample (ignored for 'vertices' type).
pick_object_name: Name of the object for created picks.
pick_session_id: Session ID for created picks.
pick_user_id: User ID for created picks.
voxel_spacing: Voxel spacing for coordinate scaling.
tomo_type: Tomogram type for getting volume dimensions. Default is 'wbp'.
min_dist: Minimum distance between points. If None, uses 2 * voxel_spacing.
edge_dist: Distance from volume edges in voxels. Default is 32.0.
include_normals: Include surface normals as orientations (surface sampling only). Default is False.
random_orientations: Generate random orientations for points. Default is False.
seed: Random seed for reproducible results.
run_names: List of run names to process. If None, processes all runs.
workers: Number of worker processes. Default is 8.

Returns:
Dictionary with processing results and statistics.
"""
from copick.ops.run import map_runs

runs_to_process = [run.name for run in root.runs] if run_names is None else run_names

results = map_runs(
callback=_picks_from_mesh_worker,
root=root,
runs=runs_to_process,
workers=workers,
task_desc="Converting meshes to picks",
mesh_object_name=mesh_object_name,
mesh_user_id=mesh_user_id,
mesh_session_id=mesh_session_id,
sampling_type=sampling_type,
n_points=n_points,
pick_object_name=pick_object_name,
pick_session_id=pick_session_id,
pick_user_id=pick_user_id,
voxel_spacing=voxel_spacing,
tomo_type=tomo_type,
min_dist=min_dist,
edge_dist=edge_dist,
include_normals=include_normals,
random_orientations=random_orientations,
seed=seed,
)

return results


# Lazy batch converter for new architecture
picks_from_mesh_lazy_batch = create_lazy_batch_converter(
converter_func=picks_from_mesh_standard,
Expand Down
17 changes: 0 additions & 17 deletions src/copick_utils/converters/picks_from_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
from skimage.morphology import ball, binary_dilation, binary_erosion
from skimage.segmentation import watershed

from copick_utils.converters.converter_common import (
create_batch_converter,
create_batch_worker,
)
from copick_utils.converters.lazy_converter import create_lazy_batch_converter

if TYPE_CHECKING:
Expand Down Expand Up @@ -148,19 +144,6 @@ def picks_from_segmentation(
return None


# Create worker function using common infrastructure
_picks_from_segmentation_worker = create_batch_worker(picks_from_segmentation, "picks", "segmentation", min_points=0)


# Create batch converter using common infrastructure
picks_from_segmentation_batch = create_batch_converter(
picks_from_segmentation,
"Converting segmentations to picks",
"picks",
"segmentation",
min_points=0,
)

# Lazy batch converter for new architecture
picks_from_segmentation_lazy_batch = create_lazy_batch_converter(
converter_func=picks_from_segmentation,
Expand Down
14 changes: 0 additions & 14 deletions src/copick_utils/converters/plane_from_picks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

from copick_utils.converters.converter_common import (
cluster,
create_batch_converter,
create_batch_worker,
store_mesh_with_stats,
validate_points,
)
Expand Down Expand Up @@ -232,18 +230,6 @@ def create_plane_from_points(cluster_points):
return None


# Create worker function using common infrastructure
_plane_from_picks_worker = create_batch_worker(plane_from_picks, "plane", min_points=3)


# Create batch converter using common infrastructure
plane_from_picks_batch = create_batch_converter(
plane_from_picks,
"Converting picks to plane meshes",
"plane",
min_points=3,
)

# Lazy batch converter for new architecture
plane_from_picks_lazy_batch = create_lazy_batch_converter(
converter_func=plane_from_picks,
Expand Down
17 changes: 0 additions & 17 deletions src/copick_utils/converters/segmentation_from_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
from copick.util.log import get_logger
from trimesh.ray.ray_triangle import RayMeshIntersector

from copick_utils.converters.converter_common import (
create_batch_converter,
create_batch_worker,
)
from copick_utils.converters.lazy_converter import create_lazy_batch_converter

if TYPE_CHECKING:
Expand Down Expand Up @@ -271,19 +267,6 @@ def segmentation_from_mesh(
return None


# Create worker function using common infrastructure
_segmentation_from_mesh_worker = create_batch_worker(segmentation_from_mesh, "segmentation", "mesh", min_points=0)


# Create batch converter using common infrastructure
segmentation_from_mesh_batch = create_batch_converter(
segmentation_from_mesh,
"Converting meshes to segmentations",
"segmentation",
"mesh",
min_points=0,
)

# Lazy batch converter for new architecture
segmentation_from_mesh_lazy_batch = create_lazy_batch_converter(
converter_func=segmentation_from_mesh,
Expand Down
17 changes: 0 additions & 17 deletions src/copick_utils/converters/segmentation_from_picks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
from copick.util.log import get_logger
from scipy.ndimage import zoom

from copick_utils.converters.converter_common import (
create_batch_converter,
create_batch_worker,
)
from copick_utils.converters.lazy_converter import create_lazy_batch_converter

if TYPE_CHECKING:
Expand Down Expand Up @@ -277,19 +273,6 @@ def segmentation_from_picks(
return None


# Create worker function using common infrastructure
_segmentation_from_picks_worker = create_batch_worker(segmentation_from_picks, "segmentation", "picks", min_points=1)


# Create batch converter using common infrastructure
segmentation_from_picks_batch = create_batch_converter(
segmentation_from_picks,
"Converting picks to segmentations",
"segmentation",
"picks",
min_points=1,
)

# Lazy batch converter for new architecture
segmentation_from_picks_lazy_batch = create_lazy_batch_converter(
converter_func=segmentation_from_picks,
Expand Down
14 changes: 0 additions & 14 deletions src/copick_utils/converters/sphere_from_picks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

from copick_utils.converters.converter_common import (
cluster,
create_batch_converter,
create_batch_worker,
store_mesh_with_stats,
validate_points,
)
Expand Down Expand Up @@ -287,18 +285,6 @@ def sphere_from_picks(
return None


# Create worker function using common infrastructure
_sphere_from_picks_worker = create_batch_worker(sphere_from_picks, "sphere", min_points=4)


# Create batch converter using common infrastructure
sphere_from_picks_batch = create_batch_converter(
sphere_from_picks,
"Converting picks to sphere meshes",
"sphere",
min_points=4,
)

# Lazy batch converter for new architecture
sphere_from_picks_lazy_batch = create_lazy_batch_converter(
converter_func=sphere_from_picks,
Expand Down
Loading