copick-utils 0.6.0__py3-none-any.whl → 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. copick_utils/__init__.py +1 -0
  2. copick_utils/cli/__init__.py +33 -0
  3. copick_utils/cli/clipmesh.py +161 -0
  4. copick_utils/cli/clippicks.py +154 -0
  5. copick_utils/cli/clipseg.py +163 -0
  6. copick_utils/cli/conversion_commands.py +32 -0
  7. copick_utils/cli/enclosed.py +191 -0
  8. copick_utils/cli/filter_components.py +166 -0
  9. copick_utils/cli/fit_spline.py +191 -0
  10. copick_utils/cli/hull.py +138 -0
  11. copick_utils/cli/input_output_selection.py +76 -0
  12. copick_utils/cli/logical_commands.py +29 -0
  13. copick_utils/cli/mesh2picks.py +170 -0
  14. copick_utils/cli/mesh2seg.py +167 -0
  15. copick_utils/cli/meshop.py +262 -0
  16. copick_utils/cli/picks2ellipsoid.py +171 -0
  17. copick_utils/cli/picks2mesh.py +181 -0
  18. copick_utils/cli/picks2plane.py +156 -0
  19. copick_utils/cli/picks2seg.py +134 -0
  20. copick_utils/cli/picks2sphere.py +170 -0
  21. copick_utils/cli/picks2surface.py +164 -0
  22. copick_utils/cli/picksin.py +146 -0
  23. copick_utils/cli/picksout.py +148 -0
  24. copick_utils/cli/processing_commands.py +18 -0
  25. copick_utils/cli/seg2mesh.py +135 -0
  26. copick_utils/cli/seg2picks.py +128 -0
  27. copick_utils/cli/segop.py +248 -0
  28. copick_utils/cli/separate_components.py +155 -0
  29. copick_utils/cli/skeletonize.py +164 -0
  30. copick_utils/cli/util.py +580 -0
  31. copick_utils/cli/validbox.py +155 -0
  32. copick_utils/converters/__init__.py +35 -0
  33. copick_utils/converters/converter_common.py +543 -0
  34. copick_utils/converters/ellipsoid_from_picks.py +335 -0
  35. copick_utils/converters/lazy_converter.py +576 -0
  36. copick_utils/converters/mesh_from_picks.py +209 -0
  37. copick_utils/converters/mesh_from_segmentation.py +119 -0
  38. copick_utils/converters/picks_from_mesh.py +542 -0
  39. copick_utils/converters/picks_from_segmentation.py +168 -0
  40. copick_utils/converters/plane_from_picks.py +251 -0
  41. copick_utils/converters/segmentation_from_mesh.py +291 -0
  42. copick_utils/{segmentation → converters}/segmentation_from_picks.py +151 -15
  43. copick_utils/converters/sphere_from_picks.py +306 -0
  44. copick_utils/converters/surface_from_picks.py +337 -0
  45. copick_utils/features/skimage.py +33 -13
  46. copick_utils/io/readers.py +62 -59
  47. copick_utils/io/writers.py +9 -14
  48. copick_utils/logical/__init__.py +43 -0
  49. copick_utils/logical/distance_operations.py +604 -0
  50. copick_utils/logical/enclosed_operations.py +222 -0
  51. copick_utils/logical/mesh_operations.py +443 -0
  52. copick_utils/logical/point_operations.py +303 -0
  53. copick_utils/logical/segmentation_operations.py +399 -0
  54. copick_utils/pickers/grid_picker.py +5 -4
  55. copick_utils/process/__init__.py +47 -0
  56. copick_utils/process/connected_components.py +360 -0
  57. copick_utils/process/filter_components.py +306 -0
  58. copick_utils/process/hull.py +106 -0
  59. copick_utils/process/skeletonize.py +326 -0
  60. copick_utils/process/spline_fitting.py +648 -0
  61. copick_utils/process/validbox.py +333 -0
  62. copick_utils/util/__init__.py +6 -0
  63. copick_utils/util/config_models.py +614 -0
  64. {copick_utils-0.6.0.dist-info → copick_utils-1.0.0.dist-info}/METADATA +38 -12
  65. copick_utils-1.0.0.dist-info/RECORD +71 -0
  66. {copick_utils-0.6.0.dist-info → copick_utils-1.0.0.dist-info}/WHEEL +1 -1
  67. copick_utils-1.0.0.dist-info/entry_points.txt +29 -0
  68. copick_utils/__about__.py +0 -4
  69. copick_utils/segmentation/picks_from_segmentation.py +0 -67
  70. copick_utils-0.6.0.dist-info/RECORD +0 -15
  71. /copick_utils/{segmentation → io}/__init__.py +0 -0
  72. /copick_utils-0.6.0.dist-info/LICENSE.txt → /copick_utils-1.0.0.dist-info/licenses/LICENSE +0 -0
