src.utils.curve.simple_final_cleanup
Classes
|
- 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:split_z_reversalsat the standard \(\Delta z_{\text{full}} =\)_max_dz(merge_radius)threshold. The post-optpost_chain_merge_until_stabledriver bridges same-CID features across different elevations and can introduce drawdowns far above the pre-merge split’s threshold.drop_cov_refine_by_predicatewith 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._relabel_disconnected_curves. Adoption can place a feature into a CID whose other members are withinmerge_radiusat 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_2Dfalls belowmin_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
SimpleCurveExtractorinstance that exposes_max_dzand_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_optimizationand only whenfinal_cleanup=True(defaults toFalseso the production JSON,SimpleCurveEvaluationTestand the bench probes preserve their current behaviour exactly).- Variables:
merge_radius (float) – Endpoint-merge radius forwarded to
_max_dzfor 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
SimpleCrossingHandlerused by the cross-CID drop step._sce (
SimpleCurveExtractoror None) – Back-reference to the consumingSimpleCurveExtractorinstance. Used for the_max_dzand_relabel_disconnected_curvescallbacks (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_2Dmetadata is belowself.min_segment_length.Short-circuits to the identity when
self.min_segment_length <= 0(parity with the inline guard the cleanup driver replaced). MissingLENGTH_2Dkeys default to0.0so 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
Truewhen 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
faandfb).
- Returns:
Trueif the pair is a cross-CID coverage-refine drift candidate.- Return type:
bool