Skip to content

CMC classification consensus#196

Merged
vergep merged 74 commits intomainfrom
cmc-classification-consensus
Apr 10, 2026
Merged

CMC classification consensus#196
vergep merged 74 commits intomainfrom
cmc-classification-consensus

Conversation

@vergep
Copy link
Copy Markdown
Collaborator

@vergep vergep commented Mar 17, 2026

CMC classification consensus.
Based on Procrustes rotation and translation to find consensus parameters

@vergep vergep changed the base branch from main to feature/create_readme_scratch_core March 27, 2026 10:19
@vergep vergep changed the base branch from feature/create_readme_scratch_core to main March 27, 2026 10:19
Comment thread packages/scratch-core/src/conversion/surface_comparison/cmc_consensus/pipeline.py Outdated
Comment thread packages/scratch-core/src/conversion/surface_comparison/cmc_consensus/pipeline.py Outdated
Comment thread packages/scratch-core/src/conversion/surface_comparison/cmc_consensus/pipeline.py Outdated
Comment thread packages/scratch-core/src/conversion/surface_comparison/cmc_consensus/pipeline.py Outdated
Comment thread packages/scratch-core/src/conversion/surface_comparison/models.py Outdated
Copy link
Copy Markdown
Collaborator

@cfs-data cfs-data left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with suggestions

Comment thread packages/scratch-core/src/conversion/surface_comparison/models.py Outdated
Comment thread packages/scratch-core/README.md
vergep and others added 5 commits April 2, 2026 12:56
…_classification/test_cmc_internals_concensus.py

Co-authored-by: Laurens Weijs <laurens.weijs@rijksoverheid.nl>
# Conflicts:
#	packages/scratch-core/tests/conversion/surface_comparison/cell_classification/test_cmc_internals_median.py
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 2, 2026

Diff Coverage

Diff: origin/main..HEAD, staged and unstaged changes

  • packages/scratch-core/src/conversion/surface_comparison/cmc_classification_median.py (100%)
  • packages/scratch-core/src/conversion/surface_comparison/cmc_consensus/criterion.py (100%)
  • packages/scratch-core/src/conversion/surface_comparison/cmc_consensus/models.py (100%)
  • packages/scratch-core/src/conversion/surface_comparison/cmc_consensus/pipeline.py (81.1%): Missing lines 102,120,194-195,198,203,211,215-216,219
  • packages/scratch-core/src/conversion/surface_comparison/cmc_consensus/procrustes.py (95.5%): Missing lines 111-112
  • packages/scratch-core/src/conversion/surface_comparison/pipeline.py (100%)

Summary

  • Total: 155 lines
  • Missing: 12 lines
  • Coverage: 92%

packages/scratch-core/src/conversion/surface_comparison/cmc_consensus/pipeline.py

   98             max_abs_angle_distance,
   99         )
  100 
  101         if 2 < len(current_ids) < n_cells:
! 102             _refine(
  103                 current_ids,
  104                 criterion_current,
  105                 cells,
  106                 max_distance,

  116 
  117         if len(best_ids) == n_cells:
  118             return best_ids  # outer loop short-circuit
  119 
! 120     return best_ids
  121 
  122 
  123 def _update_congruent_cells(cells: list[Cell], congruent_ids: list[int]) -> None:
  124     """update cell.is_congruent property

  190     :param max_distance: maximum distance threshold (meters)
  191     :param max_abs_angle_distance: maximum absolute angle threshold (degrees)
  192     """
  193 
! 194     while True:
! 195         cell_distances, cell_angle_distances = _get_cell_angle_and_position_distances(
  196             current_ids, cells
  197         )
! 198         candidate_ids = np.where(
  199             (cell_distances <= max_distance)
  200             & (cell_angle_distances <= max_abs_angle_distance)
  201         )[0].tolist()
  202 
! 203         criterion_candidate = calculate_criterion(
  204             cell_distances[candidate_ids],
  205             cell_angle_distances[candidate_ids],
  206             max_distance,
  207             max_abs_angle_distance,

  207             max_abs_angle_distance,
  208         )
  209 
  210         # Accept if strictly more inlier, or same count with lower criterion
! 211         if len(candidate_ids) > len(current_ids) or (
  212             len(candidate_ids) == len(current_ids)
  213             and criterion_candidate < criterion_current
  214         ):
! 215             criterion_current = criterion_candidate
! 216             current_ids = candidate_ids
  217         else:
  218             # we have our local optimum and return, also for len(candidate_ids) == len(current_ids) and criterion did not improve
! 219             return

packages/scratch-core/src/conversion/surface_comparison/cmc_consensus/procrustes.py

  107     )  # (2, 2)
  108 
  109     # If det == -1 we have an unintended reflection; correct it by changing sign of last column of left_singular_vectors.
  110     if np.linalg.det(rotation_matrix) == -1:
! 111         left_singular_vectors[:, -1] *= -1
! 112         rotation_matrix = left_singular_vectors @ right_singular_vectors_transposed
  113 
  114     # Rotation angle: atan2(sin/cos)
  115     (cos, sin) = tuple(rotation_matrix[0])
  116     consensus_rotation_rad = float(np.arctan2(sin, cos))  # -pi <= angle <= pi

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 2, 2026

Code Coverage

Package Line Rate Branch Rate Health
. 96% 92%
computations 94% 67%
container_models 99% 100%
conversion 96% 89%
conversion.export 99% 93%
conversion.filter 97% 89%
conversion.leveling 100% 100%
conversion.leveling.solver 100% 75%
conversion.plots 99% 88%
conversion.preprocess_impression 99% 91%
conversion.preprocess_striation 90% 62%
conversion.profile_correlator 96% 82%
conversion.surface_comparison 99% 89%
conversion.surface_comparison.cell_registration 100% 90%
conversion.surface_comparison.cmc_consensus 91% 65%
extractors 97% 75%
mutations 100% 100%
parsers 97% 50%
parsers.patches 89% 60%
preprocessors 100% 100%
processors 100% 83%
renders 99% 50%
utils 71% 100%
Summary 98% (3383 / 3465) 86% (353 / 412)

Minimum allowed line rate is 50%

@laurensWe laurensWe self-requested a review April 9, 2026 05:57
Copy link
Copy Markdown
Member

@laurensWe laurensWe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the changes :)

@vergep vergep merged commit 8de1bcc into main Apr 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants