pycroglia.core.tests.unit package
Submodules
- pycroglia.core.tests.unit.test_arclength.test_circle_linear()[source]
Test arc length of a circle using linear chords.
This test discretizes a unit circle into 20 points and computes its arc length using straight-line (linear chordal) distances. The result is expected to underestimate the true circumference slightly, but remain within 2% relative tolerance.
- Asserts:
The computed arc length is close to
2πwithin rtol=0.02.
- pycroglia.core.tests.unit.test_arclength.test_circle_pchip()[source]
Test arc length of a circle using PCHIP interpolation.
This test discretizes a unit circle into 20 points and computes its arc length using Piecewise Cubic Hermite Interpolating Polynomial (PCHIP) interpolation. The smoother parametric curve gives a more accurate estimate of the circumference.
- Asserts:
The computed arc length is close to
2πwithin rtol=0.005.
- pycroglia.core.tests.unit.test_arclength.test_circle_spline()[source]
Test arc length of a circle using cubic spline interpolation.
This test discretizes a unit circle into 20 points and computes its arc length using cubic spline interpolation. The smooth spline fit should provide a highly accurate estimate of the circumference.
- Asserts:
The computed arc length is close to
2πwithin rtol=0.005.
- pycroglia.core.tests.unit.test_bounding_box.test_bounding_box_of_cell()[source]
Test Bounding Box computation on a simple 3D volume.
- Scenario:
A single foreground voxel is placed at (z=2, y=3, x=4) in a (5,6,7) volume. The bounding box should crop along Y and X to tightly include only that voxel.
- Asserts:
The cropped volume has shape (5, 1, 1), shrinking only in y and x.
The bounding box left/right (x bounds) are both 4.
The bounding box bottom/top (y bounds) are both 3.
The voxel at the expected cropped coordinate is True.
- pycroglia.core.tests.unit.test_branch_analysis.indices_to_mask(cell_indices, img_shape)[source]
Convert a 1D list of voxel indices into a 3D binary mask.
- Parameters:
- Returns:
3D uint8 mask of shape img_shape with True (1) at all specified voxel indices and False (0) elsewhere.
- Return type:
np.ndarray
- pycroglia.core.tests.unit.test_branch_analysis.test_branch_analysis_equivalence()[source]
Test BranchAnalysis matches MATLAB reference results.
- Asserts:
Python and MATLAB endpoint voxel masks are identical.
The number of detected branch points matches MATLAB output.
Branch point coordinates match element-wise.
Maximum, minimum, and average branch lengths match within 1e-6.
- pycroglia.core.tests.unit.test_centroid.test_compute_average_centroid_distance()[source]
Test compute_average_distance returns correct scaled distance.
- Asserts:
The average pairwise distance between two centroids is correctly computed in physical units, given voxel scales for XY and Z.
- pycroglia.core.tests.unit.test_centroid.test_get_centroids()[source]
Test Centroids correctly computes centroids from binary masks.
- Asserts:
The computed centroids match the expected voxel coordinates for two simple 3D masks.
- pycroglia.core.tests.unit.test_full_cell_analysis.test_full_cell_analysis()[source]
Test FullCellAnalysis computes convex volumes and complexities.
This test builds two synthetic 3×3×3 masks, each containing four voxels arranged in an L-shape. These small shapes have simple convex hulls, making it straightforward to verify correctness of the analysis.
- Verifications performed:
Convex hull simplices and vertex indices are consistent with the voxel geometry.
Convex hull volumes are computed in physical units by scaling with voxscale.
Cell complexities are correctly calculated as convex_volume / cell_volume.
The maximum cell volume is determined correctly from voxel counts.
- Asserts:
cell_volumes match expected floating-point values.
convex_vertices match the expected vertex indices for each mask.
convex_volumes match expected floating-point values.
cell_complexities match expected floating-point values.
max_cell_volume matches the expected maximum cell volume.
- pycroglia.core.tests.unit.test_nearest_pixel.test_nearest_pixel()[source]
Test NearestPixel correctly finds the closest foreground voxel.
- Scenario:
A 5×5×5 binary volume is created with a single voxel set to True at coordinates (z=2, y=3, x=4).
The search starts at (0,0,0) with isotropic scale=1.0.
- Asserts:
The nearest voxel coordinates returned by compute match the expected location (x=4, y=3, z=2).
The returned result is equal to a NearestPixelCoordinates instance with these values.
- pycroglia.core.tests.unit.test_reorder.test_diagonal_path()[source]
Test reorder_pixel_list correctly orders a 3D diagonal line.
- Asserts:
Voxels are reordered from endpoint (0,0,0) to centroid (4,4,4).
The resulting path matches [[0,0,0], [1,1,1], …, [4,4,4]].
- pycroglia.core.tests.unit.test_reorder.test_simple_line_path()[source]
Test reorder_pixel_list correctly orders a straight vertical line.
- Asserts:
Voxels are reordered from the endpoint at z=0 to the centroid at z=4.
The resulting order matches [[0,2,2], [1,2,2], …, [4,2,2]].
- pycroglia.core.tests.unit.test_segmentation.simple_cells_img()[source]
Returns a 3D binary image with two separate cells.
- Returns:
3D binary image.
- Return type:
NDArray
- pycroglia.core.tests.unit.test_segmentation.test_segment_cell_basic()[source]
Test segment_cell returns correct number of segments for simple input.
- Asserts:
The number of returned segments matches the number of cells.
- pycroglia.core.tests.unit.test_segmentation.test_segment_cell_small_cell_not_split()[source]
Test segment_cell does not split small cells below cut_off_size.
- Asserts:
The returned segment is the same as the input cell.
- pycroglia.core.tests.unit.test_segmentation.test_segment_single_cell_split()[source]
Test segment_single_cell splits a large cell into multiple segments.
- Asserts:
The number of returned segments matches the number of nuclei.
- pycroglia.core.tests.unit.test_segmentation.test_segmentation_config_defaults()[source]
Test SegmentationConfig default values.
- Asserts:
The default values are set as expected.