@@ -0,0 +1,155 @@
1
+ """CLI commands for segmentation processing operations."""
2
+
3
+ import click
4
+ import copick
5
+ from click_option_group import optgroup
6
+ from copick.cli.util import add_config_option, add_debug_option
7
+ from copick.util.log import get_logger
8
+ from copick.util.uri import expand_output_uri, parse_copick_uri
9
+
10
+ from copick_utils.cli.util import add_output_option, add_tomogram_option
11
+
12
+
13
+ @click.command(
14
+ context_settings={"show_default": True},
15
+ short_help="Generate valid area box meshes for tomographic reconstructions.",
16
+ no_args_is_help=True,
17
+ )
18
+ @add_config_option
19
+ @optgroup.group("\nInput Options", help="Options related to the input runs.")
20
+ @optgroup.option(
21
+ "--run-names",
22
+ "-r",
23
+ multiple=True,
24
+ help="Specific run names to process (default: all runs).",
25
+ )
26
+ @add_tomogram_option(required=True)
27
+ @optgroup.group("\nTool Options", help="Options related to this tool.")
28
+ @optgroup.option(
29
+ "--angle",
30
+ type=float,
31
+ default=0.0,
32
+ help="Rotation angle around Z-axis in degrees.",
33
+ )
34
+ @optgroup.option(
35
+ "--workers",
36
+ type=int,
37
+ default=8,
38
+ help="Number of worker processes.",
39
+ )
40
+ @optgroup.group("\nOutput Options", help="Options related to output meshes.")
41
+ @add_output_option("mesh", default_tool="validbox")
42
+ @add_debug_option
43
+ def validbox(
44
+ config,
45
+ run_names,
46
+ tomogram_uri,
47
+ angle,
48
+ workers,
49
+ output_uri,
50
+ debug,
51
+ ):
52
+ """
53
+ Generate valid area box meshes for tomographic reconstructions.
54
+
55
+ \b
56
+ URI Format:
57
+ Meshes: object_name:user_id/session_id
58
+ Tomograms: tomo_type@voxel_spacing
59
+
60
+ \b
61
+ Creates box meshes representing the valid imaging area of tomographic
62
+ reconstructions. The box dimensions are based on the tomogram voxel dimensions
63
+ and can be optionally rotated around the Z-axis.
64
+
65
+ \b
66
+ Examples:
67
+ # Generate validbox meshes for all runs
68
+ copick process validbox --tomogram wbp@10.0 -o "validbox"
69
+
70
+ # Generate with rotation and specific tomogram type
71
+ copick process validbox -t imod@10.0 --angle 45.0 -o "validbox/rotated"
72
+ """
73
+ from copick_utils.process.validbox import validbox_batch
74
+
75
+ logger = get_logger(__name__, debug=debug)
76
+
77
+ root = copick.from_file(config)
78
+ run_names_list = list(run_names) if run_names else None
79
+
80
+ # Parse tomogram URI to extract tomo_type and voxel_spacing
81
+ try:
82
+ tomogram_params = parse_copick_uri(tomogram_uri, "tomogram")
83
+ except ValueError as e:
84
+ raise click.BadParameter(f"Invalid tomogram URI: {e}") from e
85
+
86
+ tomo_type = tomogram_params["tomo_type"]
87
+ voxel_spacing = tomogram_params["voxel_spacing"]
88
+ if isinstance(voxel_spacing, str):
89
+ voxel_spacing = float(voxel_spacing)
90
+
91
+ # Expand output URI with smart defaults (no input, so use synthetic input)
92
+ try:
93
+ output_uri = expand_output_uri(
94
+ output_uri=output_uri,
95
+ input_uri="validbox:*/*", # Synthetic input for default object name
96
+ input_type="mesh",
97
+ output_type="mesh",
98
+ command_name="validbox",
99
+ individual_outputs=False,
100
+ )
101
+ except ValueError as e:
102
+ raise click.BadParameter(f"Error expanding output URI: {e}") from e
103
+
104
+ # Parse output URI (now fully expanded)
105
+ try:
106
+ output_params = parse_copick_uri(output_uri, "mesh")
107
+ except ValueError as e:
108
+ raise click.BadParameter(f"Invalid output URI: {e}") from e
109
+
110
+ mesh_object_name_output = output_params["object_name"]
111
+ mesh_user_id_output = output_params["user_id"]
112
+ mesh_session_id_output = output_params["session_id"]
113
+
114
+ logger.info(f"Generating validbox meshes for object '{mesh_object_name_output}'")
115
+ logger.info(f"Tomogram: {tomo_type}@{voxel_spacing}")
116
+ logger.info(f"Rotation angle: {angle} degrees")
117
+ logger.info(f"Target mesh: {mesh_object_name_output} ({mesh_user_id_output}/{mesh_session_id_output})")
118
+
119
+ if run_names_list:
120
+ logger.info(f"Processing {len(run_names_list)} specific runs")
121
+ else:
122
+ logger.info(f"Processing all {len(root.runs)} runs")
123
+
124
+ results = validbox_batch(
125
+ root=root,
126
+ voxel_spacing=voxel_spacing,
127
+ mesh_object_name=mesh_object_name_output,
128
+ mesh_user_id=mesh_user_id_output,
129
+ mesh_session_id=mesh_session_id_output,
130
+ tomo_type=tomo_type,
131
+ angle=angle,
132
+ run_names=run_names_list,
133
+ workers=workers,
134
+ )
135
+
136
+ successful = sum(1 for result in results.values() if result and result.get("processed", 0) > 0)
137
+ total_vertices = sum(result.get("vertices_created", 0) for result in results.values() if result)
138
+ total_faces = sum(result.get("faces_created", 0) for result in results.values() if result)
139
+
140
+ # Collect all errors
141
+ all_errors = []
142
+ for result in results.values():
143
+ if result and result.get("errors"):
144
+ all_errors.extend(result["errors"])
145
+
146
+ logger.info(f"Completed: {successful}/{len(results)} runs processed successfully")
147
+ logger.info(f"Total vertices created: {total_vertices}")
148
+ logger.info(f"Total faces created: {total_faces}")
149
+
150
+ if all_errors:
151
+ logger.warning(f"Encountered {len(all_errors)} errors during processing")
152
+ for error in all_errors[:5]: # Show first 5 errors
153
+ logger.warning(f" - {error}")
154
+ if len(all_errors) > 5:
155
+ logger.warning(f" ... and {len(all_errors) - 5} more errors")
@@ -0,0 +1,35 @@
1
+ """Converters for different copick data types."""
2
+
3
+ from copick_utils.converters.ellipsoid_from_picks import ellipsoid_from_picks, ellipsoid_from_picks_batch
4
+ from copick_utils.converters.mesh_from_picks import mesh_from_picks, mesh_from_picks_batch
5
+ from copick_utils.converters.mesh_from_segmentation import mesh_from_segmentation, mesh_from_segmentation_batch
6
+ from copick_utils.converters.picks_from_mesh import picks_from_mesh, picks_from_mesh_batch
7
+ from copick_utils.converters.picks_from_segmentation import picks_from_segmentation, picks_from_segmentation_batch
8
+ from copick_utils.converters.plane_from_picks import plane_from_picks, plane_from_picks_batch
9
+ from copick_utils.converters.segmentation_from_mesh import segmentation_from_mesh, segmentation_from_mesh_batch
10
+ from copick_utils.converters.segmentation_from_picks import segmentation_from_picks, segmentation_from_picks_batch
11
+ from copick_utils.converters.sphere_from_picks import sphere_from_picks, sphere_from_picks_batch
12
+ from copick_utils.converters.surface_from_picks import surface_from_picks, surface_from_picks_batch
13
+
14
+ __all__ = [
15
+ "mesh_from_segmentation",
16
+ "mesh_from_segmentation_batch",
17
+ "picks_from_segmentation",
18
+ "picks_from_segmentation_batch",
19
+ "picks_from_mesh",
20
+ "picks_from_mesh_batch",
21
+ "segmentation_from_mesh",
22
+ "segmentation_from_mesh_batch",
23
+ "segmentation_from_picks",
24
+ "segmentation_from_picks_batch",
25
+ "mesh_from_picks",
26
+ "mesh_from_picks_batch",
27
+ "sphere_from_picks",
28
+ "sphere_from_picks_batch",
29
+ "ellipsoid_from_picks",
30
+ "ellipsoid_from_picks_batch",
31
+ "plane_from_picks",
32
+ "plane_from_picks_batch",
33
+ "surface_from_picks",
34
+ "surface_from_picks_batch",
35
+ ]