mascaf.validation¶
Validation module for SWC models.
Provides the Validation class to compare SWC models against original mesh and skeleton data.
- class mascaf.validation.Validation(mesh, skeleton, morphology)[source]¶
Bases:
objectValidation of MorphologyGraph models against original mesh and skeleton.
This class provides methods to validate a MorphologyGraph by comparing it to the original mesh (geometry and surface) and the original skeleton (topology and centerline).
- Parameters:
mesh (
Union[Trimesh,MeshManager]) – The original mesh to validate against. Can be either a trimesh.Trimesh object or a MeshManager instance.skeleton (
SkeletonGraph) – The original skeleton graph used to generate the morphology.morphology (
Union[MorphologyGraph,str,Path]) – Either a MorphologyGraph instance to validate, or a path to an SWC file which will be loaded as a MorphologyGraph.
- mesh¶
The mesh object (extracted from MeshManager if needed).
- Type:
- skeleton¶
The original skeleton graph.
- Type:
SkeletonGraph
- morphology¶
The morphology graph to validate.
- Type:
MorphologyGraph
Examples
>>> from mascaf import MeshManager, SkeletonGraph, Validation >>> mesh_mgr = MeshManager(mesh_path="neuron.obj") >>> skeleton = SkeletonGraph.from_polylines(polylines) >>> # Option 1: Validate from SWC file >>> validator = Validation(mesh_mgr, skeleton, "output.swc") >>> # Option 2: Validate existing MorphologyGraph >>> graph = MorphologyGraph.from_swc_file("output.swc") >>> validator = Validation(mesh_mgr, skeleton, graph) >>> volume_ratio = validator.compare_volumes() >>> radius_errors = validator.validate_radii()
- __init__(mesh, skeleton, morphology)[source]¶
- Parameters:
mesh (Trimesh | MeshManager)
skeleton (SkeletonGraph)
morphology (MorphologyGraph | str | Path)
- compare_volumes(account_for_overlaps=False)[source]¶
Compare total volume between mesh and morphology model.
Computes the mesh volume using trimesh and the morphology volume by summing truncated cone volumes for each edge segment.
- Parameters:
account_for_overlaps (
bool) – If True, subtract branch-point overlap corrections in the morphology volume (seeMorphologyGraph.compute_volume()).- Returns:
Dictionary containing: - ‘mesh_volume’: float, volume of the mesh - ‘morphology_volume’: float, volume of the morphology model - ‘ratio’: float, morphology_volume / mesh_volume - ‘absolute_difference’: float, abs(morphology_volume - mesh_volume) - ‘relative_error’: float, abs difference / mesh_volume
- Return type:
Examples
>>> result = validator.compare_volumes() >>> print(f"Volume ratio: {result['ratio']:.3f}")
- compare_surface_areas(account_for_overlaps=False)[source]¶
Compare total surface area between mesh and morphology model.
Computes the mesh surface area using trimesh and the morphology surface area by summing lateral surface areas of truncated cones for each edge segment.
- Parameters:
account_for_overlaps (
bool) – If True, subtract branch-point overlap corrections in the morphology surface area (seeMorphologyGraph.compute_surface_area()).- Returns:
Dictionary containing: - ‘mesh_area’: float, surface area of the mesh - ‘morphology_area’: float, surface area of the morphology model - ‘ratio’: float, morphology_area / mesh_area - ‘error’: float, morphology_area - mesh_area - ‘relative_error’: float, error / mesh_area
- Return type:
Examples
>>> result = validator.compare_surface_areas() >>> print(f"Surface area ratio: {result['ratio']:.3f}")
- full_validation()[source]¶
Run all validation checks and log comprehensive results.
Compares volumes and surface areas (with and without branch-point overlap correction when branch vertices are present) and logs each result via the module logger at
INFOlevel.- Returns:
Results are emitted via logging rather than returned.
- Return type: