src.utils.curve.simple_final_cleanup

Classes

SimpleFinalCleanup([merge_radius, ...])

class src.utils.curve.simple_final_cleanup.SimpleFinalCleanup(merge_radius=15.0, min_segment_length=0.0, segment_grid_cell=5.0, sce=None)
Author:

Alberto M. Esmoris Pena

Optional final-cleanup collaborator for the curves produced by SimpleCurveExtractor. Re-applies three invariants whose first invocation in the SCE pipeline runs before the merge and snap cascades and whose post-cascade output the cascades can violate:

  1. split_z_reversals at the standard \(\Delta z_{\text{full}} =\) _max_dz(merge_radius) threshold. The post-opt post_chain_merge_until_stable driver bridges same-CID features across different elevations and can introduce drawdowns far above the pre-merge split’s threshold.

  2. drop_cov_refine_by_predicate with the cross-CID coverage-refine predicate. Snap shifts can drift coverage_refine helpers across an other-CID feature after the pre-snap drop already ran.

  3. _relabel_disconnected_curves. Adoption can place a feature into a CID whose other members are within merge_radius at the moment of adoption; subsequent endpoint extension and snap can then drift the components apart.

The driver also runs a tiny-segment filter between steps 1 and 2 that drops sub-features whose LENGTH_2D falls below min_segment_length (post-split tails shorter than the SCE min-segment threshold).

The collaborator follows the established R3..R6 pattern: a snapshot of the relevant SCE attributes is taken at construction time, plus a back-reference to the consuming SimpleCurveExtractor instance that exposes _max_dz and _relabel_disconnected_curves (both non-trivial helpers that intentionally stay on SCE).

Instances are constructed once per consuming SCE pipeline phase from the orchestrator helper _step_global_optimization and only when final_cleanup=True (defaults to False so the production JSON, SimpleCurveEvaluationTest and the bench probes preserve their current behaviour exactly).

Variables:
  • merge_radius (float) – Endpoint-merge radius forwarded to _max_dz for the Z-reversal split threshold and used implicitly by the back-call to _relabel_disconnected_curves.

  • min_segment_length (float) – Threshold for the tiny- segment filter that runs between the Z-reversal split and the cross-CID drop. Values \(\le 0\) short-circuit the filter.

  • segment_grid_cell (float) – Bbox-grid cell size forwarded to the internal SimpleCrossingHandler used by the cross-CID drop step.

  • _sce (SimpleCurveExtractor or None) – Back-reference to the consuming SimpleCurveExtractor instance. Used for the _max_dz and _relabel_disconnected_curves callbacks (both helpers stay on SCE because they pull on SCE-private static helpers and therefore would cascade extra dependencies into this module).

__init__(merge_radius=15.0, min_segment_length=0.0, segment_grid_cell=5.0, sce=None)

Snapshot the SCE configuration relevant to the final-cleanup cascade and hold the SCE back-reference for the two SCE-side callbacks.

run(smooth_curves, metadata)

Execute the four-step cleanup chain.

Parameters:
  • smooth_curves (list of dict) – Chained curve segments.

  • metadata (list of dict) – Per-chain metadata dicts.

Returns:

Cleaned-up (smooth_curves, metadata).

Return type:

tuple

filter_short_segments(smooth_curves, metadata)

Drop features whose LENGTH_2D metadata is below self.min_segment_length.

Short-circuits to the identity when self.min_segment_length <= 0 (parity with the inline guard the cleanup driver replaced). Missing LENGTH_2D keys default to 0.0 so a feature without the key is treated as zero-length and is dropped only when the threshold is positive.

Parameters:
  • smooth_curves (list of dict) – Chained curve segments.

  • metadata (list of dict) – Per-chain metadata dicts.

Returns:

Filtered (smooth_curves, metadata).

Return type:

tuple

static is_cross_cid_cov_refine_pair(fa, fb, md)

Predicate for SimpleCrossingHandler.drop_cov_refine_by_predicate().

Returns True when the two features (a) belong to different CIDs and (b) at least one of them was emitted by the coverage-refine extractor (i.e. SKEL_MTH == 'coverage_refine'). Same-CID crossings are tolerated at this stage because the cross-CID resolver and the same-CID resolver have distinct downstream consequences.

Parameters:
  • fa (int) – Index of the first feature.

  • fb (int) – Index of the second feature.

  • md (list of dict) – Per-feature metadata list (indexed by fa and fb).

Returns:

True if the pair is a cross-CID coverage-refine drift candidate.

Return type:

bool